Fix dynamic scene resources not being entity mapped (#18395)

# Objective

The resources were converted via `clone_reflect_value` and the cloned
value was mapped. But the value that is inserted is the source of the
clone, which was not mapped.

I ran into this issue while working on #18380. Having non consecutive
entity allocations has caught a lot of bugs.

## Solution

Use the cloned value for insertion if it exists.
This commit is contained in:
Eagster 2025-03-18 16:04:55 -04:00 committed by GitHub
parent 5d0505a85e
commit 339914b0af
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -149,16 +149,22 @@ impl DynamicScene {
// If this component references entities in the scene, update
// them to the entities in the world.
if let Some(map_entities) = registration.data::<ReflectMapEntities>() {
let mut resource = clone_reflect_value(resource.as_partial_reflect(), registration);
let mut cloned_resource;
let partial_reflect_resource = if let Some(map_entities) =
registration.data::<ReflectMapEntities>()
{
cloned_resource = clone_reflect_value(resource.as_partial_reflect(), registration);
SceneEntityMapper::world_scope(entity_map, world, |_, mapper| {
map_entities.map_entities(resource.as_partial_reflect_mut(), mapper);
map_entities.map_entities(cloned_resource.as_partial_reflect_mut(), mapper);
});
}
cloned_resource.as_partial_reflect()
} else {
resource.as_partial_reflect()
};
// If the world already contains an instance of the given resource
// just apply the (possibly) new value, otherwise insert the resource
reflect_resource.apply_or_insert(world, resource.as_partial_reflect(), &type_registry);
reflect_resource.apply_or_insert(world, partial_reflect_resource, &type_registry);
}
Ok(())