Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Expected performance of dynamic CompoundColliders?

Discussion in 'Physics for ECS' started by zachlindblad, Dec 15, 2019.

  1. zachlindblad


    Sep 29, 2016
    Hi, so I've been running some experiments, here's a little context: I have a project that's highly ECS/DOTS based, but it requires a lot of changes to colliders. Making these changes in ECS, then piping them over to PhysX had been my performance bottleneck up till now so even though I know it's early I thought I'd allocate a few days to try out unity physics.
    I've really liked the API, but I'm seeing an issue with performance in my compoundcollider objects
    Basically when this:

    hits a static boxCollider my framerate tanks to 15FPS:

    Using single non-compound colliders has no issue. I can spawn dozens of those with not even a bump in the profiler, it's only when I make a compound object like this that I see problems.

    I know in this case I could just be using one box collider for the whole thing, but it's destructible, so I need to be able to add/remove cells from that compound collider on the fly.

    PhysX handles this case...adequately. It struggles a little bit when complex compound colliders approach other complex compounds, but not on hitting a simple box collider, and not to this extent.

    The creation process I'm using is something like this (chopped up for brevity obviously):
    Code (CSharp):
    1. //....
    2. NativeArray<CompoundCollider.ColliderBlobInstance> childColliders =
    3.             new NativeArray<CompoundCollider.ColliderBlobInstance>(identifiers.Length, Allocator.TempJob,NativeArrayOptions.UninitializedMemory);
    5.         new CreateShipUnityColliders()
    6.         {
    7.             cellSize =  cellSize,
    8.             childColliders = childColliders,
    9.             identifiers = identifiers,
    10.             indicies = indicies,
    11.             wallCollider = UBoxCollider.Create(new BoxGeometry(){BevelRadius = 0,Center =,Orientation = quaternion.identity,Size = cellSize},CollisionFilter.Default),
    12.             floorCollider = UBoxCollider.Create(new BoxGeometry(){BevelRadius = 0,Center = new float3(0,-cellSize.y/2f,0)
    13.                 ,Orientation = quaternion.identity,Size = new float3(cellSize.x,.1f,cellSize.z)},CollisionFilter.Default),
    14.             COG = COM
    16.         }.Schedule(identifiers.Length,64).Complete();
    17.         var ncollider = CompoundCollider.Create(childColliders);
    18.         childColliders.Dispose();
    19.         var colliderComponent = new PhysicsCollider { Value = ncollider };
    20.         entityManager.SetComponentData(entity,colliderComponent);
    22. //....
    23. public struct CreateShipUnityColliders : IJobParallelFor
    24. {
    25.    //....
    26.     public void Execute(int index)
    27.     {
    28.         childColliders[index] = new CompoundCollider.ColliderBlobInstance
    29.         {
    30.             CompoundFromChild = new RigidTransform(quaternion.identity, new float3(indicies[index].x*cellSize.x, 0, indicies[index].y*cellSize.z)),
    32.             Collider = identifiers[index] != uint.MaxValue ? wallCollider : floorCollider
    33.         };
    34.     }
    35. }
    (EDIT: ok, so I'm fairly certain this is a bug, as on further testing, this slowdown only occurs upon the FIRST dynamic compound body touching my static ground collider. I can spawn literal OODLES of these complex compound colliders, and after the first one, there's absolutely no significant performance hit. Has anyone else had this problem with a first collision slowdown? Specifically with the NarrowPhase ProcessBodyPairs job hanging as pictured in the profiler above. I'm on the newest 0.2.4 unity physics version)

    TL;DR questions:
    1. Are compoundColliders with many children a case that is performing well for others, and I'm doing something wrong with the setup?

    2. Are compoundColliders with many children a case that will ever perform well in UnityPhysics?
    3.How many child colliders should I be able to put in a dynamic compoundCollider object in unityPhysics and expect it to be performant? (I know it'd be more performant to absorb these box cells into larger convex shapes, but at what point should I expect to hit that upper limit of complexity?)

    I've seen another post about compound colliders with hundreds of thousands of children performing at 100fps (, but in his video I didn't see it colliding with anything, guessing it was only raycasts?

    Anyways,thanks for taking a look.
    Last edited: Dec 15, 2019
  2. Rory_Havok


    Jun 25, 2018
    Hi, the job has not yet been Burst compiled when you see it being slow - you can tell by it not having the "(Burst)" suffix in the profiler. If you enable synchronous compilation you will see it fast the first time too.