Skip to content

Commit cf161c2

Browse files
committed
ensure ragdolls are despawned with scenes
1 parent 75994ec commit cf161c2

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

  • crates/bevy_animation_graph/src/core

crates/bevy_animation_graph/src/core/plugin.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ impl Plugin for AnimationGraphPlugin {
8282
self.register_assets(app);
8383
self.register_types(app);
8484
self.register_nodes(app);
85+
self.register_component_hooks(app);
8586

8687
app.configure_sets(
8788
self.physics_schedule,
@@ -263,4 +264,19 @@ impl AnimationGraphPlugin {
263264
app.register_type::<RelativeKinematicBody>();
264265
app.register_type::<RelativeKinematicBodyPositionBased>();
265266
}
267+
268+
fn register_component_hooks(&self, app: &mut App) {
269+
app.world_mut()
270+
.register_component_hooks::<AnimationGraphPlayer>()
271+
.on_replace(|mut world, context| {
272+
if let Some(spawned_ragdoll) = world
273+
.entity(context.entity)
274+
.get::<AnimationGraphPlayer>()
275+
.and_then(|p| p.spawned_ragdoll.as_ref())
276+
.map(|s| s.root)
277+
{
278+
world.commands().entity(spawned_ragdoll).despawn();
279+
}
280+
});
281+
}
266282
}

0 commit comments

Comments
 (0)