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: