-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Description
What problem does this solve or what need does it fill?
Currently, the only built-in run condition like this is any_with_component. However, this very quickly loses value on the systems that depend on a combination of components including the provided component type. Compounding any_with_component doesn't address this as it doesn't look at archetypes like a filter does.
Take the following system for example:
fn update(mut enemies: Query<(&EnemyMovement, &mut Transform)>, time: Res<Time>) {
for (movement, mut transform) in enemies.iter_mut() {
transform.translation.y -= time.delta_secs() * movement.speed;
}
}
This is a very basic system, but the built-in run conditions do not provide means to limit the scheduling of this system. If I were to use any_with_component::<EnemyMovement>, this system will still run if there are EnemyMovement components that exist without Transform, and therefore time would be wasted scheduling this system for execution in that frame. Instead, I've used the suggested condition:
app.add_systems(
Update,
update.run_if(any_for_filter::<(With<EnemyMovement>, With<Transform>)>),
);
What solution would you like?
I'm using this in every project in order to appropriately limit my scheduled systems:
pub fn any_for_filter<F: QueryFilter>(entities: Query<(), F>) -> bool {
!entities.is_empty()
}
What alternative(s) have you considered?
No alternatives.
Additional context
N/A