Simplified Animations in Unity3d

Taming Graphs with Playables API

While I'm a big fan of Unity's Mechanim animtion system and it introduced a ton of great features, sometimes the original "Legacy" animation system worked a lot better by allowing developers a programmatic interface to controlling animation logic.

This article shows how to use the Playables system (a feature introduced in 2017, but something I haven't spent a lot of time using) to simplify your animation controllers by taking direct control over animation states of your avatars, as well as the transitions between them using an interface similar to the Legacy animation system.

For this article we will be using:

Mechanim is the built-in animation system for Unity, that has a lot of really great features and was ahead of it's time when it was introduced years ago. The general workflow involves using a GUI to build a graph representation of all the animations your character can have, where each edge was a configurable transition, allowing you full control over each state, condition, and blend process.

It works best when you can handle your animation logic as much in the graph as possible, and your code is simply feeding character state into the mechanim graph. Conversely, when your character state tracking grows sufficiently complex, it feels like an unnecessary compliation to replicate this in Mechanim - sometimes, even for very complex animation networks, you wish you could just do things the Legacy way.

In contrast, the Legacy animation system tracked only an actively playing AnimationClip, and offered some rudimentary APIs for performing basic transitions (ie: blending between two animations). Unfortunately, it also lacks retargetting, IK, layers, and other advanced animation features.

What would be great is Legacy API ontop of Mechanim, that allows us direct control over the animation graph. Unity actually does provide a system called Playables, originally designed to assist developers in making in-game cutscenes, that allows you to build and execute graphs in code, as well as an API for directly controlling Mechanim objects. Originally, I used Playables sparingly just as a way to manage in game cutscenes and some basic behaviors, but I was inspired to attempt to use the same system to write a custom Animation Player that works like the Legacy system, while maintaining all the great features of Mechanim.

The AnimationPlayer

[TODO: Explanation]

Full Source