This adds support for clearing events when **entering** a state (instead of just when exiting) and updates the names to match `DespawnOnExitState`. Before: ```rust app.add_state_scoped_event::<MyGameEvent>(GameState::Play); ``` After: ```rust app .add_event::<MyGameEvent>() .clear_events_on_exit_state::<MyGameEvent>(GameState::Play); ```
1.0 KiB
1.0 KiB
| title | pull_requests | ||
|---|---|---|---|
| Renamed state scoped entities and events |
|
Previously, Bevy provided the StateScoped component and add_state_scoped_event method
as a way to remove entities/events when exiting a state.
However, it can also be useful to have the opposite behavior,
where entities/events are removed when entering a state.
This is now possible with the new DespawnOnEnterState component and clear_events_on_enter_state method.
To support this addition, the previous method and component have been renamed.
Also, clear_event_on_exit_state no longer adds the event automatically, so you must call App::add_event manually.
| Before | After |
|---|---|
StateScoped |
DespawnOnExitState |
clear_state_scoped_entities |
despawn_entities_on_exit_state |
add_state_scoped_event |
add_event + clear_events_on_exit_state |