#How do you consume events in a system?

8 messages · Page 1 of 1 (latest)

silent latch
#

In the unofficial bevy cheatbook, it says the following (https://bevy-cheatbook.github.io/programming/events.html):

Every reader tracks the events it has read independently, so you can handle the same events from multiple systems.

I wonder, is there any way to consume events within a system so they won't propagate further to other systems with an EventReader<T> parameter?

pseudo perch
#

You can call drain on the ResMut<Events<T>> parameter.

silent latch
#

I'm not sure what Events is. There is no drain in EventReader though.

plush flare
#

https://docs.rs/bevy/latest/bevy/ecs/event/struct.Events.html
He meant this one, instead of getting the reader he suggested to get the Events directly.
Like if you have
EventReader<MyEvent>
You would use
Events<MyEvent>
There is also a page in the unofficial book about handling event management yourself
https://bevy-cheatbook.github.io/patterns/manual-event-clear.html

silent latch
#

Right, thank you. Are EventWriter and EventReader sort of wrappers around Events containers?

#

What's the difference between them?

silent latch
pseudo perch