pub fn resource_added<T>() -> impl FnMut(Option<Res<'_, T>>) -> bool + Clonewhere
    T: Resource,
Expand description

Generates a Condition-satisfying closure that returns true if the resource of the given type has been added since the condition was last checked.

Example

app.add_system(
    // `resource_added` will only return true if the
    // given resource was just added
    my_system.run_if(resource_added::<Counter>()),
);

fn my_system(mut counter: ResMut<Counter>) {
    counter.0 += 1;
}

world.init_resource::<Counter>();

// `Counter` was just added so `my_system` will run
app.run(&mut world);
assert_eq!(world.resource::<Counter>().0, 1);

// `Counter` was not just added so `my_system` will not run
app.run(&mut world);
assert_eq!(world.resource::<Counter>().0, 1);