How to pass NativeArray<byte> to native plugin

Hi !

I’m trying to do a native plugin in C++ for the first time… I need to send a NativeArray to my dll but it just doesn’t work like a normal byte array…

Since i can’t find any documentation on that maybe you guys know more about how i can do this ?
I don’t want to pass myNativeArray.toArray(), since myNativeArray is huge it’s very slow.

Use the Unity.Collections.LowLevel.Unsafe namespace. There’s some extension methods in there which let you do things like obtain a raw pointer to the data in a NativeArray.

But will it point to the C++ array or to a class/struct ?

It points to the raw byte data.

Could you give me an exemple with both side C++ and C#? i’m not able to pull it out…
I make unity crash or i just get random values.

— Update

Nvm ! i found my error, was using UnsafeUtility.AddressOf but it’s myarray.GetUnsafePtr or
GetUnsafeReadOnlyPtr

Thanks :slight_smile:

1 Like