Function valence::ecs::schedule::common_conditions::any_with_component
pub fn any_with_component<T>(query: Query<'_, '_, (), With<T>>) -> boolwhere
T: Component,
Expand description
A Condition
-satisfying system that returns true
if there are any entities with the given component type.
ยงExample
app.add_systems(
my_system.run_if(any_with_component::<MyComponent>),
);
#[derive(Component)]
struct MyComponent;
fn my_system(mut counter: ResMut<Counter>) {
counter.0 += 1;
}
// No entities exist yet with a `MyComponent` component so `my_system` won't run
app.run(&mut world);
assert_eq!(world.resource::<Counter>().0, 0);
world.spawn(MyComponent);
// An entities with `MyComponent` now exists so `my_system` will run
app.run(&mut world);
assert_eq!(world.resource::<Counter>().0, 1);