#How do you read events within an exclusive system? (i.e., directly from `world`)

7 messages · Page 1 of 1 (latest)

sinful bridge
#

There is a convenient world.send_event API, but there is nothing quite so obvious for reading events given world access. How can that be done?

noble ruin
#

Huh, slightly more awkward than I thought

fn w(w: &mut World) {
    for i in w
        .resource::<Events<Bob>>()
        .get_reader()
        .read(w.resource::<Events<Bob>>())
    {
        //
    }
}
pine idol
noble ruin
#

Can you get system param out of world?

outer panther
#

Use SystemState

modern sundial
#

It can be a param along side the world, something like this should be possible

fn foo(world: &mut World, mut reader: Local<ManualEventReader<Bar>>) {
    let events = world.resource_mut::<Events<Bar>>();
    for event in reader.read(&events) { }
}```
#

Though as mentioned, use SystemState like rs fn foo(world: &mut World, state: &mut SystemState<EventReader<Bar>>) { let mut reader = state.get_mut(world); for event in reader.read() { } }
Actually allows you to re-use custom SystemParams like EventReader instead of having to manually re-implement them