Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Get Entity in IJobJobParallelFor or IJobChunk

Discussion in 'Entity Component System' started by pakfront, Jun 11, 2019.

  1. pakfront

    pakfront

    Joined:
    Oct 6, 2010
    Posts:
    551
    I feel like I knew this, but much searching has not produced an example to refresh my memory.

    In an IJobChunk or IJobParallelFor, given the chunk index and the chunk.Count, how do I get a collection of the entities in a chunk?
    Something like:
    Code (CSharp):
    1.             public void Execute(int chunkIndex)
    2.             {
    3.                 var chunk = Chunks[chunkIndex];
    4.                 var chunkTranslation = chunk.GetNativeArray(TranslationType);
    5.                 var chunkEntities = chunk.???;
    6.  

    Thanks.
     
    Last edited: Jun 11, 2019
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,635
    Same way you get your translations.

    Code (CSharp):
    1.             public void Execute(int chunkIndex)
    2.             {
    3.                 var chunk = Chunks[chunkIndex];
    4.                 var chunkTranslation = chunk.GetNativeArray(TranslationType);
    5.                 var chunkEntities = chunk.GetNativeArray(EntityType);
    Where EntityType is ArchetypeChunkEntityType (obtained from this.GetArchetypeChunkEntityType())
     
    Meowitzer_kun likes this.
  3. pakfront

    pakfront

    Joined:
    Oct 6, 2010
    Posts:
    551
    Thanks! I knew it was straightforward, I just lost my notes for it.