bevyengine / bevyengine/bevy

Setting next state in OnEnter system is inconsistent if it changes states

Open
#14,058 1 comment 1 reaction 0 assignees View on GitHub
A-States C-Bug S-Needs-Investigation
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

## Bevy version 0.13.2

When setting the next state in a `OnEnter` system, there is inconsistency if it successfully changes states or not.
Example:
```rs
#[derive(States, ...)]
enum GameState
{
Inactive,
Starting,
Running,
}

fn on_enter_starting(
// ...
mut next_state: ResMut>
)
{
// ...
next_state.set(GameState::Running)
// ...
}

fn print_state(state: Res>)
{
if state.is_changed()
{
println!("GameState = {:?}", state.get())
}
}

// in main()
app.add_systems(OnEnter(GameState::Starting), on_enter_starting);
app.add_systems(Update, print_state);
```
I had two systems similar to this, and one switched from `Starting` to `Running` like expected, but the other did not switch states, and remained in the `Starting` state.

I believe it would be good to specify the behavior of something like this, and panic/warn if you shouldn't set states in `OnEnter` systems

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.