Skip to content
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

Expose current_entity in ChildBuilder #595

Merged
merged 1 commit into from
Oct 1, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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