Skip to content

multiple states and scheduling #8234

@jfouche

Description

@jfouche

Bevy version : 0.10 on Win10-64

What you did

I'm starting learning new states in Bevy. I tried the following code, assuming that when using 2 states, I could manage both when defining set and scheduling :

    use bevy::prelude::*;

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

    #[derive(States, Debug, Clone, Copy, Eq, PartialEq, Hash, Default)]
    enum SimulationState {
        Running,
        #[default]
        Paused,
    }

    #[test]
    fn test_multiple_states() {
        let mut app = App::new();
        app.add_state::<AppState>()
            .add_state::<SimulationState>()
            .add_system(
                spawn_pause_menu
                    .in_set(OnUpdate(AppState::InGame))
                    .in_schedule(OnEnter(SimulationState::Paused)),
            )
            .run();

        fn spawn_pause_menu(mut _commands: Commands) {
            panic!("Pause menu spawned");
        }
    }

What went wrong

Here, the test failed, because the pause menu was spawn but the AppState is not InGame, but MainMenu. I suppose that the spawn_pause_menu is called because it entered SimulationState::Paused, not checking the in_set(OnUpdate(AppState::InGame)). Is that expected? If the answer is yes, I would like an explanation on how should I manage this case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-BugAn unexpected or incorrect behavior

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions