Reader small image

You're reading from  Unity 5.x Animation Cookbook

Product typeBook
Published inMay 2016
Reading LevelExpert
PublisherPackt
ISBN-139781785883910
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Maciej Szczesnik
Maciej Szczesnik
author image
Maciej Szczesnik

Not interested. Too busy with current game project. Source: Linkedin.
Read more about Maciej Szczesnik

Right arrow

Using override animator controllers to animate different types of characters


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.

Getting ready

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.

How to do it...

To use Override Animator Controllers, follow these steps:

  1. 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 the HumanCombat controller, created with Warrior animations.
  2. You can attach this controller to your first character (its Animator component) and use it as previously.
  3. Create an Override Animator Controller by right-clicking on the Project View and choosing CreateOverride Animator Controller.
  4. Select the newly created override controller and go to the Inspector tab.
  5. Drag and drop your original/reference Animator Controller to the Controller field of the newly created override controller.
  6. You will see all your original animation clips listed on the left and fields for overriding those animation clips.
  1. 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 with Spider animations.
  2. Assign the Override Animator Controller to the Controller field of the Animator component of your second character.

How it works...

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.

Note

Your original Animator Controller has to have animation clips. You cannot override empty animation states.

Previous PageNext Page
You have been reading a chapter from
Unity 5.x Animation Cookbook
Published in: May 2016Publisher: PacktISBN-13: 9781785883910
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Maciej Szczesnik

Not interested. Too busy with current game project. Source: Linkedin.
Read more about Maciej Szczesnik