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

Question Researching the duplication of colliders

Discussion in 'Physics for ECS' started by WildMaN, Aug 25, 2023.

  1. WildMaN

    WildMaN

    Joined:
    Jan 24, 2013
    Posts:
    127
    Hi,

    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<Unity.Physics.Collider> instead of expected ~30.

    Code (CSharp):
    1.         Dictionary<BlobAssetReference<Unity.Physics.Collider>, int> d = new Dictionary<BlobAssetReference<Unity.Physics.Collider>, int>();
    2.        
    3.         Entities
    4.             .WithEntityQueryOptions(EntityQueryOptions.IncludeDisabled)
    5.             .ForEach(
    6.             (
    7.                 PhysicsCollider pc
    8.             )
    9.             =>
    10.             {
    11.                 if (d.ContainsKey(pc.Value))
    12.                     d[pc.Value]++;
    13.                 else
    14.                     d.Add(pc.Value, 1);
    15.             }
    16.         ).WithoutBurst().Run();
    17.  
    18.         foreach (var kvp in d)
    19.             Debug.LogFormat("{0} : {1}", kvp.Key, kvp.Value);
    20.  
    21.         Debug.Log(d.Values.Count);

    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.
     
  2. daniel-holz

    daniel-holz

    Unity Technologies

    Joined:
    Sep 17, 2021
    Posts:
    213
    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?
     
  3. WildMaN

    WildMaN

    Joined:
    Jan 24, 2013
    Posts:
    127
    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.

    Unity_lEK5fqRJaO.png
     
  4. daniel-holz

    daniel-holz

    Unity Technologies

    Joined:
    Sep 17, 2021
    Posts:
    213
    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.
     
  5. daniel-holz

    daniel-holz

    Unity Technologies

    Joined:
    Sep 17, 2021
    Posts:
    213
    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.