
# Objective - bevy removed `Observe` type parameters in #15151 ,it enables merging `Observer` and `ObserverState ` into a single component. with this consolidation ,we can improve efficiency while reducing boilerplate. ## Solution - remove `ObserverState `and merge it into `Observer` ## Testing 40%~60% performance win due to removal of redundant look up.  This also improves ergonomics when using dynamic observer ```rust // previously world.spawn(ObserverState { // SAFETY: we registered `event_a` above and it matches the type of EventA descriptor: unsafe { ObserverDescriptor::default().with_events(vec![event_a]) }, runner: |mut world, _trigger, _ptr, _propagate| { world.resource_mut::<Order>().observed("event_a"); }, ..Default::default() }); // now let observe = unsafe { Observer::with_dynamic_runner(|mut world, _trigger, _ptr, _propagate| { world.resource_mut::<Order>().observed("event_a"); }) .with_event(event_a) }; world.spawn(observe); ```
428 B
428 B
title | pull_requests | |
---|---|---|
Integrate `ObserverState` component into `Observer`. |
|
ObserverState
and Observer
have been merged into a single component.
now you can use Observer::with_dynamic_runner
to build custom Observe.
let observe = unsafe {
Observer::with_dynamic_runner(|mut world, trigger, ptr, propagate| {
// do something
})
.with_event(event_a)
};
world.spawn(observe);