Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Are there events for component changes? Eg: Play animation when component is added.

Discussion in 'DOTS Animation' started by GarthSmith, Jul 2, 2018.

  1. GarthSmith

    GarthSmith

    Joined:
    Apr 26, 2012
    Posts:
    1,240
    Hello!

    We've used Entitas in the past, so we would pass an Entity into a View, and that View would subscribe to data changes on the Entity by implementing an interface. Eg: IDestroyedListener.

    Is there a similar thing I can do to react to a data change on an Entity? Eg: I want the View to play an animation when a DestroyedComponent is attached to an Entity.

    Should I poll the entity every frame to detect if the component was added? Thanks for helping me get familiarized with Unity!
     
    Last edited: Jul 2, 2018
  2. recursive

    recursive

    Joined:
    Jul 12, 2012
    Posts:
    669
    You can have reactive systems that using tracking components (different from the way entitas handles reactivity, but you can achieve the same result and have more low-level control). You can also create change filters that respond to added/changed components (no destroyed yet).

    The samples are still in a state of flux, but the Unit tests that come with the entity package should show some usage.

    This thread has some good discussion/quick examples.

    This post describes how to create reactive systems with ISystemStateComponentData (a shared data component version has also been added in the interim).

    This post points out you can use SetFilterChanged() on a component group to create a change filter, which will only get you the entities that changed since the last time the system was run.

    EDIT:
    I will point out that the concept of a "view" doesn't yet exist in ECS, you'll have to roll your own for the time being.
     
    GarthSmith likes this.
  3. MartijnGG

    MartijnGG

    Joined:
    May 3, 2018
    Posts:
    74
    I do not think the `SetFilterChanged` will work with a `ComponentArray`. It does not keep track of component versioning like the `ComponentDataArray`. This versioning is used to figure out what changed since last tick.