How to Export an Optimized Blender Rig with Animation to Unity

hot toys bruce lee upper body

I've spent a lot of time wrapping my head around animation in Blender and understanding how to optimize and export animation from Blender to Unity. Without going into too much detail, here's a break-down of the steps I take and my learnings so far. I will say this, animation is hard. It's very hard. I do not consider myself an animator. If you have any feedback on my process, please share it with me.

⚠ WARNING  
THIS IS NOT A TUTORIAL FOR ABSOLUTE BEGINNERS
💀 YOU HAVE BEEN WARNED ðŸ’€

I want to give a big shout-out to CGDive. The CGDive YouTube channel is a must watch if you're struggling with exporting animation to a game engine. His Blender add-on "Game Rig Tools" (GRT) is what has kept me sane when dealing with animation, and I highly recommend it. I will link a few videos and playlists to check out for more in-depth information (bottom of the page). The GRT add-on is part of my workflow, and though you can do it manually, save yourself the trouble and just get the addon. 

Before you start, make sure that...

  • …your character is facing forward (-y).
  • …the feet are planted on the ground.
  • …the pivot is in the bottom center of the mesh.
  • …scale and rotation is applied.
  • …the model is to scale.
  • …the topology is good.
Basically we'll be creating two rigs, a control rig and a game rig. The control rig is what you will animate and the game rig will be what you export (which will be optimized for a game engine). 

Part I: Create a Control Rig

  1. Create a rig of any sort (this is your control rig). This could be done manually or, for example, with Rigify. There are many tutorials for this on YouTube if you are not sure of how to do it, but basically you add an armature, extrude bones, parent those bones, create IK-chains, align the bones, and symmetrize if needed. See link in the resources section at the bottom for CGDive's manual rigging approach.
  2. Make sure the mesh and the armature are placed at the world center.
  3. Select the mesh, then the control rig and parent With Automatic Weights.
  4. Make sure everything is working as intended by checking in pose mode.
  5. Name it "LookAtMeI'mRiggingControlRig" (or something else that makes more sense).
a mesh with a standard rig
The Shadow Man from our game LIMINAL PHASE with a control- and game rig (hidden).

Part II: Generate a Game Rig with the GRT Add-on

  1. GRT window
    It's as easy as clicking the button.
    Select the control rig in object mode and
    generate the game rig with GRT.
  2. Name it "LookAtMeI'mRiggingGameRig"
  3. Make sure all bones are parented correctly.

Part III: Weight Paint it

  1. Select the game rig in object mode, then select the mesh, switch to weight paint mode and Ctrl-click on a bone to start weight painting.
  2. Paint with the value set to Mix and adjust the Weight to either 0 or 1, depending on if you want to add or erase.
  3. Make extreme poses and adjust your weight painting if needed. Clear all transformations when done.

Part IIII: Animate it

  1. Position the timeline on "0" for Unity.
  2. Create an action and name it "CTRL_Asset_AnimationType". You can name it whatever you want, but make sure you use a prefix like "CTRL_" (for control rig).
  3. Animate the control rig and then push the action to the NLA. I'm aware that the previous sentence could be anything from a few minutes to days or perhaps weeks of work, but as this is not an animation tutorial, I will gently and respectfully move on...

Part V: Bake Animations with GRT

  1. GRT window
    Bake actions.
    Make sure that both the control rig and the game rig are visible.
  2. Add the actions that you want to bake in GRT's Action Bakery.
  3. Set the frames manually if needed, specify the rigs and check Push To NLA. 
  4. Press Bake Action Bakery, choose Replace and set From: "CTRL_" and leave To: blank. Press OK.
  5. Test the actions. The constraints will be muted by default after you have baked the actions. Remember to turn these on in pose mode when you are going to animate. You can mute and unmute using the two buttons at the top after selecting the game rig.
  6. If you want to, you can create a default pose action for the game rig on frame 0 that has all transforms cleared. Set a keyframe, then push it down to the NLA.

Part VI: Export to Unity

  1. Make sure that the scale is applied and position the object at 0, 0, 0. 
  2. Hide the control rig and make sure that the constraints are disabled before you export (muted).
  3. Select the armature, then the mesh/meshes and export an .fbx-file.
  4. Settings for exporting: check Selected objects, choose Armature and Mesh, disable: Add Leaf Bones, under Armature. Disable: All Actions, under Bake Animation. See link below for an in-depth article regarding this.

Part VII: Quick Setup in Unity

  1. Go with Animation Type: Generic, and pick Avatar Definition: Create From This Model.
  2. Create an Animator Controller and drop it on your asset.
  3. Go to the Animator window, drop animations from the .fbx-file and connect them.

Part VIII: Resources

CGDive

Comments

Popular posts from this blog

How To Set Up a Steam Broadcast With RoboStreamer

Some thoughts on finishing a game