bevy icon indicating copy to clipboard operation
bevy copied to clipboard

Add ReplaceChildren and ClearChildren EntityCommands

Open taladar opened this issue 2 years ago • 4 comments

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).

taladar avatar Sep 02 '22 09:09 taladar

Hi there! Never contributed before. Can I help with this issue?

ld000 avatar Sep 14 '22 06:09 ld000

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.

mockersf avatar Sep 14 '22 06:09 mockersf

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.

@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?

ld000 avatar Sep 14 '22 11:09 ld000

ClearChildren already exists, or i'm missing something? bevy::hierarchy::DespawnChildrenRecursive

Sergi-Ferrez avatar Sep 15 '22 22:09 Sergi-Ferrez

My suggestion was something to remove children from the parent, not to despawn them.

taladar avatar Sep 16 '22 05:09 taladar