NativeArray of generic type?

I have a function that creates a NativeArray but the types vary upon the inputs to the function that creates this array. Is it possible to make a NativeArray without a specifically defined type? I need to define this NativeArray as what is returned by a function.

Thanks. Happy 2020!

Any update on this?

 void MyFunc<T>(T[] argument) where T : struct {
   new NativeArray<T>(argument, Allocator.Temp);
}

MyFunc<float>(...);

you mean like this? dots might not be right for you, its quite complex and hacky, currently at least

1 Like

Oh, I missed the where T : struct.

This is how I used it:

    private void ArrayDispose<T>(NativeArray<T> array) where T : struct
    {
        if(array.IsCreated)
        {
            array.Dispose();
        }
    }

(I needed a way to cut down on boilerplate code for disposal.)