Search Unity

Resolved IJobEntity EntityCommandBuffer.AsParallel writer, entityInQueryIndex ?

Discussion in 'Entity Component System' started by toomasio, Nov 18, 2022.

  1. toomasio

    toomasio

    Joined:
    Nov 19, 2013
    Posts:
    199
    Hello,

    With the ForEach approach, you could get the entityInQueryIndex. Is there an equivalent in IJobEntity for using an EntityCommandBuffer.ParallelWriter? Do you just use Entity.Index?

    Thanks,
     
  2. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,271
    Use [ChunkIndexInQuery] for ECBs.
     
    toomasio likes this.
  3. toomasio

    toomasio

    Joined:
    Nov 19, 2013
    Posts:
    199
    Perfect thanks!

    This is how it's done as an example:
    Code (CSharp):
    1. [BurstCompile]
    2.     public partial struct ExampleJob : IJobEntity
    3.     {
    4.         public EntityCommandBuffer.ParallelWriter ecb;
    5.  
    6.         public void Execute([ChunkIndexInQuery] int chunkIndex)
    7.         {
    8.                 var spawn = ecb.Instantiate(chunkIndex, ...);
    9.         }
    10.     }