#What is the Difference between Event and Message

17 messages · Page 1 of 1 (latest)

rich hawk
#

i want to learn bevy event but i'm confused by the type Message...
from Bevy 0.18 what is best to learn ? is there a runtime cost difference ?

swift bone
#

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

slate crescent
# rich hawk i want to learn bevy event but i'm confused by the type Message... from Bevy 0...

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)

rich hawk
#

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...

slate crescent
#

so I'd say to just stick to whatever feels easier / more intuitive for you

rich hawk
#

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

slate crescent
#

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

rich hawk
#

thanks !

slate crescent
copper birch
#

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.

rich hawk
#

What is the Difference between Event and Message

limber marsh
#

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.

rich hawk
#

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 ?