-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Insert children #17558
base: main
Are you sure you want to change the base?
Insert children #17558
Conversation
Welcome, new contributor! Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨ |
Fixes #17478 |
@@ -185,6 +185,33 @@ impl<'w> EntityWorldMut<'w> { | |||
self.add_related::<ChildOf>(children) | |||
} | |||
|
|||
/// Insert children at specific index |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if the entity is already a child? As a user, I'd like to know whether that is okay ok or not. For example, does doing so reorder it?
); | ||
} | ||
children_component.0.reserve(children.len()); | ||
let mut v = children_component.0.split_off(index); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not update the other side of the relationship (ChildOf
), invalidating the assumptions of the system as a whole.
Objective
This PR implements the requested, previously deprecated feature from #17478. Which is concerning the
insert_children
ofEntityWorldMut
. This method inserts children into the tree, at a specific index.Solution
I mostly copied the code from the deprecated crate
bevy_hierarchy
though this is no longer a trait method.This code also used
SmallVec
which has later been switched byVec
. This was easily interchangeable with working code.Testing
I wrote a unit test covering both
EntityWorldMut::add_entities
andEntityWorldMut::insert_entities
, simply calledhierarchy::tests::insert_children
. I was unsure what error handling architecture i should be using, but i think the simplest to debug in this case would just be a panic in the case of an index out of bounds.Showcase
I find this feature pretty self exoplanetary, but the unit test can also bee informing about what this feature implements:
Click to view showcase