- Home /
SkinnedMeshRenderer.bones heap churn
So, I'm doing my own skinning on a few vertices from my mesh, to obtain accurate animated centre / bounds information.
I notice that a garbage collection gets triggered every 2-3 seconds, taking 7-8ms, which is a rather large spike; according to the profiler, the only source of memory allocations is SkinnedMeshRenderer.get_bones(), called from the SkinnedMeshRenderer's bones property from my skinning code. Presumably the property's accessor is taking a copy of the bones array and returning that to me (why?)
Is there a way of transforming a point by a bone that does not cause the bone to get copied under the hood?
My skinning code is trivial, but here's the relevant bit (appears in the profiler callstack as the immediate caller of SkinnedMeshRenderer.get_bones()), just in case someone spots I'm accessing things in some particularly bad way:
Vector3 pos = m_renderer.bones[m_verts[i].m_weights.boneIndex0].TransformPoint(m_verts[i].m_pos0) * m_verts[i].m_weights.weight0
+ m_renderer.bones[m_verts[i].m_weights.boneIndex1].TransformPoint(m_verts[i].m_pos1) * m_verts[i].m_weights.weight1
+ m_renderer.bones[m_verts[i].m_weights.boneIndex2].TransformPoint(m_verts[i].m_pos2) * m_verts[i].m_weights.weight2
+ m_renderer.bones[m_verts[i].m_weights.boneIndex3].TransformPoint(m_verts[i].m_pos3) * m_verts[i].m_weights.weight3;
EDIT: factoring out the access to the bones property does indeed massively reduce heap churn; yet doing that is rather counterintuitive, and the transform array still gets copied once a frame without any obvious need, so the question of how to skin a set of verts without hitting the heap at all still stands.
Your answer