File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed
Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
88## [ Unreleased]
99
10+ ### Fixed
11+
12+ - Use ` FromReflect ` when replicating components into dynamic scenes.
13+
1014## [ 0.29.1] - 2024-12-16
1115
1216### Fixed
Original file line number Diff line number Diff line change @@ -90,18 +90,28 @@ pub fn replicate_into(scene: &mut DynamicScene, world: &World) {
9090 debug ! ( "ignoring `{type_name}` because it's missing `#[reflect(Component)]`" ) ;
9191 continue ;
9292 } ;
93+ let from_reflect = registration
94+ . data :: < ReflectFromReflect > ( )
95+ . unwrap_or_else ( || panic ! ( "`{type_name}` should reflect `FromReflect`" ) ) ;
9396
9497 for entity in archetype. entities ( ) {
9598 let component = reflect_component
9699 . reflect ( world. entity ( entity. id ( ) ) )
97100 . unwrap_or_else ( || panic ! ( "entity should have `{type_name}`" ) ) ;
98101
102+ // Clone via `FromReflect`. Unlike `PartialReflect::clone_value` this
103+ // retains the original type and `ReflectSerialize` type data which is needed to
104+ // deserialize.
105+ let component = from_reflect
106+ . from_reflect ( component. as_partial_reflect ( ) )
107+ . unwrap_or_else ( || panic ! ( "`{type_name}` should be dynamically clonable" ) ) ;
108+
99109 let components = entities
100110 . get_mut ( & entity. id ( ) )
101111 . expect ( "all entities should be populated ahead of time" ) ;
102112
103113 debug ! ( "adding `{type_name}` to `{}`" , entity. id( ) ) ;
104- components. push ( component. clone_value ( ) ) ;
114+ components. push ( component. into_partial_reflect ( ) ) ;
105115 }
106116 }
107117 }
You can’t perform that action at this time.
0 commit comments