bevy_ecs::schedule::common_conditions

Function run_once

Source
pub fn run_once(has_run: Local<'_, bool>) -> bool
Expand description

A Condition-satisfying system that returns true on the first time the condition is run and false every time after.

ยงExample

app.add_systems(
    // `run_once` will only return true the first time it's evaluated
    my_system.run_if(run_once),
);

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

// This is the first time the condition will be evaluated so `my_system` will run
app.run(&mut world);
assert_eq!(world.resource::<Counter>().0, 1);

// This is the seconds time the condition will be evaluated so `my_system` won't run
app.run(&mut world);
assert_eq!(world.resource::<Counter>().0, 1);