Search Unity

Question Defer creation of NativeArray until previous job is complete

Discussion in 'Entity Component System' started by TJHeuvel-net, Nov 8, 2022.

  1. TJHeuvel-net

    TJHeuvel-net

    Joined:
    Jul 31, 2012
    Posts:
    838
    I'm relatively new to the Job System, and i'm trying to figure out how to best schedule multiple jobs, that do have dependencies.

    In my example i have a bunch of points, i first filter out a bunch i am not interested in, and then i want to associate a score value with the ones that remain.

    I understand that with IJobParallelForDefer i can schedule my second job, and it takes the length based on the indices from the first. However this job should output a NativeArray<float> of scores, and i dont know how i can make that of an appropriate length.

    Is there any way to make a NativeArray's length based on the output of the previous NativeList? At the moment i simply make the array very large, or i could use NativeList as well. But i feel like it would be better if there was something like `AsDeferredJobArray`, where i could make an entirely new array of a different type, but its length tied to another NativeList.
     
  2. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,267
    Most people just use a NativeList and resize it in the job.
     
    TJHeuvel-net likes this.
  3. TJHeuvel-net

    TJHeuvel-net

    Joined:
    Jul 31, 2012
    Posts:
    838
    Thanks, makes some sense!