Unity Animation Pipeline From Maya (Part 2)
Picking up from where the previous post left off, here are the final steps to getting those animation files to Unity.
Folder Structures, File Naming, and Formats
I always recommend saving your Maya files in “Ascii” format instead of “Binary.” Saving in this manner changes the Maya File extensions to “MA” and allows you to salvage files that get corrupted by editing the text directly. When Binary files get corrupted, they are typically unrecoverable.
Rig\Base Model Maya File
The “name” of your character, building or Animated Object inside unity. It should be something descriptive and informative to anyone looking at it.
For our purposes, we are working on a character simply named “Male01”.
Maya File Name: “Male01.ma”
We are going to utilize a special character when naming our animation files. The @ symbol lets Unity know that these files are animations and automatically names Animation Clips for us inside Unity. Even though these are the Maya files, we want to keep the naming consistent between packages to make them easily correlated with each other.
All animations should begin with the Rig\Base Model name followed by the @ symbol.
After the @ symbol should be the name of the animation itself IE:
I ALWAYS add a “01” to the end of my files to future proof and make sure the file system displays them in order.
I tend to set up a mirrored “Source” and “Project” directory for every project I am on. Mirrored folder structures make it easier to find source files, as well as making it simpler to automate the exporting process through scripts later on.
Source Folder Structure
Project Folder Structure
Exporting To Unity
The exporting process, when done right, is a destructive process. You delete and bake your joints inside the Maya file, which effectively destroys your Rig or Animation Files for future editing.
SAVE A COPY of your file before you start this process or make a script that does all this for you. I will go over how to write a script for this process later and link back to this.
FBX Export Settings
Settings for ALL exports should be as follows:
Scale Factor: 1
File Units Converted To: Centimeters (This is due to some Maya to Unity unit conversion wackiness, see dev notes below)
Axis: Y up
Type: ASCII (See Developer Note Below)
The reason we converted the FBX to centimeters is to remove a scale value that gets baked into the joints when we export in meters. We want the file to be as clean and close to “default” as possible, so we do not have to work with bizarre scale transforms in the Editor. The centimeters option cancels out the difference in Units between the two packages, leaving the scale result 1 inside the FBX.
ASCII FBX format makes it easier to write scripts that set up your files in the future. Binary, while smaller, makes the file inaccessible for reading through scripts. More on adding custom attributes to your FBX files later.
Exporting a Base Model File – Skeleton + Skinned Model *No Animation*
The Base Model is the object that is the starting point of the Unity prefab and will “play” the animations inside Unity.
Save your file out as something else first, so you do not lose your work.
Bake all the skinned Joints down to frames. Baking makes sure that when you delete the control group, your joints do not move on you unexpectedly.
Use the bake options in Maya under Edit -> Keys -> Bake Animation with the parent object of the joint hierarchy selected.
Delete your control groups.
Delete any Extra Nodes. These would be any extra transforms at the root of the hierarchy.
Remove all namespaces on your nodes
The menu is located in Windows -> General Editors -> Namespace Editor
1. Select the Namespace and press “Delete” then merge them with the root.
2. Repeat this until all the namespaces are gone.
3. Completed hierarchy should look as close to ONLY the skeleton and mesh as possible:
Go to File -> Export All and save the file out in its mirror directory inside the project folder using the following FBX settings.
Removing Namespaces keeps your Unity Hierarchy clean and easily manageable when creating your prefabs or adding components to specific joints in the Unity objects by removing extra characters from your hierarchy.
Exporting An Animation File
Save the file out as an “Export” file to keep from losing your work.
Import References into the file
Importing is done through the Reference Editor: File -> Reference Editor
Right Click on your reference in the list Goto File -> Import Objects from Reference from the menu
Remove any namespaces on your nodes (See Developer Note ***)
Windows -> General Editors -> Namespace Editor
1. Select the Namespace and press “Delete” then choose the “Merge with Root” option.
2. Repeat this until all the namespaces are merged
Bake the animation down to the joint hierarchy, for the length of the Time Slider this time instead of just 0 to 1 like in the Base Rig
Remove all extra nodes. (Controls, transforms, Meshes, etc…)
File -> Export All using the above FBX settings and saving the file out into the “Animations” folder inside the project directory.
It is a good idea to run a curve filter to minimize the number of keys and thus the file size. That requires some fiddling to get the values right. I will address that in a future post.
The FBX should only be keyframes and the joints associated with them. Exporting in this manner reduces the space needed to store animations and minimizes them to only the information Unity needs to set up an Animation Clip.
*** The reason we are merging all the namespaces is to make sure that the joint hierarchy names match the rig file EXACTLY. Unity uses the joint names to map the animation, so if your animation does not on your Base Model file, this is the most likely culprit.
I guess this is a good spot to talk about using FBX files instead of MA or MB files directly. Using Maya files is typically not a good idea, especially for larger teams. You lose control over what and how things get exported into Unity, resulting in cluttered files and often transforms on your root objects that you then have to handle.
What it is doing is running a copy of Maya in the background and doing the export for you. Which also means that anyone that is working on your project needs to have Maya installed to view the assets properly.
I say, eliminate the middle-man and just export the FBX directly into the project. It makes it cheaper and easier to deal with the files later on and gives you the control over what is happening to your exported files.
Setting the Proper Scale
The purpose of all the scale settings in both the export and the source Maya files is to make sure that once the files get into Unity the “Scale Factor” is 1 and the “File scale” is .01. Again, this is because Maya is built to use centimeters and Unity is built to use Meters. This process reduces the “Scale Adjustment” to a single location, the export options, and leaves the in game transforms at 1.
As you can see, when put next to a 1 by 1 cube in the Unity editor the character matches up perfectly with zero scale transforms on the characters hierarchy.
The exported FBX file, once in unity, automatically creates an Animation clip under the file with the proper name of the animation.
The same scale settings that are on the Base Mesh apply to each of the animation files. (They should all be 1 and fileScale should be .01)
I will go over how to set up and manage your unity project in a later post, but that should be everything you need to start your art files off on the right foot.
Please let me know if I missed something, or if there was a part that was more confusing than the rest. I will be going through some of these sections in greater detail in future posts as a lot of this was meant as a general overview of how to get files into Unity properly.
Happy Game Making!
15 Free Unity Asset Tips
Join the community and stay up to date with the whats happening with the site!
I'll also throw in my top 15 tips for managing assets inside Unity!