You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently WithChild and WithChildren only register an on_add hook. This is incredibly convenient for bundling up hierarchies, but feels like it's missing a way to automatically remove these child components.
An alternative design might be to also register child removal during on_remove. This may add overhead while despawning a hierarchy, but I think for most cases it would be preferred to remove the spawned child components when WithChild or WithChildren is removed.
letmut world = World::default();let parent = world.spawn(WithChild::new((A,B(3)))).id();// FIXME: this should not be needed!
world.flush();assert!(!world.entity(parent).contains::<A>());assert!(!world.entity(parent).contains::<B>());let children = world.get::<Children>(parent).unwrap();assert_eq!(children.len(),1);let child_entity = children[0];assert_eq!(world.get::<A>(child_entity),Some(&A));assert_eq!(world.get::<B>(child_entity),Some(&B(3)));
world.entity_mut(parent).remove::<WithChild<(A,B)>>();// FIXME: this should not be needed!
world.flush();assert!(world.get::<A>(child_entity).is_none());assert!(world.get::<B>(child_entity).is_none());
The text was updated successfully, but these errors were encountered:
Currently
WithChild
andWithChildren
only register anon_add
hook. This is incredibly convenient for bundling up hierarchies, but feels like it's missing a way to automatically remove these child components.An alternative design might be to also register child removal during
on_remove
. This may add overhead while despawning a hierarchy, but I think for most cases it would be preferred to remove the spawned child components whenWithChild
orWithChildren
is removed.The text was updated successfully, but these errors were encountered: