Search Unity

  1. The 2022.1 beta is now available for testing. To find out what's new, have a look at our 2022.1 beta blog post.
    Dismiss Notice

What is the best way to add or remove components using a IJobChunk

Discussion in 'Data Oriented Technology Stack' started by StaffanEk, Aug 10, 2019.

  1. StaffanEk

    StaffanEk

    Joined:
    Jul 13, 2012
    Posts:
    380
    I'm fairly new to DOTS, and was just trying to learn about utilizing the job system.

    Specifically I wanted to benefit from the job system while while filtering both all, any and none of component types. The IJobChunk struct works beautifully for this since It is guaranteed to return entities with the same archetype. I was just wondering what is the best way to add and remove components using it in a job. Is it possible (or advisable) to pass Entities to an entityCommandBuffer with it?

    IJobForEach has access to entities implicitly, but how would one go about accessing Entities using an IJobChunk?

    The manual doesn't mention much. And my searches have come up short.

    https://docs.unity3d.com/Packages/com.unity.entities@0.1/manual/chunk_iteration_job.html

    This paragraph in the manual alludes to what I want, but I would love for it to be elaborated upon.
     
  2. recursive

    recursive

    Joined:
    Jul 12, 2012
    Posts:
    667
    Look into
    GetArchetypeChunkEntityType()
    and
    ArchetypeChunk.GetNativeArray()
    . That should get you what you want.
     
  3. StaffanEk

    StaffanEk

    Joined:
    Jul 13, 2012
    Posts:
    380
    Brilliant, thank you very much.
     
    recursive likes this.
unityunity