Search Unity

How to write components back after been proccesed by a Job?

Discussion in 'Entity Component System' started by Fallc, Mar 24, 2019.

  1. Fallc

    Fallc

    Joined:
    Mar 13, 2015
    Posts:
    48
    I'm fetching components with a ComponentGroup inside of a ComponentSystem. The fetched components are passed to a IJobParallelFor. One of those components then needs to be wrote back to the system. But how?

    Just writing to the NativeArray by ToComponentDataArray<>() doesn't work. Using Entitie.ForEach with the same set of components sounds counter intuitive and also doesn't gurantee I'm writing back to the same entity (doesn't it?).

    I guess I should be using the JobComponentSystem but I need to cross access all entities inside the job, so that won't work.

    Any Ideas?
     
    Last edited: Mar 24, 2019
  2. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    1,011
    ToComponentDataArray() make copy of original components so wirting to it is not persistent. If you want to write back, use ToEntityArray() with ComponentDataFromEntitiy() or just IJobProcessComponentData struct.
     
  3. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,683
    For writing back if you using ToComponentDataArray() you should use CopyFromComponentDataArray, it's API added in 0.0.24 for this purposes.
     
    Derebeyi likes this.
  4. Fallc

    Fallc

    Joined:
    Mar 13, 2015
    Posts:
    48
    That's what i'm was looking for, thank you!