Getting Entity from a NativeList<ArchetypeChunk>?

You can do that using EntityCommandBuffer

public class CommandBufferInIJobProcessComponent : JobComponentSystem{ 
  [Inject] EndFrameBarrier _barrier;  // inject barrier 
  protected override JobHandle OnUpdate(JobHandle deps) => new Job(){
      CommandBuffer = _barrier.CreateCommandBuffer().ToConcurrent() // create new command buffer
  }.Schedule( this, deps );
 
  [RequireSubtractiveComponent(typeof(B))]
  private struct Job : IJobProcessComponentDataWithEntity<A>{
    public EntityCommandBuffer.Concurrent CommandBuffer;
    public void Execute( Entity entity, int index, [ReadOnly] ref A a ){
      //schedule changes
      CommandBuffer.AddComponent( index, entity, new B() ); //index must a unique ID per job
    }
  } 
}

**NOTE: Burst does not work with EntityCommandBuffer at this stage. see Anyone got Burst working with EntityCommandBuffer ? *

1 Like