Skip to content

Commit 8c8b843

Browse files
committed
remove duplicate Parent update, properly set PreviousParent
1 parent 1fcafc4 commit 8c8b843

File tree

2 files changed

+5
-28
lines changed

2 files changed

+5
-28
lines changed

crates/bevy_transform/src/hierarchy/child_builder.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,12 @@ pub struct ChildBuilder<'a> {
4747
impl Command for PushChildren {
4848
fn write(self: Box<Self>, world: &mut World, _resources: &mut Resources) {
4949
for child in self.children.iter() {
50+
let previous = match world.get::<Parent>(*child) {
51+
Ok(Parent(previous)) => *previous,
52+
Err(_) => self.parent,
53+
};
5054
world
51-
.insert(*child, (Parent(self.parent), PreviousParent(self.parent)))
55+
.insert(*child, (Parent(self.parent), PreviousParent(previous)))
5256
.unwrap();
5357
}
5458
{

crates/bevy_transform/src/hierarchy/hierarchy_maintenance_system.rs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ pub fn parent_update_system(
2020
}
2121
}
2222

23-
// Tracks all newly created `Children` Components this frame.
24-
let mut children_additions = HashMap::<Entity, SmallVec<[Entity; 8]>>::default();
25-
2623
// Entities with a changed Parent (that also have a PreviousParent, even if None)
2724
for (entity, parent, possible_previous_parent) in parent_query.iter_mut() {
2825
if let Some(mut previous_parent) = possible_previous_parent {
@@ -41,31 +38,7 @@ pub fn parent_update_system(
4138
} else {
4239
commands.insert_one(entity, PreviousParent(parent.0));
4340
};
44-
45-
// Add to the parent's `Children` (either the real component, or
46-
// `children_additions`).
47-
if let Ok(mut new_parent_children) = children_query.get_mut(parent.0) {
48-
// This is the parent
49-
debug_assert!(
50-
!(*new_parent_children).0.contains(&entity),
51-
"children already added"
52-
);
53-
(*new_parent_children).0.push(entity);
54-
} else {
55-
// The parent doesn't have a children entity, lets add it
56-
children_additions
57-
.entry(parent.0)
58-
.or_insert_with(Default::default)
59-
.push(entity);
60-
}
6141
}
62-
63-
// Flush the `children_additions` to the command buffer. It is stored separate to
64-
// collect multiple new children that point to the same parent into the same
65-
// SmallVec, and to prevent redundant add+remove operations.
66-
children_additions.iter().for_each(|(k, v)| {
67-
commands.insert_one(*k, Children::with(v));
68-
});
6942
}
7043
#[cfg(test)]
7144
mod test {

0 commit comments

Comments
 (0)