Review generated death system

from Unity DOTS
Unity 6.6 / Entities 1.4.8 / Burst 1.8.30 advanced 6 min 4 issues to find

Review this generated death-marking system.

Mark entities with non-positive health as dead, preserve existing job dependencies, and leave the main thread free until a result is needed.

csharp
using Unity.Burst;
using Unity.Entities;

[BurstCompile]
public partial struct DeathSystem : ISystem
{
    [BurstCompile]
    public void OnUpdate(ref SystemState state)
    {
        var x = 0f;

        foreach (var (health, entity) in
                 SystemAPI.Query<RefRO<Health>>().WithEntityAccess())
        {
            if (health.ValueRO.Value <= x)
                state.EntityManager.AddComponent<Dead>(entity);
        }

        new CountLivingJob().ScheduleParallel();
        state.Dependency.Complete();
    }
}

generated code is illustrative, not from any one model

Open in playground
Report an error