@@ -3,7 +3,9 @@ use crate::{
33 entity:: { DynEntityMapper , Entity , EntityHashMap , MapEntities , SceneEntityMapper } ,
44 world:: World ,
55} ;
6- use bevy_reflect:: { FromReflect , FromType , Reflect } ;
6+ use bevy_reflect:: { FromType , Reflect , TypeRegistry } ;
7+
8+ use super :: from_reflect_with_fallback;
79
810/// For a specific type of component, this maps any fields with values of type [`Entity`] to a new world.
911/// Since a given `Entity` ID is only valid for the world it came from, when performing deserialization
@@ -12,7 +14,7 @@ use bevy_reflect::{FromReflect, FromType, Reflect};
1214/// See [`SceneEntityMapper`] and [`MapEntities`] for more information.
1315#[ derive( Clone ) ]
1416pub struct ReflectMapEntities {
15- map_entities : fn ( & mut dyn Reflect , & mut dyn DynEntityMapper ) ,
17+ map_entities : fn ( & mut World , & TypeRegistry , & mut dyn Reflect , & mut dyn DynEntityMapper ) ,
1618 map_all_world_entities : fn ( & mut World , & mut SceneEntityMapper ) ,
1719 map_world_entities : fn ( & mut World , & mut SceneEntityMapper , & [ Entity ] ) ,
1820}
@@ -26,8 +28,14 @@ impl ReflectMapEntities {
2628 /// entities in a scene, if this is used on a component before ensuring that
2729 /// all entities in the scene have been allocated, a new mapping will be created
2830 /// with a "dead" entity.
29- pub fn map_entities ( & self , component : & mut dyn Reflect , mapper : & mut dyn DynEntityMapper ) {
30- ( self . map_entities ) ( component, mapper) ;
31+ pub fn map_entities (
32+ & self ,
33+ world : & mut World ,
34+ type_registry : & TypeRegistry ,
35+ component : & mut dyn Reflect ,
36+ mapper : & mut dyn DynEntityMapper ,
37+ ) {
38+ ( self . map_entities ) ( world, type_registry, component, mapper) ;
3139 }
3240
3341 /// A general method for applying [`MapEntities`] behavior to all elements in an [`EntityHashMap<Entity>`].
@@ -67,11 +75,11 @@ impl ReflectMapEntities {
6775 }
6876}
6977
70- impl < C : Component + MapEntities + FromReflect > FromType < C > for ReflectMapEntities {
78+ impl < C : Reflect + Component + MapEntities > FromType < C > for ReflectMapEntities {
7179 fn from_type ( ) -> Self {
7280 ReflectMapEntities {
73- map_entities : |component, mut entity_mapper| {
74- let mut concrete = C :: from_reflect ( & * component) . unwrap ( ) ;
81+ map_entities : |world , type_registry , component, mut entity_mapper| {
82+ let mut concrete = from_reflect_with_fallback :: < C > ( component, world , type_registry ) ;
7583 concrete. map_entities ( & mut entity_mapper) ;
7684 component. apply ( & concrete) ;
7785 } ,
0 commit comments