Is it possible to update a skinned mesh renderer's bones?

I have a model with nested game objects that have skinned mesh renderers that are linked to that model’s bone hierarchy. This nested objects are its clothing, so when the model moves, its clothes deforms with it accordingly. I’m trying to add new clothes to it, but they don’t deform at all.

I’m thinking that maybe I shouldn’t link a picture of the entire model, as it is kind of NSFW, so here are some pictures of the clothing item in question.

alt text

To the left is the default boot which I imported together with the complete model. To the right is the new boot that I imported with the very same complete model, but at a later time.

alt text

Here is how this new boot deforms when its entire model is added to the scene.

alt text

This is what happens when I try to attach this game object to another model.

alt text

Even though I changed this new item’s Root Bone property’s, it’s still not linking itself with the other model’s bones.

The model which I’m trying to nest this new boot is my main prefab that has much work done to it (ragdoll, hitboxes, tags, custom scripts that use specific bones, etc). The only thing that seems I can do is to recreate this prefab again, with the new model this time. That is very inefficient for me, as I have a lot of prefabs that would need to be created all over again. Looking through the documentation is not yielding answers to this, neither googling for this. How do you nest new skinned mesh renderers to game object and link its bones to it?

Edit: Issue solved. As I’m not skilled enough as a programmer to make a script of my own without scratching my head for hours, I grabbed the one linked by Cherno. The formatting was a little messed in the post, so I took the liberty to fix it and put it on a pastebin: https://pastebin.com/RVY8ygur.

The rootbone has nothing to do with the actual skinning of the SkinnedMeshRenderer, It has been added for the root motion feature of the the mecanim system.

The actual link between the bones and the SkinnedMeshRenderer is made through the bones array. However this array is not visible in the inspector though it is serialized. That’s why a SkinnedMeshRenderer does not animate when you delete it’s own bone array.

One problem is that if you have two skinned meshes with identical bones, it’s not necessarily given that the order is the same. If it is the same you could simply copy the bones array from your main model to your clothes model.

If the order is not the same and you want to use a single bone structure you would need to keep the both bone hierarchies and use a script to replace the bones one-by-one based on the bone name / hierarchical position.