#How do you read events within an exclusive system? (i.e., directly from `world`)
7 messages · Page 1 of 1 (latest)
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>>())
{
//
}
}
That will either miss some events or see some twice.
Prefer a Local<ManualEventsReader<Bob>> system paramenter instead and call .read(...) on it.
Can you get system param out of world?
Use SystemState
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