Search Unity

How to resize a Job NativeArray result?

Discussion in 'Entity Component System' started by PJRM, Jul 29, 2018.

  1. PJRM

    PJRM

    Joined:
    Mar 4, 2013
    Posts:
    303
    Simply speaking:
    In my AI System, I want the pathfind be calculate by a job. However, i find myself in trouble because the documentation says that i need to allocate the size of the array for the Job, even thought i read that NativeList is resizable, but it doesn't say how.

    So, do i do the result path as NativeList?

    Note: the job inputs receives as input:
    • NativeArray<MyStructCoordinates> as all the available path
    • MyStructCoordinates as start point
    • MyStructCoordinates as end point
     
  2. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    NativeList<T> resize itself automatically as you add more items over the initial limit like C#'s List<T>
     
    PJRM likes this.
  3. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,780
    A 5argon said, simply (example)
    Code (CSharp):
    1. Unity.Collections.NativeList <int> list = new Unity.Collections.NativeList<int> () ;
    2.             list.Add ( 2 ) ;
    3.             list.Add ( 6 ) ;
    4.             list.Add ( 2 ) ;
    5.             list.Add ( 13 ) ;
    Just like normal List
     
    PJRM likes this.
  4. PJRM

    PJRM

    Joined:
    Mar 4, 2013
    Posts:
    303
    Thank you guys. i've been busy and i couldn't test it.
    Thank you so much for the answers. Will look into it and I give a feedback.