MOVING MESHES TO NEW ARMATURES
Using Unity Version 2019.4
A customer recently asked me if it was possible to swap hairstyles between my characters. The answer? Yes, but it can be complicated.
Hi there! I have a problem I’m hoping you can help me with. We’ve purchased your Sci-Fi Scarlett Riley character and I’m wondering if it’s possible to use the hair from one with the others? Also, is there a way to use Sci-Fi Scarlett’s accessories (belt, backpack) only when we want to? Should we just hide them and make turn them on when needed? We’re hoping to create more armors for her like helmets, weapons, etc. How do we make the pieces bend with the character animations only when they are equipped?
This is a common question with a complicated answer.
Of course, there are hundreds of ways to achieve this. If I reiterate the question above, it seems simple enough: We want to add additional meshes to an existing armature. Hundreds of games do this. It must be simple, right?
Most people initially approach this in one of two ways:
1. Export the rigged character with the mesh parts. As the accessories are changed, added, or removed, a script will turn their respective mesh renderers on or off. Why it is not ideal: This can mean exporting a rigged character with a ridiculous number of meshes. Additionally, characters that need to share the same accessories need each part exported with their rig, which means duplicating each accessory/hairstyle mesh for each and every character. That could be…a lot.
2. Just parent the mesh parts to the existing character rig. This is the primary way to add attachments like weapons or shields to characters. A script will either parent a mesh from the scene to an existing target within the character rig or instantiate a prefab to the existing target within the character rig.
Why it is not ideal: As stated above, this works well for attachments like weapons. But the reason this will not often work for other parts is because it ignores bone weighting completely. In other words, the entire weapon is turned into a child of the target and will move as the target moves. However, if you try this with, say, parenting a belt to a hip or spine bone, it will not be weighted to the armature and the vertices in the weight will stay rigid as the character moves, like this:
Following that, our question is not only how to parent additional parts to the armature, but also how to make sure it’s weights respond properly to the bones of that armature.