Function bevy_internal::ecs::schedule::common_conditions::run_once
source · pub fn run_once() -> impl FnMut() + Clone
Expand description
Generates a Condition
-satisfying closure that returns true
if 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);