Swapping Rigged Hair to an Existing Armature

ADDING RIGGED HAIRSTYLES TO ARMATURES

Using Unity Version 2019.4


We’re going to talk about hair today!


This tutorial is a bit of a follow-up to my Adding Parts to a Rigged Character guide. Both are about moving parts from one character rig to another, but the key difference here is that in this tutorial, we're going to use parts that are weighted to unique armature bones. Namely: Hairstyles.


The Problem

Let’s say that you have a character with a few hair and clothing options. In many cases, like with my assets, the hair is rigged to unique hair bones to allow for physics or animation and that means every hairstyle will use a slightly different rig, even if the main skeleton is consistent. So the character with Clothing A will have Hairstyle A and Clothing B with Hairstyle B. But if you want to move Hairstyle B over to the rig with Clothing A, you run into a problem because the hair bones are different.


My Solution

You could follow my other guide and just move the hairstyle over to the new rig, ignoring the hair bones entirely. However, this could cause issues if the hair depends on those bones. Perhaps it’s only partially anchored to the Head bone and the rest of it is weighted to children of the Head bone. In that case, the unweighted vertices of the mesh would behave as though they weren’t weighted to anything at all because…well…they aren’t. And even if none of that is an issue, you lose any ability to use physics on the hair bones or animate it.


So the best solution is to move the hair and the hair bones over to the rig. This tutorial will show you how to do this.


We’ll also talk about doing this with a custom editor so you can create new character prefabs and how to add physics to the hair.

This post will use two of my character packages as an example: Scarlett Riley: Stylized Sci Fi and the Ultimate Stylized Business Women. However, they aren't required for this tutorial -- you could definitely adapt the code for your own characters too! Scarlett is a great example to work with because there are multiple rigs and hairstyles available. You can purchase the assets to follow along if you want :)

If you want to be able to add physics to the hair, you'll want an asset to do so. I prefer Dynamic Bone, which you find here:



How it Works:

This code will do three things:

  1. Remove the existing hair bones and hairstyle from an armature

  2. Add hair bones from a new armature to the existing armature, and

  3. Add the corresponding hair mesh from the new rig to the existing armature

Rules

  • If the hairstyle is weighted to bones other than the hair bones, such as the head, spine or shoulders, the armatures (aside from the hair bones or extended bones for wings, weapons, etc.) MUST contain the same hierarchy of bone names. This is because hair that contains weights for the head, spine, shoulders, etc. will look for those bones in the rebinding code.

  • The characters MUST be the same. This code is intended for meshes that are already modelled to the character. For instance, my Scarlett characters will all work with other Scarlett hairstyles, but you won’t get ideal results if you try to use a Dahlia hairstyle on a Scarlett character. The heads, neck, shoulders and chest between the characters are different shapes and sizes and the hairstyles are modelled for them separately.

So with that in mind, let's get started!


The Setup

When you open the Prefab folder in the Scarlett Riley package, you'll see five folders for the different clothing options. Inside each folder are three FBX files -- one for each hairstyle.


Start by choosing any of the prefab files and drag it into the Scene hierarchy. This will be the main armature (the one you are going to move the new hairstyle to).


Right click on the character in the hierarchy window and select Unpack Prefab Completely.