- Home /
Fixing a byte array in Unity
I have the following simple C# code
var someBytes = new byte[64];
fixed (byte* pBytes = someBytes)
{
System.Diagnostics.Debug.WriteLine(new IntPtr(pBytes).ToString("X"));
}
When I run this in a Win32 .Net 2.0 console app the address of pBytes is 0x2EBFC10, i.e. an address into memory as expected. When I run the same code in Unity the address of pBytes is 0x00.
What is going wrong? How do I fix a byte array in Unity?
(N.B. I have it set-up to 'allow unsafe code' in both cases.)
Comment
Totally guessing here: When you say you ran the code in Unity, I'm guessing you mean in the Editor?
Have you tried building your project then running it? This might have your wanted results as the Unity editor might be doing something weird
I'll try, but I need it to work in the editor as we're building a package other Unity developers will code against to write games using our new HID device.