use aery::prelude::*; use bevy::{app::AppExit, prelude::*}; #[derive(Relation)] struct ChildOf; #[derive(Component)] struct Name(&'static str); fn setup(mut cmds: Commands) { cmds.spawn(Name("Alice")).scope::(|chld| { chld.add(Name("Jack")) .scope::(|chld| { chld.add(Name("Dave")); }) .add(Name("Jill")) .scope::(|chld| { chld.add(Name("Stephen")).add(Name("Sam")); }); }); cmds.spawn(Name("Loyd")).scope::(|chld| { chld.add(Name("Anya")); }); } fn display_children(tree: Query<(&Name, Relations)>, roots: Query>) { tree.traverse::(roots.iter()) .track_self() .for_each(|Name(parent), _, Name(child), _| { println!("{} is the parent of {}", parent, child); }); } fn exit(mut exit: EventWriter) { exit.send(AppExit::Success); } fn main() { App::new() .add_systems(Startup, setup) .add_systems(Update, (display_children, exit).chain()) .run(); }