DOTS Physics stops processing trigger events after reaching high entity count

com.unity.physics: 0.51.0-preview.32

I’m having an issue that I can’t seem to pin down.

I have lots of bullets and enemies, very simple, all sphere colliders locked to the z-plane. Everything works fine until I hit around 10k+ entities and all trigger collisions begin to just not occur. This is very consistent. i have disabled almost every other system in the game and it still occurs.

Here is my collision job:

[UpdateInGroup(typeof(FixedStepSimulationSystemGroup))]
    [UpdateAfter(typeof(ExportPhysicsWorld))]
    [UpdateBefore(typeof(EndFramePhysicsSystem))]
    public abstract partial class TriggerPhysicsSystemBase<T> : SystemBase where T : struct, ITriggerEventsJob
    {
        protected StepPhysicsWorld m_StepPhysicsWorld = default;

        protected override void OnCreate()
        {
            m_StepPhysicsWorld = World.GetOrCreateSystem<StepPhysicsWorld>();
        }

        protected override void OnUpdate()
        {
            var collectTriggerEventsJob = CreateJob();

            collectTriggerEventsJob.Schedule(m_StepPhysicsWorld.Simulation, Dependency).Complete();
        }

        protected abstract T CreateJob();
    }

Then the actual job system looks like:

[BurstCompile]
public struct KillDoodTriggerJob : ITriggerEventsJob 
{
    public EntityCommandBuffer commandBuffer;

    public ComponentDataFromEntity<BulletTag> bulletGroup;
    [ReadOnly]
    public ComponentDataFromEntity<DoodTag> doodGroup;
    [ReadOnly]
    public ComponentDataFromEntity<DestroyTag> destroyGroup;

    public EntityQueryMask IsBullet;
    public EntityQueryMask IsDood;

    public void Execute(TriggerEvent triggerEvent)
    {
        Entity bullet;
        Entity dood;

        if (PhysicsHelpers<BulletTag, DoodTag>.EventContains(triggerEvent, ref IsBullet, ref IsDood, out bullet, out dood))
        {
            if (!destroyGroup.HasComponent(dood)) // don't hit doods already marked for death
            {
                commandBuffer.AddComponent(dood, new DestroyTag { });

                var bulletData = bulletGroup[bullet];
                bulletData.Penetrations++;
                if (bulletData.Penetrations >= bulletData.BasePenetrations)
                    commandBuffer.AddComponent(bullet, new DestroyTag { });
                commandBuffer.SetComponent(bullet, bulletData);
            }
        }
    }
}

public class KillDoodOnTriggerSystem : TriggerPhysicsSystemBase<KillDoodTriggerJob>
{
    private EndFixedStepSimulationEntityCommandBufferSystem m_CommandBufferSystem;

    private EntityQuery isBulletQuery;
    private EntityQuery isDoodQuery;

    protected override void OnCreate()
    {
        m_CommandBufferSystem = World.GetOrCreateSystem<EndFixedStepSimulationEntityCommandBufferSystem>();

        isBulletQuery = EntityManager.CreateEntityQuery(typeof(BulletTag));
        isDoodQuery = EntityManager.CreateEntityQuery(typeof(DoodTag));
        base.OnCreate();
    }

    protected override KillDoodTriggerJob CreateJob()
    {
        return new KillDoodTriggerJob()
        {
            commandBuffer = m_CommandBufferSystem.CreateCommandBuffer(),
            bulletGroup = GetComponentDataFromEntity<BulletTag>(),
            doodGroup = GetComponentDataFromEntity<DoodTag>(true),
            destroyGroup = GetComponentDataFromEntity<DestroyTag>(true),
            IsBullet = EntityManager.GetEntityQueryMask(isBulletQuery),
            IsDood = EntityManager.GetEntityQueryMask(isDoodQuery)
        };
    }
}

It’s not particularly laggy. I get 20-30fps in the editor during this case. I upped the solver iteration count but that doesn’t appear to affect it. It’s not like “some” enemies get hit but not other- zero triggers are fired.
Profiler doesn’t really show anything outstanding.

No errors or warnings. Safety checks are on.

The enemy:


The Bullet:

The job itself is running but taking very minimal amount of time, as if no events found in the physics system:

Interestingly, if I make a build the game instantly crashes when I touch an enemy.

========== OUTPUTTING STACK TRACE ==================

