Search Unity

Native Collection Initializers

Discussion in 'Entity Component System' started by PublicEnumE, Aug 18, 2019.

  1. PublicEnumE

    PublicEnumE

    Joined:
    Feb 3, 2019
    Posts:
    729
    It would be a nice convenience feature is some native collections could be defined with collection initializers:

    Code (CSharp):
    1. NativeArray<int> intArray = new NativeArray<int>(3, Allocator.TempJob)
    2. {
    3.     5,
    4.     10,
    5.     1
    6. };
    7.  
    8. NativeList<int> intList = new NativeList<int>(3, Allocator.TempJob)
    9. {
    10.     5,
    11.     10,
    12.     1
    13. };
    ^ That code will fail. But it would be nice if it didn't. :p

    I assume there's a good reason unity hasn't supported collection initializers for their native collections. Does anyone know why it might be?

    Thanks for any input. :)