pub fn resource_exists<T>(res: Option<Res<'_, T>>) -> boolwhere
T: Resource,
Expand description
A Condition
-satisfying system that returns true
if the resource exists.
ยงExample
app.add_systems(
// `resource_exists` will only return true if the given resource exists in the world
my_system.run_if(resource_exists::<Counter>),
);
fn my_system(mut counter: ResMut<Counter>) {
counter.0 += 1;
}
// `Counter` hasn't been added so `my_system` won't run
app.run(&mut world);
world.init_resource::<Counter>();
// `Counter` has now been added so `my_system` can run
app.run(&mut world);
assert_eq!(world.resource::<Counter>().0, 1);