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