bevy/crates/bevy_state/src
UkoeHB adc2cf7dfe
Add state scoped events (#15085)
# 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);
}
```
2024-09-09 16:37:27 +00:00
..
state Apply unused_qualifications lint (#14828) 2024-08-21 12:29:33 +00:00
app.rs Adding Reflect data types for States and FreelyMutableState. (#14643) 2024-08-08 00:07:00 +00:00
commands.rs Add set_state extension method to Commands (#15083) 2024-09-09 15:58:09 +00:00
condition.rs remove inaccurate warning from in_state (#13862) 2024-06-16 16:06:45 +00:00
lib.rs Add state scoped events (#15085) 2024-09-09 16:37:27 +00:00
reflect.rs reflect: implement the unique reflect rfc (#7207) 2024-08-12 17:01:41 +00:00
state_scoped_events.rs Add state scoped events (#15085) 2024-09-09 16:37:27 +00:00
state_scoped.rs impl Reflect + Clone for StateScoped (#14156) 2024-07-08 01:00:04 +00:00