Tainted \\ Coders

Run a system conditionally

Last updated:

Use run conditions when adding the system.

fn main() {
    App::new()
    ...
    .add_systems(
        Update,
        increment_input_counter
            // The common_conditions module has a few useful run conditions
            // for checking resources and states. These are included in the prelude.
            .run_if(resource_exists::<InputCounter>())
            // This is a custom run condition, defined using a system that returns
            // a `bool` and which has read-only `SystemParam`s.
            // Both run conditions must return `true` in order for the system to run.
            // Note that this second run condition will be evaluated even if the first returns `false`.
            .run_if(has_user_input)
    )
}