Skip to content

FixedTimeStep systems do not honor their associated app state #8059

Description

@derchr

Bevy version

0.10

What you did

Consider the following Bevy app:

use bevy::prelude::*;

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

fn main() {
    App::new()
        .add_plugins(MinimalPlugins)
        .insert_resource(FixedTime::new_from_secs(1.0))
        .add_state::<AppState>()
        .add_system(transition_state.in_set(OnUpdate(AppState::First)))
        .add_system(
            print_hello
                .in_schedule(CoreSchedule::FixedUpdate)
                .in_set(OnUpdate(AppState::Second)),
        )
        .run();
}

fn transition_state(time: Res<Time>, mut next_state: ResMut<NextState<AppState>>) {
    if time.elapsed_seconds() > 3.0 {
        println!("Transition state!");
        next_state.set(AppState::Second);
    }
}

fn print_hello() {
    println!("Hello!");
}

What went wrong

The print_hello system runs regardless of the application state. It should only run in the AppState::Second state but it runs also in the AppState::First state.
The following output is generated:

Hello!
Hello!
Transition state!
Hello!
Hello!

If line the line with .in_schedule(CoreSchedule::FixedUpdate) is commented out, the output is:

Transition state!
Hello!
Hello!
Hello!

It's as expected. But of course the system is now run every frame.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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