Function bevy_ecs::schedule::common_conditions::resource_removed

source ·
pub fn resource_removed<T>() -> impl FnMut(Option<Res<'_, T>>) -> bool + Clone
where T: Resource,
Expand description

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

§Example

app.add_systems(
    // `resource_removed` will only return true if the
    // given resource was just removed
    my_system.run_if(resource_removed::<MyResource>()),
);

#[derive(Resource, Default)]
struct MyResource;

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

world.init_resource::<MyResource>();

// `MyResource` hasn't just been removed so `my_system` won't run
app.run(&mut world);
assert_eq!(world.resource::<Counter>().0, 0);

world.remove_resource::<MyResource>();

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