Recreate AABB for a compound collider?

Hello!
I tried to change collider in runtime with this method

https://github.com/Unity-Technologies/EntityComponentSystemSamples/blob/master/PhysicsSamples/Assets/9. Modify/Box Collider Size/BoxColliderSizeSystem.cs

When I deal with a compound collider, AABB is not affected (I could see it Physics Debug Display, red = AABB, green = compoundCollider and light green = classic unity collider)
the compound collider is combined with three box colliders which have different physics material template.

How can I change its AABB?

I'm using Unity Physics 1.0.11.

Code what I used

                    CompoundCollider* compoundCollider_p = (CompoundCollider*)physicsCollider.ValueRW.Value.GetUnsafePtr();

                    BoxCollider* ptr = (BoxCollider*)compoundCollider_p->Children[2].Collider;
                    var interactionColliderInfo = obj.GetColliderInfo(0);
                    var geometry = ptr->Geometry;
                    geometry.Size = interactionColliderInfo.size;
                    geometry.Center = interactionColliderInfo.center;
                    ptr->Geometry = geometry;

                    ptr = (BoxCollider*)compoundCollider_p->Children[0].Collider;
                    var hitBoxColliderInfo = obj.GetColliderInfo(1);
                    geometry = ptr->Geometry;
                    geometry.Size = hitBoxColliderInfo.size;
                    geometry.Center = hitBoxColliderInfo.center;
                    ptr->Geometry = geometry;

                    ptr = (BoxCollider*)compoundCollider_p->Children[1].Collider;
                    var attackColliderInfo = obj.GetColliderInfo(2);
                    geometry = ptr->Geometry;
                    geometry.Size = attackColliderInfo.size;
                    geometry.Center = attackColliderInfo.center;
                    ptr->Geometry = geometry;

9106120--1262509--picture.PNG

It is currently unfortunately not possible to incrementally update the bounding volume information (the bounding volume tree and the AABB) inside a compound collider.
You will need to recreate the compound collider with the Compound.Create function, by passing it all its children once your modifications are complete, and then reset the Collider blob asset reference in the PhysicsCollider component of the entity.

Note that you will need to manually dispose of this additional compound collider when the entity is destroyed, e.g., via the ICleanupComponentData interface, which allows you to add a system that queries specifically for destroyed entities that still require some cleanup (disposal of the additional collider blob you created).
See this documentation section for how to achieve this.

1 Like