While Unity's node based animator is visually straightforward, it does not scale well. The aim of this project is to create a library of scripts that replaces Unity’s animator controller.
uPlayableAnimation uses Playables API, to minimize the use of the animator controller. Animation logic is added to a MonoBehaviour script. Making animation handling logic more easily reusable and scalable.
Simply drag and drop the provided AnimationClipOutput script onto a game object that has an animator component (the animator component does not require a controller). At runtime animations can easily be blended into any state.
This project is still work-in-progress.
You can provide your feedback at the Unity forum post
- Download ZIP archieve using “Code” green button on the main github page.
- Copy past “Assets/Plugins/uPlayableAnimation” folder to your project.
- Open Package Manager at Unity project.
- Click on “plus” at left up corner.
- Choose “Add package from git URL…”, past link https://github.com/{Company}/uPlayableAnimation.git?path=/Assets/Plugins/uPlayableAnimation and click “add” button.
- For more info you could refer to: “https://docs.unity3d.com/Manual/upm-git.html”.
- Transition into different animation clips without wiring the animator controller over and over again.
- Assign/Transition animation at runtime.
- Avatar mask (layer-animation) support.
- Custom animation frame rate at runtime.
- Custom animation speed at runtime.
- Supports crossfade transitions between existing animator controllers at runtime.
- Custom crossfade time for each animation clip at runtime.
- FixedTimeOffSet option for offsetting target animation's start frametime when performing a crossfade.
The AnimationMixerManager creates a PlayableGraph and manages all the playable input and output within the graph. The role of AnimationOutput is to prepare the animation settings and clips and request the manager to play them. The manager will handle the life cycle of all the playables in the graph.
For performance and other reasons, you can adjust the frame rate of each animator at runtime as well as each clip's speed. Setting speed to negative will play the clip backwards.
The script handles layer blending through the Playables API.
If you’re unfamiliar with Unity’s Playables API, read the documentation. Then install the Playables Graph Visualizer.
Create a game object that be can be a character or any object, then add an Animator component (leave the Animator component empty).
- Drag the AnimationClipOutput component on the game object.
- Add an animation clip to AnimationClipOutput and create a script that calls Play() or for testing simply use the ‘Play’ button on the component.
There are two approaches to blend between animation clips.
- To play a specific animation clip at runtime, assign it to the ToClip variable of the AnimationClipOutput component and then invoke the Play method.
- There’s no limit to the number of AnimationClipOutput components each game object can have. Invoke the Play method on each AnimationClipOutput and the manager script will handle the blending for you.
For dynamic animations that are played once and then discarded, the IsStatic field should be set to false. This will cause the manager to destroy the playable animation on the graph once it is finished. In other words, each time the Play() method is invoked on a non-static AnimationClipOutput component, the manager will create a new playable and blend into it, then destroy the old playable.
Animation clips can be swapped at runtime. The new animation will take effect once Play() has been invoked.
Some animation states are meant to be permanently on the animator, such as idle animations. If you set the IsStatic toggle to true on the AnimationClipOutput component, the playable animation will persist on the playable graph. The downside is that you can't change the clip on the component at runtime. However, replaying a static animation has less overhead than a dynamic one.
By assigning a layer index inside the AnimationClipOutput component. The manager will create a AnimationLayerMixerPlayable on its own playable graph to handle the blending between different layers.
Be careful not to assign multiple avatar masks to the same layer, as this will break the system.*
In some cases, you may need to blend your animator with an existing animator controller. The AnimatorOutput component allows the animator to transition to a specific animation controller, even if the transition occurs at runtime between different animation clips and animator controllers.
The above gif demonstrates the use of the AnimationClipOutput and AnimatorOutput components. Notice how the AnimationMixerManager automatically manages the playables in the playable graph. This allows for seamless mixing of animations at runtime.
The AnimatorOutput component allows you to transition to different animator controllers. However, sometimes you may need more precise control over the transition weight between an animation clip and an animator controller. For example, you may have an idle animation and an animator controller that uses a 2D blend tree for strafe locomotion. In this case, the AnimatorMixerOutput component allows you to set up an animation clip and an animator controller, and then control the transition weight between them using the exposed Weight variable.
Check the 6th example scene's player control unity-chan and see how it setup.
- Improve the component's custom editor.
- Support unity animation rigging package.
- More/better examples (WIP).
- Clearer documentation.
- ~~Expose playable speed for easier customization ~~ (Done)
Custom frame rate for each animator(Done)
Code under UPlayableAnimation is MIT.
All the unity-chan! related assets inside the Example folder are under UCL-2.0