If you have multiple types of character in your game, most probably you would like to be able to share the animation states logic between them and just replace the animation clips. Imagine that you have several types of enemies, and their combat logic is the same (they have attacks, movement, hit reactions, and so on) but they use different animation clips. For such situations, Override Animator Controllers
come in handy.
You should have at least two characters with different animation clips ready and imported into Unity. You can also download the provided example Unity project and go to the Chapter 01 Working with animations\Recipe 09 Using override animator controllers to animate different types of characters
directory. There is a scene called Example.unity
there. If you open it, you'll find Warrior
and Spider
game objects in the Hierarchy
. They have Override Animator Controllers
attached, and you can examine them. If you run the game, the characters will play attack animations. The underlying logic is defined in the HumanCombat
controller (found in the Animator Controllers
directory). The Warrior
game object uses the HumanCombat
controller without overriding it, the Spider
game object uses a SpiderCombat
override controller.
To use Override Animator Controllers
, follow these steps:
- Create a normal
Animator Controller
that will be used as the reference controller containing the logic of animation states. In the provided example, it is theHumanCombat
controller, created withWarrior
animations. - You can attach this controller to your first character (its
Animator
component) and use it as previously. - Create an
Override Animator Controller
by right-clicking on theProject View
and choosingCreate
|Override Animator Controller
. - Select the newly created override controller and go to the
Inspector
tab. - Drag and drop your original/reference
Animator Controller
to theController
field of the newly created override controller. - You will see all your original animation clips listed on the left and fields for overriding those animation clips.
- Drag and drop the animation clips from your second character to the override fields corresponding with original animation clips of your first character. In the provided example,
Human
animations are replaced withSpider
animations. - Assign the
Override Animator Controller
to theController
field of theAnimator
component of your second character.
Override Animator Controller
only replace animation clips from your original Animator Controller
. The logic of the original controller stays the same (so you can also use the same scripts to set the same parameters and so on). It is extremely useful for creating NPC characters in your games. You create the Animator Controller
once, you write the scripts driving the controller once and only change the animations.