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 animations from multiple assets


At times it is very convenient to separate animations to multiple assets. A common scenario is to have rigged models separated from animations or different animation types separated from each other (combat from movement, movement from actions, actions from cut scenes, and so on). This recipe shows how to do it for both Humanoid and Generic rigs.

Getting ready

Before we start, you should prepare and import at least two assets containing animations. If you are using a Generic rig, make sure to have the same rig in both assets. You can also use the provided example Unity project and go to the Chapter 01 Working with animations\Recipe 06 Using animations from multiple assets. There is a scene called Example.unity file there. In the scene Hierarchy you can find a Character game object. It has an attached Animator Controller in which you can find two animations: Idle and Wave. In the Rigs directory, you will find the Character.fbx asset containing only a rigged character along with the Idle.fbx and Wave.fbx assets containing the corresponding animations.

Note

If you are exporting FBX files from Blender, make sure to disable the Add Leaf Bones option in the exporter. If you are exporting just the rig and animations (without a mesh), add an empty object to the scene. If you will not do this, your rig could be messed up a bit after import.

How to do it...

To use animations from multiple assets, you need to follow these steps:

  1. Import the files to Unity.
  2. If you are using the Generic rig, you have to set the Avatar Definition to Create From This Model on your character (or reference character if you plan to have multiple characters with the same rig). For each imported animation asset, set the Avatar Definition to Copy From Other Avatar and choose the avatar of your character or reference character. To do so, you need to unfold the character asset, find the avatar, and drag and drop it to the Source field in the Inspector tab.
  1. If you are using a Humanoid rig, you don't have to copy the Avatar Definition (you still can if your rigs are exactly the same; that way you will have fewer avatars in your project, making it easier to find the ones you need).
  2. Create or open an Animator Controller.
  3. Assign animations from different files and build transitions between them.
  4. Run the game to see the animations work.

How it works...

All Generic rigs can use animations from multiple assets that share the same Avatar Definition. To share the same Avatar DefinitionGeneric rigs have to have exactly the same rigs (the same hierarchy, the same bone names and transforms). All Humanoid rigs can use animations from multiple assets that are also set to Humanoid. Additionally, they don't need to have the same rigs because Unity automatically retargets all humanoid animations.

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