#Systems communication and Interacting with Other Entities

1 messages · Page 1 of 1 (latest)

twin elbow
#

I have physics system. It needs to fire "got pushed" event when entity is pushed. And when it is pushed "health system" needs to subtract -1 health.

How can I make systems interact with each other?

Also an entity can push other entities. when entity A pushes entity B how do I let entity B know that Entity A pushed it?

spare phoenix
#

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.

twin elbow
#

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.

last jetty
#

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

split veldt
#

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.

fast hull
# twin elbow I have physics system. It needs to fire "got pushed" event when entity is pushed...

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.

fast hull
# fast hull You just create a data component that both systems will work with. One system c...

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.