mirror of
https://github.com/bevyengine/bevy
synced 2024-11-14 00:47:32 +00:00
adc2cf7dfe
# Objective - Improve robustness of state transitions. Currently events that should be scoped to a specific state can leak between state scopes since events live for two ticks. - See https://github.com/bevyengine/bevy/issues/15072 ## Solution - Allow registering state scoped events that will be automatically cleared when exiting a state. This is *most of the time* not obviously useful, but enables users to write correct code that will avoid/reduce edge conditions (such as systems that aren't state scoped polling for a state scoped event and having unintended side effects outside a specific state instance). ## Testing Did not test. --- ## Showcase Added state scoped events that will be automatically cleared when exiting a state. Useful when you want to guarantee clean state transitions. Normal way to add an event: ```rust fn setup(app: &mut App) { app.add_event::<MyGameEvent>(); } ``` Add a state-scoped event (**NEW**): ```rust fn setup(app: &mut App) { app.add_state_scoped_event::<MyGameEvent>(GameState::Play); } ``` |
||
---|---|---|
.. | ||
macros | ||
src | ||
Cargo.toml |