pub fn any_with_component<T: Component>(
query: Query<'_, '_, (), With<T>>,
) -> boolExpand description
A SystemCondition-satisfying system that returns true
if there are any entities with the given component type.
This is equivalent to any_match_filter::<With<T>>()
To skip a system with a Query parameter if the query is empty,
you may instead use Populated, if the query may match multiple entities,
or Single, if it will only match one.
ยง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);