You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Which wraps the array in a Span<byte> and calls SetSizedArrayForChannel
SetArrayForChannelImpl then pins the span with fixed and passes the pointer to native code, which copies it into the mesh. No managed array is created anywhere along the way
By measuring the allocation count:
It ran 100 iterations on a 1000-vertex mesh and read Mono heap usage before and after:
Calls
Bytes allocated
mesh.vertices = v; mesh.colors32 = c;
0
mesh.SetVertices(v); mesh.SetColors(c);
0
var x = mesh.vertices; var y = mesh.colors32;
1,638,400 (≈ 100 × (12 KB + 4 KB))
It used Profiler.GetMonoUsedSizeLong() to count the allocations.
To work around that: use the Set methods (e.g. SetVertices(), SetColors(), etc)
We double-checked it against Unity's reference source: the getters go through GetAllocArrayFromChannel (the native AllocExtractMeshComponentFromScript returns a new managed array), while the setters only wrap the array in a Span<byte> and pass it to SetMeshComponentFromSpanFromScript, so there is no managed allocation.
assignments like mesh.vertices = ... are no longer reported (and the code fix no longer rewrites them),
accesses on a mesh that changes with each iteration (like meshInfo.mesh in your loop, or a foreach variable) are no longer reported either, as they cannot be cached before the loop.
Activity
[-]UNT0042 wrongly flag the setters too[/-][+]UNT0042 wrongly flags the setters too[/+]sailro commentedon Nov 30, 2026
Thanks for the detailed report Creak (@MightyCreak), you're right.
We double-checked it against Unity's reference source: the getters go through
GetAllocArrayFromChannel(the nativeAllocExtractMeshComponentFromScriptreturns a new managed array), while the setters only wrap the array in aSpan<byte>and pass it toSetMeshComponentFromSpanFromScript, so there is no managed allocation.This is fixed in #521:
mesh.vertices = ...are no longer reported (and the code fix no longer rewrites them),meshInfo.meshin your loop, or aforeachvariable) are no longer reported either, as they cannot be cached before the loop.