Support converting byte arrays to Unity struct arrays in Udon
ureishi
I would like to request support for efficiently converting byte[] data into Unity struct arrays in Udon, such as:
Color[]
, Color32[]
, Vector2[]
, Vector3[]
, Vector4[]
Ideally, this would be similar in spirit to
System.Buffer
, but extended to support Unity struct arrays.## Background
Currently, converting raw byte[] data into Unity struct arrays in Udon is not straightforward.
While it is technically possible through indirect approaches, these require many Udon steps and become inefficient when handling large datasets.
In an actual 3D model loader currently in use, this process may need to handle hundreds of thousands of elements, such as around 300,000 entries.
## Proposal
Please add a way for Udon to convert byte[] data into Unity struct arrays, similar in spirit to
System.Buffer
.For example:
Vector3[] vertices = new Vector3[size];
UdonBuffer.TryBlockCopy(byteData, byteIndex, vertices);
This would make it possible to directly convert binary data obtained from external sources (such as data fetched from the web) into Unity struct arrays in Udon, without workarounds.
Log In
suzuki_i
Wouldn't
Buffer.BlockCopy
work?nuruwo
suzuki_i
Buffer.BlockCopy can only convert a byte array to a float array;
therefore, converting from a float array to a Vector3 array requires processing within an Udon loop.
Vector3 vec3 = new Vector3(floatArray[0], floatArray[1], floatArray[2]);
Of course, if Buffer.BlockCopy supported Vector3[] and similar formats, this request would be fulfilled.
suzuki_i
nuruwo
I understand. Thank you!