#Systems communication and Interacting with Other Entities
1 messages · Page 1 of 1 (latest)
There are no events in ecs, since it's not OOP. You communicate between entities ans system by adding or removing components or modifying their data.
As for collisions, they are handled by Unity Physics ECS package
https://docs.unity3d.com/Packages/com.unity.physics@1.0/manual/index.html
Follow up after getting help from DOT/ECS experts.
A. ECS has no event is wrong. event is a core programming concept, it exists just not as delegates.
B. Firing events by adding/removing comp rebuilds archetypes, destroys performance and opens race condition.
C. Consider using double-buffer event queue (it's a popular solution)
D. The previous answer is misleading and potentially harmful to learners because reason B
E. No answer is better than misleading guidance. Be careful with your "help" by considering if its actually a helpful answer. I say this cuz I noticed you (many times) didn't want to actually discuss obstacle but insist on what you think is the way to do things. It's not helpful.
I suppose the easiest way is to push events using a dynamic buffer, e.g. a buffer for damage, which is read by the health system and cleared after all processing is done
double buffering is usually not necessary in my experience but it can help parallelization in some cases
I have a system that updates a bool to false. I can fire an event by changing the bool to true in a system that updates before.
You just create a data component that both systems will work with.
One system can set some field to true when an event occurs. The other system can monitor the value of this field, perform some logic to handle the event and reset the field to false.
Instead of the field, you can implement IEnableComponentData and enable it if an event occurs on the current frame and disable it if it does not.
To be sure that the event will be processed exactly, you can specify the order of system updates using the UpdateAfter and UpdateBefore attributes.
If you want the event to be processed by an arbitrary number of systems.
You can reset the event at the end of the frame (reset the field to false or disable the component).
In order to move the logic to the beginning or end of the frame I have two SystemBases, one is updated at the beginning of the frame, the other at the end. Each has a static event that other systems can subscribe to. Their handlers are called when updating.