Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[Solved] Correct way for EntityCommandBuffer in IJobChunk : jobIndex / chunkIndex?

Discussion in 'Entity Component System' started by Antypodish, Aug 27, 2019.

  1. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,754
    I got some entity error "The entity does not exist", which I try to pin down.
    It points at system with EntityCommandBuffer in IJobChunk.
    It worked before. But I expanded functionality. And when more entities is involved, error start popping out. For few entities still works.
    It may be (most likely), that I got issue rather somewhere else.

    That actually did rise my question.

    If I use EntityCommandBuffer.ToConcurent in IJobChunk, considering
    Code (CSharp):
    1. public void Execute ( ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex )
    in this job, is it correct, if I do pass chunkIndex into ECB?
    For example
    Code (CSharp):
    1. Entity newChildEntity = ecb.Instantiate ( chunkIndex, sourceEntity ) ;
    Intellisense suggest jobIndex, rather chunkIndex.
    upload_2019-8-27_19-7-33.png

    Hence that makes me concern, if I create potentially some race condition, when using chunkIndex in ECB?
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,754
    I resolved my problem.
    I had mistakanely put
    ecb.SetComponent
    after
    ecb.Destroy

    So my IJobChunk jobs with ecb work well as previously.
    Appears that using chunkIndex in IJobChunk
    Code (CSharp):
    1. ecb.Instantiate ( chunkIndex, sourceEntity ) ;
    is right approach indeed.
     
  3. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,683
    Shouldn’t. Chunk index it’s job index itself, cause IJobChunk is per chunk iteration, which means it runs job for every chunk (speaking in simple words)
     
    Tony_Max and Antypodish like this.
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,754
    Thank you for confirmation.