#What is the Difference between Event and Message
17 messages · Page 1 of 1 (latest)
Events are executed on command flush, which usually happens after the end of the current system, Message are buffered and you choose exactly when to read them
For Event you use observers with the On system param, for Message you use systems with the MessageReader system param
I wouldn't say one is better than the other, they're just 2 different tools for different purposes.
A Message is something a system can write through a MessageWriter and another system receive through MessageReader, while an Event or EntityEvent is something that one system triggers and any observer system listening to it will be caused to run, meaning that system only runs when the Event is triggered
If you're trying to learn from the unofficial (outdated) cheatbook, Message used to be just Event, but used inside an observer instead of the Reader
it all depends on how you structure your app and imo you shouldn't really worry about performance if you're still learning; just experiment with both (neither is inherently more costly than the other afaik, it's all dependant on the use-case)
well Message are very easy to use... i'm just scare to learn deprecated functionality... many are there to last though... Event may be one of them...
there are no plans to deprecate messages any time soon afaik, and there's no reason to either, there are many behaviors that depend on messages and can't be replicated through observers / events (at least without increasing their complexity / cost)
so I'd say to just stick to whatever feels easier / more intuitive for you
where i can get a minimal example for event (non outated) ?
im wondering how to add an observer at system level ? not at world level
this is a really good general guide on how to work with both messages and events: https://taintedcoders.com/bevy/events
these are current official examples for observers (events):
https://bevy.org/examples/ecs-entity-component-system/observers/
https://bevy.org/examples/ecs-entity-component-system/observer-propagation/
you can also check this entry in the 0.17 migration guide if you're confused about the changes:
https://bevy.org/learn/migration-guides/0-16-to-0-17/#observer-event-api-changes
thanks !
it's just commands. instead of world. typically
Yeah I couldn't imagine messages going away ever. It's very useful to have a single sender with potentially multiple consumers for different things like non time sensitive gameplay logic, logging, achievement tracking, etc. Events to me are more for performing same frame reactive gameplay logic. I could even see sending a message from an event handler being useful for logging or achievement tracking.
What is the Difference between Event and Message
Probably worth adding to Hukasu's point - Events are not automatically parallelized like systems. Your Messages dealing systems benefit from Bevy's scheduler. Events/Observers are executed like commands, one by one, during flush points.
i finally get to an important point of my bevy learning, is MessageReader<T> for Touch/Keyboard ( involving double buffering ) is the optimal choice for game control if i understood well the Message is guaranty to be handled in at least 2 frames or should i use Global resource input method instead ?