Sparse and short-lived components vs EventChannel/events

(W. Brian Gourlie) #1

I’ve found it useful to graph my system dependencies so I can visualize the direction data is processed in, and realized that my event listeners are always immediately downstream from the systems sending them, which made me consider whether or not they are necessary.

I’m relatively new to ECS and am still trying to figure out sane design patterns. but feel like I’m starting to depend on EventChannel too much, and was wondering if it may be more appropriate to have systems put short-lived components on entities that a subsequent system will check for and consume (remove it) if it exists.

4 Likes
(OvermindDL1) #2

I find both useful. In general:

  • I use events to say that ‘something happened’, but there could be many, overlapping, whatever, just fire and forget.
  • I use tag components to say something needs to be done, these are also useful to say that one such ‘event’ can happen for a given entity, like something checking an in-game resource state like energy for some upcoming action or so.

In general I tended to prefer events since in my old system adding a new component for such a ‘tag’ thing was often a hashmap access compared to a simple function call dispatch (which was oddly often a lot faster). Plus you don’t have to worry about system ordering then.

1 Like
(W. Brian Gourlie) #3

In general I tended to prefer events since in my old system adding a new component for such a ‘tag’ thing was often a hashmap access compared to a simple function call

Yeah, one thing I’ve found myself doing with entity-specific events is defining the the event type as (Entity, EventEnum), and then the consuming system puts the events into an Entity-keyed hashmap for easy lookup when joining over entities. I’m starting to think that this is a symptom of me using Events where I shouldn’t be.

1 Like
(Joël Lupien) #4

If you are storing events in a hashmap (or storing them at all), that probably means you should be using components instead. Of course, it varies on a case by case basis. There isn’t a one true answer to tag components vs event channels.

2 Likes