Search Unity

CompoundCollider Filter Error Not Union Of Children

Discussion in 'Physics for ECS' started by alfiare, May 6, 2021.

  1. alfiare

    alfiare

    Joined:
    Feb 10, 2017
    Posts:
    30
    I can't explain why this happens or why the fix works, maybe it's a bug. I am creating a compound collider using the following code

    Code (CSharp):
    1. NativeArray<CompoundCollider.ColliderBlobInstance> colliderArray = new NativeArray<CompoundCollider.ColliderBlobInstance>(3, Allocator.Temp);
    2.  
    3.                 colliderArray[0] = new CompoundCollider.ColliderBlobInstance()
    4.                 {
    5.                     Collider = Unity.Physics.SphereCollider.Create(
    6.                     new SphereGeometry() { Center = float3.zero, Radius = privateModel.HeatSignatureSize },
    7.                     new CollisionFilter() { BelongsTo = Constants.CollisionLayers.HeatSignature, CollidesWith = Constants.CollisionLayers.HeatSignature, GroupIndex = -targetingId }),
    8.                     CompoundFromChild = new RigidTransform() { pos = float3.zero, rot = quaternion.identity }
    9.                 };
    10.  
    11.                 colliderArray[1] = new CompoundCollider.ColliderBlobInstance()
    12.                 {
    13.                     Collider = Unity.Physics.SphereCollider.Create(
    14.                     new SphereGeometry() { Center = float3.zero, Radius = privateModel.RadarSignatureSize },
    15.                     new CollisionFilter() { BelongsTo = Constants.CollisionLayers.RadarSignature, CollidesWith = Constants.CollisionLayers.RadarSignature, GroupIndex = -targetingId }),
    16.                     CompoundFromChild = new RigidTransform() { pos = float3.zero, rot = quaternion.identity }
    17.                 };
    18.  
    19.                 colliderArray[2] = new CompoundCollider.ColliderBlobInstance()
    20.                 {
    21.                     Collider = Unity.Physics.SphereCollider.Create(
    22.                     new SphereGeometry() { Center = float3.zero, Radius = privateModel.OpticalSignatureSize },
    23.                     new CollisionFilter() { BelongsTo = Constants.CollisionLayers.OpticalSignature, CollidesWith = Constants.CollisionLayers.OpticalSignature, GroupIndex = -targetingId }),
    24.                     CompoundFromChild = new RigidTransform() { pos = float3.zero, rot = quaternion.identity }
    25.                 };
    26.  
    27.                 //colliderArray[3] = new CompoundCollider.ColliderBlobInstance()
    28.                 //{
    29.                 //    Collider = Unity.Physics.SphereCollider.Create(
    30.                 //        new SphereGeometry() { Center = float3.zero, Radius = 5 },
    31.                 //        new CollisionFilter() { BelongsTo = Constants.CollisionLayers.HeatSignature, CollidesWith = Constants.CollisionLayers.HeatSignature }),
    32.                 //    CompoundFromChild = new RigidTransform() { pos = float3.zero, rot = quaternion.identity }
    33.                 //};
    34.  
    35.                 collider = CompoundCollider.Create(colliderArray);
    36.                 colliderArray.Dispose();
    If I create the collider like this I get the error at the bottom of this post (with Burst turned off). If I uncomment the 4th collider to be added to the compound (and change the array dimension to accommodate it) then I don't get the error, everything seems to work as expected. The only difference I can see is that the 4th collider (which I created just to test this out, not really intended to have two with roughly the same filter etc.) doesn't have a GroupIndex being set on it, but I can't think of any reason that should matter.

    Hoping someone has an idea why this is?



    ArgumentException: FixedString32: Truncation while copying "CollisionFilter of a compound collider is not a union of its children. You must call CompoundCollider.RefreshCollisionFilter() to update the root filter after changing child filters."
    Unity.Collections.FixedString128.CheckCopyError (Unity.Collections.CopyError error, System.String source) (at Library/PackageCache/com.unity.collections@0.15.0-preview.21/Unity.Collections/FixedString.gen.cs:2575)
    Unity.Collections.FixedString128..ctor (System.String source) (at Library/PackageCache/com.unity.collections@0.15.0-preview.21/Unity.Collections/FixedString.gen.cs:2102)
    Unity.Collections.FixedString128.op_Implicit (System.String b) (at Library/PackageCache/com.unity.collections@0.15.0-preview.21/Unity.Collections/FixedString.gen.cs:2505)
    Unity.Physics.Systems.ExportPhysicsWorld.CheckColliderFilterIntegrity (Unity.Collections.NativeArray`1[T] colliders) (at Library/PackageCache/com.unity.physics@0.6.0-preview.3/Unity.Physics/ECS/Base/Systems/ExportPhysicsWorld.cs:325)
    Unity.Physics.Systems.ExportPhysicsWorld+CheckColliderIntegrity.Execute (Unity.Entities.ArchetypeChunk batchInChunk, System.Int32 batchIndex) (at Library/PackageCache/com.unity.physics@0.6.0-preview.3/Unity.Physics/ECS/Base/Systems/ExportPhysicsWorld.cs:271)
    Unity.Entities.JobEntityBatchExtensions+JobEntityBatchProducer`1[T].ExecuteInternal (Unity.Entities.JobEntityBatchExtensions+JobEntityBatchWrapper`1[T]& jobWrapper, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) (at Library/PackageCache/com.unity.entities@0.17.0-preview.41/Unity.Entities/IJobEntityBatch.cs:571)
    Unity.Entities.JobEntityBatchExtensions+JobEntityBatchProducer`1[T].Execute (Unity.Entities.JobEntityBatchExtensions+JobEntityBatchWrapper`1[T]& jobWrapper, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) (at Library/PackageCache/com.unity.entities@0.17.0-preview.41/Unity.Entities/IJobEntityBatch.cs:513)
     
  2. petarmHavok

    petarmHavok

    Joined:
    Nov 20, 2018
    Posts:
    461
    There is a bug in the safety system and I think not setting the group index is actually what gets you past this (you get a group index of 0). :)

    The fix is quite easy. Go to ExportPhysicsWorld.cs and locate a function CheckColliderFilterIntegrity(). Then, after the inner for loop, right before the final if statement, add this line:

    combinedFilter.GroupIndex = rootFilter.GroupIndex;

    This effectively invalidates group index comparison since it has no concept of union, so it will help pass the check. Let me know if it fixes it for you.

    I know it's not ideal, since it will require you to edit the package, but I can't give any info on the timeline for this fix at the moment.