Function bevy::ecs::prelude::resource_exists
pub fn resource_exists<T>() -> impl FnMut(Option<Res<'_, T>>) + Clonewhere
T: Resource,
Expand description
Generates a Condition
-satisfying closure 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);