@@ -82,7 +82,7 @@ impl<C: AnyCollider> Plugin for ColliderTreeUpdatePlugin<C> {
8282 //
8383 // 1. On insert `C` or `ColliderOf`, add to new tree if not already present. Remove from old tree if present.
8484 // 2. On remove `C`, remove from tree.
85- // 3. On remove `ColliderOf`, remove from tree, move to standalone tree if `C` still exists.
85+ // 3. On remove `ColliderOf`, move to standalone tree if `C` still exists.
8686 // 4. On re-enable `C`, add to tree.
8787 // 5. On disable `C`, remove from tree.
8888 // 6. On add `Sensor`, set sensor proxy flag.
@@ -91,7 +91,7 @@ impl<C: AnyCollider> Plugin for ColliderTreeUpdatePlugin<C> {
9191 // 9. On replace `ActiveCollisionHooks`, set proxy flag.
9292
9393 // Case 1
94- app. add_observer ( add_to_tree_on :: < Add , ( C , ColliderOf ) , Without < ColliderDisabled > > ) ;
94+ app. add_observer ( add_to_tree_on :: < Insert , ( C , ColliderOf ) , Without < ColliderDisabled > > ) ;
9595
9696 // Case 2
9797 app. add_observer (
@@ -101,14 +101,17 @@ impl<C: AnyCollider> Plugin for ColliderTreeUpdatePlugin<C> {
101101 // Case 3
102102 app. add_observer (
103103 |trigger : On < Remove , ColliderOf > ,
104- mut collider_query : Query < (
105- & ColliderTreeProxyKey ,
106- & ColliderAabb ,
107- & EnlargedAabb ,
108- Option < & CollisionLayers > ,
109- Has < Sensor > ,
110- Option < & ActiveCollisionHooks > ,
111- ) > ,
104+ mut collider_query : Query <
105+ (
106+ & ColliderTreeProxyKey ,
107+ & ColliderAabb ,
108+ & EnlargedAabb ,
109+ Option < & CollisionLayers > ,
110+ Has < Sensor > ,
111+ Option < & ActiveCollisionHooks > ,
112+ ) ,
113+ With < C > ,
114+ > ,
112115 mut trees : ResMut < ColliderTrees > ,
113116 mut moved_proxies : ResMut < MovedProxies > | {
114117 let entity = trigger. entity ;
@@ -121,7 +124,9 @@ impl<C: AnyCollider> Plugin for ColliderTreeUpdatePlugin<C> {
121124
122125 // Remove the proxy from its current tree.
123126 let tree = trees. tree_for_type_mut ( proxy_key. tree_type ( ) ) ;
124- tree. remove_proxy ( proxy_key. id ( ) ) ;
127+ if !tree. remove_proxy ( proxy_key. id ( ) ) {
128+ return ;
129+ }
125130
126131 // If the collider still exists, move it to the standalone tree.
127132 let aabb = Aabb :: from ( * collider_aabb) ;
0 commit comments