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

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!

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.

1 Like

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.