Function moonshine_check::purge
source · pub fn purge() -> PolicyExpand description
Returns a Policy which despawns matching instances and all of their children.
§Usage
Use this policy to remove invalid entities from the world.
§Example
use bevy::prelude::*;
use moonshine_check::prelude::*;
#[derive(Bundle, Default)]
struct AB {
a: A,
b: B,
}
#[derive(Component, Default)]
struct A;
#[derive(Component, Default)]
struct B;
let mut app = App::new();
app.add_plugins(MinimalPlugins)
.check::<A, Without<B>>(purge())
.add_systems(Update, update);
app.world_mut().spawn(AB::default()); // OK!
app.world_mut().spawn(A); // Bug! `B` is missing!
app.update();
fn update(items: Query<Entity, With<A>>, query: Query<&B>) {
for entity in items.iter() {
// Guaranteed:
assert!(query.contains(entity));
}
}