Skip to content

Commit

Permalink
Expose current_entity in ChildBuilder (#595)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregoor authored Oct 1, 2020
1 parent 3a4eacb commit 056f84a
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions crates/bevy_transform/src/hierarchy/child_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ impl<'a> ChildBuilder<'a> {
self
}

pub fn current_entity(&self) -> Option<Entity> {
self.commands.current_entity
}

pub fn with_bundle(
&mut self,
components: impl DynamicBundle + Send + Sync + 'static,
Expand Down Expand Up @@ -215,6 +219,7 @@ mod tests {
let mut parent = None;
let mut child1 = None;
let mut child2 = None;
let mut child3 = None;

commands
.spawn((1,))
Expand All @@ -224,14 +229,18 @@ mod tests {
.spawn((2,))
.for_current_entity(|e| child1 = Some(e))
.spawn((3,))
.for_current_entity(|e| child2 = Some(e));
.for_current_entity(|e| child2 = Some(e))
.spawn((4,));

child3 = parent.current_entity();
});

commands.apply(&mut world, &mut resources);
let parent = parent.expect("parent should exist");
let child1 = child1.expect("child1 should exist");
let child2 = child2.expect("child2 should exist");
let expected_children: SmallVec<[Entity; 8]> = smallvec![child1, child2];
let child3 = child3.expect("child3 should exist");
let expected_children: SmallVec<[Entity; 8]> = smallvec![child1, child2, child3];

assert_eq!(
world.get::<Children>(parent).unwrap().0.clone(),
Expand Down

0 comments on commit 056f84a

Please sign in to comment.