0x00007FF8EA775A94 (lib_burst_generated) [F:\Projects\KillDoods\Library\PackageCache\com.unity.entities@0.51.0-preview.32\Unity.Entities\EntityCommandBuffer.cs:2507] Unity.Entities.EntityCommandBuffer/EcbWalker`1<Unity.Entities.EntityCommandBuffer/PlaybackProcessor>.1409::Unity.Entities.EntityCommandBuffer.EcbWalker`1<Unity.Entities.EntityCommandBuffer.PlaybackProcessor>.ProcessChain
0x00007FF8EA771471 (lib_burst_generated) 6cbe9b44f55dff161edecf05c9660a36_avx2
0x0000026DE2404083 (Mono JIT Code) (wrapper managed-to-native) object:wrapper_native_00007FF8EA88FAA0 (intptr,int,intptr,int,int)
0x0000026DFB94D40A (Mono JIT Code) (wrapper delegate-invoke) <Module>:invoke_void_intptr_int_intptr_int_int (intptr,int,intptr,int,int)
0x0000026DFB94D32D (Mono JIT Code) [F:\Projects\KillDoods\Library\PackageCache\com.unity.entities@0.51.0-preview.32\Unity.Entities\ECBInterop.interop.gen.cs:98] Unity.Entities.ECBInterop:_forward_mono_ProcessChainChunk (void*,int,Unity.Entities.ECBChainPlaybackState*,int,int)
0x0000026DFB94D25B (Mono JIT Code) [F:\Projects\KillDoods\Library\PackageCache\com.unity.entities@0.51.0-preview.32\Unity.Entities\ECBInterop.interop.gen.cs:80] Unity.Entities.ECBInterop:ProcessChainChunk (void*,int,Unity.Entities.ECBChainPlaybackState*,int,int)
0x0000026DE549FD3B (Mono JIT Code) [F:\Projects\KillDoods\Library\PackageCache\com.unity.entities@0.51.0-preview.32\Unity.Entities\EntityCommandBuffer.cs:2459] Unity.Entities.EntityCommandBuffer/EcbWalker`1<Unity.Entities.EntityCommandBuffer/PlaybackProcessor>:WalkChains (Unity.Entities.EntityCommandBuffer)
0x0000026DE549F3CB (Mono JIT Code) [F:\Projects\KillDoods\Library\PackageCache\com.unity.entities@0.51.0-preview.32\Unity.Entities\EntityCommandBuffer.cs:2321] Unity.Entities.EntityCommandBuffer:PlaybackInternal (Unity.Entities.EntityDataAccess*)
0x0000026DE549F0D3 (Mono JIT Code) [F:\Projects\KillDoods\Library\PackageCache\com.unity.entities@0.51.0-preview.32\Unity.Entities\EntityCommandBuffer.cs:2283] Unity.Entities.EntityCommandBuffer:Playback (Unity.Entities.EntityManager)
0x0000026DE549EBFB (Mono JIT Code) [F:\Projects\KillDoods\Library\PackageCache\com.unity.entities@0.51.0-preview.32\Unity.Entities\EntityCommandBufferSystem.cs:271] Unity.Entities.EntityCommandBufferSystem:FlushPendingBuffers (bool)
0x0000026DE549EA33 (Mono JIT Code) [F:\Projects\KillDoods\Library\PackageCache\com.unity.entities@0.51.0-preview.32\Unity.Entities\EntityCommandBufferSystem.cs:193] Unity.Entities.EntityCommandBufferSystem:OnUpdate ()
0x0000026DE549D361 (Mono JIT Code) [F:\Projects\KillDoods\Library\PackageCache\com.unity.entities@0.51.0-preview.32\Unity.Entities\ComponentSystem.cs:115] Unity.Entities.ComponentSystem:Update ()
0x0000026DE549E66F (Mono JIT Code) [F:\Projects\KillDoods\Library\PackageCache\com.unity.entities@0.51.0-preview.32\Unity.Entities\ComponentSystemGroup.cs:585] Unity.Entities.ComponentSystemGroup:UpdateAllSystems ()
0x0000026DE549E1C3 (Mono JIT Code) [F:\Projects\KillDoods\Library\PackageCache\com.unity.entities@0.51.0-preview.32\Unity.Entities\ComponentSystemGroup.cs:524] Unity.Entities.ComponentSystemGroup:OnUpdate ()
0x0000026DE549D361 (Mono JIT Code) [F:\Projects\KillDoods\Library\PackageCache\com.unity.entities@0.51.0-preview.32\Unity.Entities\ComponentSystem.cs:115] Unity.Entities.ComponentSystem:Update ()
0x0000026DE549D109 (Mono JIT Code) [F:\Projects\KillDoods\Library\PackageCache\com.unity.entities@0.51.0-preview.32\Unity.Entities\ScriptBehaviourUpdateOrder.cs:428] Unity.Entities.ScriptBehaviourUpdateOrder/DummyDelegateWrapper:TriggerUpdate ()
0x0000026DBEEC6CF0 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)
0x00007FF8D0DFF1E0 (mono-2.0-bdwgc) mono_get_runtime_build_info
0x00007FF8D0D82AC2 (mono-2.0-bdwgc) mono_perfcounters_init
0x00007FF8D0D8BB1F (mono-2.0-bdwgc) mono_runtime_invoke
0x00007FF8BF57031D (UnityPlayer) UnityMain
0x00007FF8BF56CA9C (UnityPlayer) UnityMain
0x00007FF8BF12C3FD (UnityPlayer) UnityMain
0x00007FF8BF12C41F (UnityPlayer) UnityMain
0x00007FF8BF132542 (UnityPlayer) UnityMain
  ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FF8BEB43FBF)
0x00007FF8BEB43FBF (UnityPlayer) (function-name not available)
  ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FF8BEB41C3B)
0x00007FF8BEB41C3B (UnityPlayer) (function-name not available)
  ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FF8BEB47976)
0x00007FF8BEB47976 (UnityPlayer) (function-name not available)
0x00007FF8BEB4893B (UnityPlayer) UnityMain
  ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FF72AB411F2)
0x00007FF72AB411F2 (Kill1Billion) (function-name not available)
0x00007FF9D1727034 (KERNEL32) BaseThreadInitThunk
0x00007FF9D24E2651 (ntdll) RtlUserThreadStart

I have resolved this issue. I’m not sure what the actual problem was but I copied the StatefulTriggerEvent code from the PhysicsSamples and it seems to have fixed this.