Animating facial expressions

When working with 3D Characters, it's likely that you'll want them to be visually emotive, and change expression based on their mode. Facial animation can be applied by using the Character: Animate Action, but it's also possible (and often more convenient) to use BlendShapes.

If you want a character to change expression based on what text they are saying, see this tutorial.

When you import a model into Unity that has blend shapes, you'll find that you can access the intensity of each shape within the Skinned Mesh Renderer component. Here, for example, the Brain model used in the 3D demo has two BlendShapes related to expressions: ExpressionHappy and ExpressionSad:

While we may want to transition between these two shapes, we generally only want one to be "active" at any time. Adventure Creator lets us group such shapes together, so that we can call upon them more easily.

Begin by adding the Shapeable script component below the Skinned Mesh Renderer in the Inspector window.

In the component's Inspector, click Create new shape group, and label it Expressions.

We'll create one shape key per BlendShape, so click Create new shape key twice, naming them Happy and Sad respectively.

Each key needs to be mapped to one of the BlendShapes listed above, in the Skinned Mesh Renderer. This is done by entering the index number, or the number (starting from zero), in which the BlendShapes appears in the list. Therefore, the Happy key's Blendshape index is 0, and the Sad key's Blendshape index is 1.

Our Character's BlendShapes can now be manipulated with the Object: Blend shape Action. From within the Scene Manager, create a new Cutscene, and change the default Action to Object: Blend shape. (For more on Cutscenes and Actions, see this tutorial)

Set the Object field as the GameObject we were just working with, and you'll see that the Action updates itself with the group we defined:

We now want to choose which of our shapes is made active, and by how much. Set the Shape key to Happy, and set the New value to 100. Increase the Transition time to 0.5, and set the Move method to Smooth.

We can test this Action out by running our scene, and clicking the Run now button at the top of the Cutscene's Inspector.

Look at that smile!

While the game is still running, try changing the Shape key to Sad, and run the Cutscene again. Notice how the Happy BlendShape turns itself off - this is because both shapes are in the same group. Any shapes on the Skinned Mesh Renderer that aren't in this group will be ignored by this Action, making it a convenient way to give Characters expression.

Adventure Creator and this website are copyright Chris Burton, ICEBOX Studios

Go to top