Introducing the Simple Animation Component
Staff Writer By: David Geoffroy, Unity
Ever since they were introduced as experimental in 5.2, Playables have been mysterious beasts. Many of our users have been curious, and have asked us, "What am I supposed to do with those?" We answered, "Anything!" but we didn't have any concrete examples to start from... yet.
After multiple API rewrites and Unity versions, Playables were moved out of experimental in 2017.1, along with the release of Timeline. At that point, the answer became "anything you want, including custom Timeline tracks, or even something as complicated as your own Timeline".
While this answer is certainly exciting (customizability is always nice), making your own Timeline is something very few will even attempt, and we were still missing examples of the other category: "Anything you want".
Why not an Animation Component?
On the Animation team, one common feedback we receive is that the Animator component and the AnimatorController are often unnecessarily complicated for simple cases where you want one or a few animations on an object.
Another frequent request is more complex Playables examples. A few basic examples were made to show simple API usage, but they are not very useful to show what can be accomplished using Playables.
Therefore, we decided to address both issues at the same time, and make a simple Animation Component, all in C#, and Open Source it so that it could also serve as a living, functional Playables example.
(If you'd rather jump directly to the code or try it for yourself, you can find the implementation here.)
Something old, something new
The Animation Component is already well documented, still widely used, and except for a few more advanced features, has a simple and straightforward interface. As far as examples go, reimplementing something our users already knew and could intuitively understand seemed like an obvious choice.
As is visible in the above Inspector screenshot, the SimpleAnimation inspector is very similar to the Animation inspector, except for one thing: the SimpleAnimation Component requires the Animator to run. As the designed Animation output for Playables, the Animator is required by Playable Graphs. That, however, is the extent of its use. By adding a SimpleAnimation Component to a GameObject, the Animator will automatically be added for you. You can then simply fold it away and forget about it.
On the scripting side, the interface is almost identical to the Animation Component's interface. You can find an in-depth explanation of the differences on the project's wiki here.
Retro exterior, new engine
Graph Visualizer view of the SimpleAnimation Playable Graph
While the SimpleAnimation Component looks like the Animation Component on the outside, under the hood, all the Animation logic is implemented through Playables. This way, the component is compatible with Timeline, with other playable graphs, and, the Animation logic can be reused in other Playable graphs.
Not just a playable example
Simple Animation tests in Unity test runner
To ensure a smooth transition from the Animation component, we had to make sure that the SimpleAnimation Component's behavior was as close as possible to that of the Animation Component. Since some of the test tools we use internally at Unity are now public, it was very easy for us to create tests and include them in the project. The project contains a suite of more 100 comparative tests that validate that both Animation and SimpleAnimation components behave the same. When you clone or download the SimpleAnimation GitHub project, the tests can be found under Assets/SimpleAnimationComponent/Tests. If you decide to customize or extend the Component, you can use those tests to validate your work.
The Simple Animation Component is compatible with Unity 2017.1 and subsequent versions, and it's available now on GitHub. Please try it out and give us feedback.