Skip to content

Commit 1ae7ec9

Browse files
committed
Use FromReflect when replicating components into dynamic scenes
For details see bevyengine/bevy#15174
1 parent 9826d5d commit 1ae7ec9

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff 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

src/scene.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)