-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Closed
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsA-NetworkingSending data between clients, servers and machinesSending data between clients, servers and machinesA-ScenesSerialized ECS data stored on the diskSerialized ECS data stored on the diskC-BugAn unexpected or incorrect behaviorAn unexpected or incorrect behaviorS-Needs-DesignThis issue requires design work to think about how it would best be accomplishedThis issue requires design work to think about how it would best be accomplished
Description
Bevy version
v0.14.0
What you did
I have a component that stores an entity. The component implements and reflects MapEntities, so on scene deserialization it automatically maps entities inside it.
What went wrong
When I implement on_add hook or OnAdd observer for such component, it triggers before MapEntities which results in invalid entity access.
It happens because we insert components here:
bevy/crates/bevy_scene/src/scene.rs
Lines 117 to 123 in eabb58a
| reflect_component.copy( | |
| &self.world, | |
| world, | |
| scene_entity.id(), | |
| *entity, | |
| &type_registry, | |
| ); |
But entities mapped later:
bevy/crates/bevy_scene/src/scene.rs
Lines 128 to 131 in eabb58a
| for registration in type_registry.iter() { | |
| if let Some(map_entities_reflect) = registration.data::<ReflectMapEntities>() { | |
| map_entities_reflect.map_all_entities(world, entity_map); | |
| } |
I think we should map entities before the insertion.
Metadata
Metadata
Assignees
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsA-NetworkingSending data between clients, servers and machinesSending data between clients, servers and machinesA-ScenesSerialized ECS data stored on the diskSerialized ECS data stored on the diskC-BugAn unexpected or incorrect behaviorAn unexpected or incorrect behaviorS-Needs-DesignThis issue requires design work to think about how it would best be accomplishedThis issue requires design work to think about how it would best be accomplished
Type
Projects
Status
No status