Unity : Animate your character using Mecanim

In the Legacy animation system(Before unity 4.0),we used to manually write code to control the animation.We were either using a animation.CrossFade(); or animation.Play().After the advent of unity 4.0 ,things changed drastically(in a positive way).Unity introduced something called MECANIM.
Mecanim, Unity’s uniquely powerful and flexible animation system, brings your human and non-human characters to life with incredibly natural and fluid motion.


This is a simple mecanim setup (animator window), which i used in my soccer game to control the character.

The animated character is controlled by changing the state,state is managed through the parameters (speed and direction) which you will define in your script (C#/Javascript/Boo).

The  transition(white arrow in the figure above) from Idle to walkback and vice-a-versa is controlled by playing with speed parameter.

  • If speed less than -0.1,then transition from idle to walkback (down arrow)

  • If speed greater than -0.1 then transition from walkback to idle

In my soccer game,the character will be in 'Any state',when i start increasing speed (forward arrow),character will change the state from 'idle'->'walk'->'Run'

As you see there is one more parameter called 'Direction'.Let me tell you,how i use this to control (change state) my character.


In mecanim,The most important concept to understand is 'Blend Tree'.
Blend Trees are used for allowing multiple animations to be blended smoothly by incorporating parts of them all to varying degrees.

Using the blending parameter Direction,i make the character to turn right or left in the current motion (walk or run).For any blending parameter the minimum value is -1 and maximum value is 1.So when my direction parameter value is

  • -1,character will turn left in current motion.

  • 0,straight in current motion.

  • 1,will turn right in current motion.


Check the threshold value to understand what i was talking about.

In a summary,

Unity has a rich and sophisticated animation system called Mecanim. Mecanim provides:

  • Easy workflow and setup of animations on humanoid characters.

  • Animation retargeting - the ability to apply animations from one character model onto another.

  • Simplified workflow for aligning animation clips.

  • Convenient preview of animation clips, transitions and interactions between them. This allows animators to work more independently of programmers, prototype and preview their animations before gameplay code is hooked in.

  • Management of complex interactions between animations with a visual programming tool.

  • Animating different body parts with different logic.

For a complete experience of mecanim, please go through this video.

Courtesy :Unity3D

Vidyasagar MSC

Developer Advocate, IBM • Microsoft XBox MVP • Intel software Innovator


  1. "Definition of adversely : When something affects you adversely , it's harmful or negative."

  2. Thank you for your correction :)