Skip to content

Commit 286c788

Browse files
committed
fix Parent and PreviousParent entity mapping
1 parent 2e35c21 commit 286c788

File tree

1 file changed

+10
-2
lines changed
  • crates/bevy_transform/src/components

1 file changed

+10
-2
lines changed

crates/bevy_transform/src/components/parent.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ impl FromWorld for Parent {
2222

2323
impl MapEntities for Parent {
2424
fn map_entities(&mut self, entity_map: &EntityMap) -> Result<(), MapEntitiesError> {
25-
self.0 = entity_map.get(self.0)?;
25+
// Parent of an entity in the new world can be in outside world, in which case it
26+
// should not be mapped.
27+
if let Ok(mapped_entity) = entity_map.get(self.0) {
28+
self.0 = mapped_entity;
29+
}
2630
Ok(())
2731
}
2832
}
@@ -47,7 +51,11 @@ pub struct PreviousParent(pub(crate) Entity);
4751

4852
impl MapEntities for PreviousParent {
4953
fn map_entities(&mut self, entity_map: &EntityMap) -> Result<(), MapEntitiesError> {
50-
self.0 = entity_map.get(self.0)?;
54+
// PreviousParent of an entity in the new world can be in outside world, in which
55+
// case it should not be mapped.
56+
if let Ok(mapped_entity) = entity_map.get(self.0) {
57+
self.0 = mapped_entity;
58+
}
5159
Ok(())
5260
}
5361
}

0 commit comments

Comments
 (0)