bevy
bevy copied to clipboard
Add ReplaceChildren and ClearChildren EntityCommands
What problem does this solve or what need does it fill?
We have AddChildren, InsertChildren, PushChildren and RemoveChildren but sometimes you just want to remove or replace all existing children without caring what their Entity value is.
What solution would you like?
I would propose the addition of a ClearChildren EntityCommand to remove all children from a parent Entity and a ReplaceChildren command which basically combines this with PushChildren. Potentially a variant of the latter which uses a ChildBuilder might be useful as well though I am not sure about the naming conventions used here.
What alternative(s) have you considered?
It is possible to do this with RemoveChildren but for that we first need to retrieve all existing child Entitys in a separate query (which is especially annoying if we are in a utility function).
Hi there! Never contributed before. Can I help with this issue?
That would be most welcomed!
This PR should probably go in https://github.com/bevyengine/bevy/blob/main/crates/bevy_hierarchy/src/child_builder.rs. When working on hierarchy, the important thing to look out for is to not leave some entities in an invalid state with their Children
or Parent
components.
That would be most welcomed!
This PR should probably go in https://github.com/bevyengine/bevy/blob/main/crates/bevy_hierarchy/src/child_builder.rs. When working on hierarchy, the important thing to look out for is to not leave some entities in an invalid state with their
Children
orParent
components.
@mockersf So I think adding command structs and clear_children(&mut self)
, replace_children(&mut self, children: &[Enity])
functions to the BuildChildren
trait will fix this? And do I need to add these two functions in the BuildWorldChildren
trait too?
ClearChildren already exists, or i'm missing something? bevy::hierarchy::DespawnChildrenRecursive
My suggestion was something to remove children from the parent, not to despawn them.