Search Unity

IJobParallelForTransform madness

Discussion in 'Entity Component System' started by snacktime, Apr 5, 2019.

  1. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    I just converted the last job we had that was an IJobParallelForTransform using the old component data arrays. Which would allow you to update the components inside the IJobParallelForTransform. So you could sync both ways in a single job.

    Now there doesn't seem to be any way to do this, and we are stuck using Unity's approach which has a rather high constant overhead (multiple jobs and having to use ToComponentDataArray).

    Anyone found a more performant method for syncing transforms with the post injection api?
     
  2. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    IJobParallelForTransform is still being used in CopyTransformToGameObjectSystem right? Isn't that means it is still valid to use? (Or just use CopyTransformToGameObject)

    Also did you use ToComponentDataArray that gives out JobHandle? If you chain the handle to the job, To__ method's overhead became just like CDA.
     
  3. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    CDA was writable inside IJobParallelForTransform. Changes you made persisted to the chunk data. That's not the case with passing the NativeArray that ToComponentDataArray gives you to IJobParallelForTransform. Also the out jobhandle will not work for arrays you are writing to, it will complain about the job not being completed.

    Unity's own code creates a temp native array of proxy transform data that they write to in IJobParallelForTransform and then pass that to an IJobForEachWithEntity to copy the transform values to component data. It's not terribly inefficient but before you could sync both ways in a single IJobParallelForTransform without having to allocate anything extra.
     
    futurlab_peterh likes this.