File tree Expand file tree Collapse file tree
crates/bevy_animation_graph/src/core Expand file tree Collapse file tree Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments