Tainted \\ Coders

Run a system when a resource changes

Last updated:

Use resource_changed in a run_if condition.

app.add_systems(
    Update,
    // `resource_changed` will only return true if the
    // given resource was just changed (or added)
    my_system.run_if(
        resource_changed::<Counter>()
        // By default detecting changes will also trigger if the resource was
        // just added, this won't work with my example so I will addd a second
        // condition to make sure the resource wasn't just added
        .and_then(not(resource_added::<Counter>()))
    ),
);