Skinning a mesh by Code...

Hello everyone!

Ok, I’ve search on the web and can’t find anything about this. I would like to re-use several animations on a custom mesh that will share the same bone structure.

If you import an animated mesh in Unity, it has:

-The bones structure has child object

-A SkinnedMeshRanderer component

-An Animation component.

In my case, the mesh will be created by the player, and therefore, can’t be animated beforehand.

I know that my bones structure will always be the same, because it’s a gameplay restriction. The problem is that if I apply a SkinnedMeshRenderer component by code and fill it properly, Unity throw me: “SkinnedMeshRenderer requires a mesh with skinning information.”

Any idea how I can provide those skinning information?

(for reference: Unity - Scripting API: Mesh)

You’ll need to fill in the bindPoses and boneWeights arrays yourself. BoneWeights is pretty simple, but bindPoses involves matrices. I believe they’re the rest positions of the bones? If your two renderers are similar enough it should be okay to copy the bindPoses and boneWeights from the working mesh to the one that isn’t bound.

You may also need to arrange the bones in the SkinnedMeshRenderer.bones array yourself in the new mesh.