diff --git a/crates/bevy_ecs/src/schedule/condition.rs b/crates/bevy_ecs/src/schedule/condition.rs index 24d80040cf2af..6eb4e93e00888 100644 --- a/crates/bevy_ecs/src/schedule/condition.rs +++ b/crates/bevy_ecs/src/schedule/condition.rs @@ -142,7 +142,7 @@ pub mod common_conditions { use crate::{ change_detection::DetectChanges, event::{Event, EventReader}, - prelude::{Component, Query, With}, + prelude::{Added, Changed, Component, Query, With}, removal_detection::RemovedComponents, schedule::{State, States}, system::{IntoSystem, Res, Resource, System}, @@ -894,6 +894,26 @@ pub mod common_conditions { move |query: Query<(), With>| !query.is_empty() } + /// Generates a [`Condition`](super::Condition)-satisfying closure that returns `true` + /// if the given component type was added to any entities. + /// + /// Run conditions are evaluated on the main thread, blocking any other systems from running. + /// This run condition is relatively expensive, as it iterates over every entity with this component. + /// As a result, you likely only want to use this run condition when the number of entities with the component `T` is small. + pub fn any_component_added() -> impl FnMut(Query<(), Added>) -> bool { + move |query: Query<(), Added>| !query.is_empty() + } + + /// Generates a [`Condition`](super::Condition)-satisfying closure that returns `true` + /// if the value of the given component type has been changed on any entities. + /// + /// Run conditions are evaluated on the main thread, blocking any other systems from running. + /// This run condition is relatively expensive, as it iterates over every entity with this component. + /// As a result, you likely only want to use this run condition when the number of entities with the component `T` is small. + pub fn any_component_changed() -> impl FnMut(Query<(), Changed>) -> bool { + move |query: Query<(), Changed>| !query.is_empty() + } + /// Generates a [`Condition`](super::Condition)-satisfying closure that returns `true` /// if there are any entity with a component of the given type removed. pub fn any_component_removed() -> impl FnMut(RemovedComponents) -> bool {