Martin Cerruti
1 min readMar 29, 2020

Assuming your Vector3 type is a struct, and all of its members are blittable (which singles/floats are), you should be able to run them through the Marshal.

I’ve not tested it, but something along the lines of this should work:

private unsafe void Writes(){byte[] buffer = new byte[sizeof(Vector3)];fixed (byte* b = buffer)Marshal.StructureToPtr(new Vector3{X = 1, Y = 1, Z = 1}, new IntPtr((int)b), false);byte[] buff = new byte[sizeof(Vector3)];fixed(byte* b = buff)Unsafe.Write(b, new Vector3{X = 1, Y = 1, Z = 1});}struct Vector3{public float X;public float Y;public float Z;}

Where the Unsafe variant is much, much faster.

Martin Cerruti

Software Architect, Technology Writer, but most of all a programmer.