Function moonshine_check::invalid
source · pub fn invalid() -> PolicyExpand description
Returns a Policy which despawns matching instances and all of their children.
§Usage
Use this policy with Valid to allow systems to safely ignore invalid entities.
§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>>(invalid())
.add_systems(Update, update_valid);
app.world_mut().spawn(AB::default()); // OK!
app.world_mut().spawn(A); // Bug! `B` is missing!
app.update();
fn update_valid(items: Query<Entity, (With<A>, Valid)>, query: Query<&B>) {
for entity in items.iter() {
// Guaranteed:
assert!(query.contains(entity));
}
}