pub fn state_exists<S: States>(
    
) -> impl FnMut(Option<Res<'_, State<S>>>) -> bool + Clone
Expand description

Generates a Condition-satisfying closure that returns true if the state machine exists.

Example

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

app.add_system(
    // `state_exists` will only return true if the
    // given state exsists
    my_system.run_if(state_exists::<GameState>()),
);

fn my_system(mut counter: ResMut<Counter>) {
    counter.0 += 1;
}

// `GameState` does not yet exist `my_system` won't run
app.run(&mut world);
assert_eq!(world.resource::<Counter>().0, 0);

world.init_resource::<State<GameState>>();

// `GameState` now exists so `my_system` will run
app.run(&mut world);
assert_eq!(world.resource::<Counter>().0, 1);