Researching the duplication of colliders


For the game I've released one issue is still outstanding, being the bloated subscenes size, about 4x the size of entities' archetype sizes. I suspected colliders to be the issue, and during the Q&A yesterday a Unity representative suggested the same.

So I did a test in a scene of ~30k entities of ~30 prefabs (i.e. I have hundreds and hundreds of identical blocks) and surprisingly it showed me ~4.200 unique BlobAssetReference instead of expected ~30.

C# code


        Dictionary<BlobAssetReference<Unity.Physics.Collider>, int> d = new Dictionary<BlobAssetReference<Unity.Physics.Collider>, int>();

                PhysicsCollider pc
                if (d.ContainsKey(pc.Value))
                    d.Add(pc.Value, 1);

        foreach (var kvp in d)
            Debug.LogFormat("{0} : {1}", kvp.Key, kvp.Value);



Now, I don't know much about those blobs and how colliders are stored, and maybe all those 4200 are just pointers to the mere 30 unique prefabs and their colliders that I have. Would appreciate any hints to resolve this.

Could you please use the actual raw collider pointer as a key of type IntPtr in your dictionary to confirm that these are actually distinct blocks of memory?

var colliderPtr = (IntPtr) pc.ColliderPtr

Also, how do you create the entity prefab instances? I suppose you are creating an entity prefab and instantiate it using EntityManager.Instantiate, right?

Same result, way too many unique values.

No, all scenes are pre-authored and all entities are placed in Editor. I meant that I'm placing usual GameObject prefabs to be converted, so 100% sure there are no unique types, sizes, filters, and material combinations.

Based on the vast majority of pointers having 1-4 references, my guess is that it doesn't recognize similar colliders. Here's a scene view - the selected 8 entities are exactly the same prefabs, but they belong to two different parents, which have their own respective physics bodies and colliders. So despite being unparented, this relationship somehow breaks the recognition of unique colliders? That's my only guess.


This is interesting. We haven't observed that here internally. This might be caused by a specific kind of structure in your scene. Would you be able to create a minimal scene that shows this issue and provide it to us through the bug reporting system?

You can post the issue id here afterwards.

To show that the issue persists in your minimal reproduction scene, after entering playmode, you can simply activate the Entities Hierarchy window, select a few entities that should have the same collider blobs and then in the Inspector navigate to the PhysicsCollider component which shows you the blob hash. The blob hash for these entities should theoretically be identical but in your case they would not be, showing that there is an issue.