Function bevy_ecs::schedule::common_conditions::resource_added
source · pub fn resource_added<T>(res: Option<Res<'_, T>>) -> boolwhere
T: Resource,
Expand description
A Condition
-satisfying system that returns true
if the resource of the given type has been added since the condition was last checked.
§Example
app.add_systems(
// `resource_added` will only return true if the
// given resource was just added
my_system.run_if(resource_added::<Counter>),
);
fn my_system(mut counter: ResMut<Counter>) {
counter.0 += 1;
}
world.init_resource::<Counter>();
// `Counter` was just added so `my_system` will run
app.run(&mut world);
assert_eq!(world.resource::<Counter>().0, 1);
// `Counter` was not just added so `my_system` will not run
app.run(&mut world);
assert_eq!(world.resource::<Counter>().0, 1);