bevy/crates/bevy_state/src/state
MiniaczQ bc72cedfe3
Make initial StateTransition run before PreStartup (#14208)
# Objective

- Fixes #14206 

## Solution

- Run initial `StateTransition` as a startup schedule before
`PreStartup`, instead of running it inside `Startup` as an exclusive
system.

Related discord discussion:

https://discord.com/channels/691052431525675048/692572690833473578/1259543775668207678

## Testing

Reproduction now works correctly:

```rs
use bevy::prelude::*;

#[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Hash, States)]
enum AppState {
    #[default]
    Menu,
    InGame,
}

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .init_state::<AppState>()
        .add_systems(Startup, setup)
        .add_systems(OnEnter(AppState::Menu), enter_menu_state)
        .run();
}

fn setup(mut next_state: ResMut<NextState<AppState>>) {
    next_state.set(AppState::Menu);
}

fn enter_menu_state() {
    println!("Entered menu state");
}
```


![image](https://github.com/bevyengine/bevy/assets/13040204/96d7a533-c439-4c0b-8f15-49f620903ce1)


---

## Changelog

- Initial `StateTransition` runs before `PreStartup` instead of inside
`Startup`.
2024-07-15 15:08:54 +00:00
..
computed_states.rs Separate state crate (#13216) 2024-05-09 18:06:05 +00:00
freely_mutable_state.rs Add more granular system sets for state transition schedule ordering (#13763) 2024-06-10 13:13:58 +00:00
mod.rs Make initial StateTransition run before PreStartup (#14208) 2024-07-15 15:08:54 +00:00
resources.rs Fix intra-doc links and make CI test them (#14076) 2024-07-11 13:08:31 +00:00
state_set.rs Add more granular system sets for state transition schedule ordering (#13763) 2024-06-10 13:13:58 +00:00
states.rs Move utilities from examples to bevy_state and add concept of state-scoped entities (#13649) 2024-06-04 11:44:34 +00:00
sub_states.rs Add more granular system sets for state transition schedule ordering (#13763) 2024-06-10 13:13:58 +00:00
transitions.rs Make initial StateTransition run before PreStartup (#14208) 2024-07-15 15:08:54 +00:00