
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); ```
21 lines
1.0 KiB
Markdown
21 lines
1.0 KiB
Markdown
---
|
|
title: Renamed state scoped entities and events
|
|
pull_requests: [18818, 19435]
|
|
---
|
|
|
|
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` |
|