Skip to content

Commit

Permalink
add swap method and update comments
Browse files Browse the repository at this point in the history
  • Loading branch information
cart committed Nov 22, 2020
1 parent 0ee990a commit 7413e32
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 5 additions & 0 deletions crates/bevy_transform/src/components/children.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ impl Children {
pub fn with(entity: &[Entity]) -> Self {
Self(SmallVec::from_slice(entity))
}

/// Swaps the child at `a_index` with the child at `b_index`
pub fn swap(&mut self, a_index: usize, b_index: usize) {
self.0.swap(a_index, b_index);
}
}

impl Deref for Children {
Expand Down
3 changes: 0 additions & 3 deletions examples/ecs/hierarchy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,6 @@ fn rotate(

// To demonstrate removing children, we'll start to remove the children after a couple of seconds
if time.seconds_since_startup >= 2.0 && children.len() == 3 {
// Using .despawn() on an entity does not remove it from its parent's list of children!
// It must be done manually if using .despawn()
// NOTE: This is a bug. Eventually Bevy will update the children list automatically
let child = children.last().copied().unwrap();
commands.despawn(child);
}
Expand Down

0 comments on commit 7413e32

Please sign in to comment.