Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multiple states and scheduling #8234

Closed
jfouche opened this issue Mar 28, 2023 · 2 comments
Closed

multiple states and scheduling #8234

jfouche opened this issue Mar 28, 2023 · 2 comments
Labels
A-ECS Entities, components, systems, and events C-Bug An unexpected or incorrect behavior
Milestone

Comments

@jfouche
Copy link

jfouche commented Mar 28, 2023

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.

@jfouche jfouche added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Mar 28, 2023
@alice-i-cecile alice-i-cecile added A-ECS Entities, components, systems, and events and removed S-Needs-Triage This issue needs to be labelled labels Mar 28, 2023
@alice-i-cecile
Copy link
Member

Use in_state(AppState::InGame) . OnEnter only works in the main schedule.

@joseph-gio
Copy link
Member

I believe this is resolved by #8260, since removing the OnUpdate set also removes this footgun.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Bug An unexpected or incorrect behavior
Projects
None yet
Development

No branches or pull requests

3 participants