Hi all,
I have a skinned character and some skinned clothing I’d like to ‘move together’ from the same bone tree once imported. (For logistic reasons, the clothing files are kept separate from the character files but share the same bone rig)
I have tried to set the clothing’s root bone (under its Skinned Mesh Renderer component) to the same root bone of my character, but to my surprise the child bones from the clothing’s bone tree still control the skinned cloth, and only the root bone of my character moves the cloth vertices skinned to it.
How can one ‘merge’ skinned meshes coming from different files to move as one?
Any clue? 
Hi all, researching this further I coded a solution that appears to work well. If this helps someone here it is… 
public static Transform TransferBone(Transform oBoneOld, Transform oBoneNewRoot) { // Returns a transform at the same relative path of a bone (provided by SkinnedMeshRenderer.bones[i]) but rooted at 'oBoneNewRoot'. Assumes an identically-structured bone tree between the objects (Running this function over all bones of an object will make it move along the object at 'oBoneNewRoot')
string sBonePath = oBoneOld.name;
Transform oNodeIterator = oBoneOld.parent;
while (oNodeIterator.parent != null) { // Iterate up the parent chain to construct the relative path all the way to just before the top-level object
sBonePath = oNodeIterator.name + "/" + sBonePath;
oNodeIterator = oNodeIterator.parent;
}
Transform oBoneNew = oBoneNewRoot.FindChild(sBonePath);
if (oBoneNew == null)
Debug.LogError("*Err: TransferBone could not transfer bone '" + sBonePath + "' to new root '" + oBoneNewRoot + "'");
return oBoneNew;
}
public static void TransferBones(ref SkinnedMeshRenderer oSkinMeshRend, Transform oBoneNewRoot) {
Transform[] aBones = oSkinMeshRend.bones;
for (int nBone = 0; nBone < oSkinMeshRend.bones.Length; nBone++) // Iterate through all bones of this skinned mesh to remap them to our body's bones. (This will make clothing skinned mesh 'move along' with body)
aBones[nBone] = TransferBone(aBones[nBone], oBoneNewRoot);
oSkinMeshRend.bones = aBones;
oSkinMeshRend.rootBone = TransferBone(oSkinMeshRend.rootBone, oBoneNewRoot); // Also remap the root bone similarly
}
You would use it with a call like: TransferBones(mySkinnedMeshRenderer, myTransformToNewBoneRoot); The code of course assumes the two skinned mesh are based on the same identical bone tree… (Neither has to use all the bones though…)
Enjoy! 