Search Unity

Any way to do NativeArray of NativeArrays / NativeList / NativeQueue?

Discussion in 'Entity Component System' started by SirMazius, Apr 23, 2018.

  1. SirMazius

    SirMazius

    Joined:
    Oct 26, 2016
    Posts:
    11
    So i was trying to made something like :

           
    NativeArray<NativeArray<int>> a = new NativeArray<NativeArray<int>>(10, Allocator.Temp);

    or
     
    NativeArray<NativeList<int>> a = new NativeArray<NativeList<int>>(10, Allocator.Temp);


    And then initialize each list but i get an error about blittable data, anyone knows how to do something similar?

    Thanks!
     
  2. slim_trunks

    slim_trunks

    Joined:
    Dec 31, 2017
    Posts:
    41
    If you want a two-dimensional array (array of arrays), you can always represent that as a one-dimensional/flattened array.
    You'll just have to do a little math for finding the correct index.

    For high performance scenarios, I've always found this method to be more efficient when iterating sequentially over all elements.
     
  3. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    Nested native containers not allowed at the moment.
     
  4. SirMazius

    SirMazius

    Joined:
    Oct 26, 2016
    Posts:
    11
    thats a pitty, thank you a lot anyway!
     
  5. SirMazius

    SirMazius

    Joined:
    Oct 26, 2016
    Posts:
    11
    I know, but is necesary if you want to build a custom hash table like im trying to do and things like that
     
  6. recursive

    recursive

    Joined:
    Jul 12, 2012
    Posts:
    669
    You could potentially write an adapter struct, similar to NativeSlice<>