Search Unity

Pointer problems... Marshal.Copy Vector3[,,] Array to Byte[] Array

Discussion in 'Scripting' started by Quatum1000, Apr 11, 2020.

  1. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    889
    Hi everyone,

    I'm trying to Marshal.Copy a Vector3[,,] array to a Byte[] array. But that seem lite ugly.
    Code (CSharp):
    1.  // Create a managed array.
    2. Vector3[,,] managedArray = new Vector3[10,10,10];
    3.  
    4. // Get the sise and and create a byte array
    5. int size = Marshal.SizeOf(managedArray[0,0,0]) * managedArray.Length;
    6.  
    7. // Allocate memory
    8. IntPtr pnt = Marshal.AllocHGlobal(size);
    9.  
    10. //// But an error occur : Can not convert Unity.Engine Vector3[,,] to byte[]
    11. Marshal.Copy(managedArray, 0, pnt, managedArray.Length);
    Does Marshal.Copy works with one dimensional arrays only?
    Is there any other solution to achieve this?

    Thank you..
     
  2. Kolja_Lubitz

    Kolja_Lubitz

    Joined:
    Aug 2, 2021
    Posts:
    4