We all have at some point wanted to make a 3D GTA like game with characters running around and punching old grandmas in the face. On my recent endeavor along the slopes of Mt. Mocap I realised that I had it figured out all wrong from the ground up. Let's go from the basics.
Animations in Unity
Quoting Unity's Documentation, "Unity’s animation system is based on the concept of Animation Clips, which contain information about how certain objects should change their position, rotation, or other properties over time." This means that each clip has a set of position and rotation data of a set of bones over a certain duration. So essentially, you would ideally have an animation clip for every kind of action, e.g., running, jogging, punching a grandma in the face, etc...All these animation clips can be controlled and played in an Animation Controller.
Animation Controller
Animation controller acts as a state machine to drive the characters actions and movements. It defines which animation needs to be played and when it needs to be played, what are the blending settings between clips and so on. You can read more about it here.
Animation Controller is an asset, meaning its saved on the disk and can be shared and will be quite easy to work with if Version Control is involved. Double clicking the Animation Controller asset opens it in the Animation Tab.
You can check the transitions during Play time if you select the controller from of the active controller. Ensure Auto Live link is enabled in the Top right of the Animator tab.
Retargeting
One of the coolest features of Unity's Animation system "Mecanim" is retargeting. In general retargeting in animation means translating movement of one rig to another rig with a different hierarchy. This is pretty common because there is no fixed standardised bone hierarchy and your character might have some specific bone needs like wings and horns and other interesting appendages. What Unity allows you to do is that you can retarget your rig to Mecanim's internal rig ( I guess thats how it works ) .
Importing & Settings
On importing your character to unity,if you select your 3D asset in the project tab, you get a few settings to tweak. These are the import settings of your 3D asset.
The import settings might look similar to the picture attached here. Since a lot of games need a humanoid character, unity comes packages with tools to deal with those. It is necessary to choose Animation Type as Humanoid to make use of Mecanim's full power on humanoid character models.
If this is your first character, you can create avatar definition here. This will try to retarget your rig to Mecanim's rig and you can configure bones and muscle settings in the Avatar Configuration window by clicking on the configure button as seen in the picture. You can read about these settings here.
Avatar
One way of understanding avatar is to consider it as a mapping data between your rig and the internal rig, if there are several animation clips made with the same rig you can use the same avatar for all of them.
How do you use Animations from multiple rigs?
Step 1 : For each new rig it is good practice to have the t-pose clip of your character making it optimal for retargeting.
Step 2 : Check for errors in import settings and try to adhere to the guidelines mentioned by unity here. If there are no errors, you now have a fully functional avatar.
Step 3 : Choose an animation clip and set its avatar as the same one created for the same rig. Do not try to use the avatar of another rig, it most probably wont work.
Step 4 : Ta Da!! Now your animations will work irrespective of which rig they were made in.
As long as all your rigs are retargeting successfully their animations are theoretically usable directly in an Animation Controller along with animations of each other's rigs. It is necessary for animation clips to be of type humanoid for it to work. You might have to do some cleaning up in your animation software a bit before importing it into unity.
Not the best or clearest flowchart but I think it gives a decent idea about how this system works and this can also be used as a simple base level pipeline as well for dealing with multiple rigs. This means that you can now integrate multiple different rigs in your unity game without many restrictions. Most 3D software includes retargeting toolset in them, and they do have much more settings and provide more control to the user but for a quick output, this seems to be adequate with a decent amount of control. Checkout the references in the links for more details and specifics.
Opmerkingen