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. The 2022.2 beta is now available for testing. To find out what's new, have a look at our 2022.2 feature highlights.
    Dismiss Notice
  3. We are updating our Terms of Service for all Unity subscription plans, effective October 13, 2022, to create a more streamlined, user-friendly set of terms. Please review them here: unity.com/legal/terms-of-service.
    Dismiss Notice
  4. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice
  5. Join us on Thursday, September 29, for a day with Unity's SRP teams here on the forum or on Reddit, and discuss topics around URP, HDRP, and the Scriptable Render Pipeline in general.
    Dismiss Notice
Dismiss Notice
Submit bug reports tagged with #Beta2022Win_Unity when you encounter unknown issues while testing the 2022.2 betas for a chance to win a year of Unity Pro. For more information, have a look at our Beta Sweepstakes Announcement.

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