How can I set a stackalloc’d array of float3’s that are representative of the desired Vector3 positions into a LineRenderer’s positions array?
I can’t seem to find a way to get at the LineRenderer’s array to do a memcpy into it, nor a way to let the LineRenderer’s SetPostions(Vector3[ ] arrayOfPositions) function know that the pointer to the float3 is an array for it to work with.
Even if you could, it seems like you’d be better off producing a “NativeArray” instead which is not only fast but also is compatible with LineRenderer.SetPositions.
In my testing, NativeArray’s have been slower than C#/Managed arrays. Not by a lot, but it’s a slight difference that’s consistent. Building the arrays into Stackalloc is a couple of orders of magnitude faster than both of them.
Presume from your “even if you could” opener that this isn’t possible, so will just stick with what I’m doing, which is exploiting another aspect of unsafe code, memcpy the stack’s array into a Native/Managed array, which is very fast. Then the SetPositions is probably doing the same (or similar) in the C++ engine code side that I can’t see.
Bit of a pity I can’t get at a pointer for the LineRenderer’s array, so as to skip the intermediate step.