Radivarig / uPlayableAnimation

An animation plugin based on Playables API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

uPlayableAnimation (Unity Playable Animation)

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


How to install

From source

  1. Download ZIP archieve using “Code” green button on the main github page.
  2. Copy past “Assets/Plugins/uPlayableAnimation” folder to your project.

Package Manager

  1. Open Package Manager at Unity project.
  2. Click on “plus” at left up corner.
  3. Choose “Add package from git URL…”, past link https://github.com/{Company}/uPlayableAnimation.git?path=/Assets/Plugins/uPlayableAnimation and click “add” button.
  4. For more info you could refer to: “https://docs.unity3d.com/Manual/upm-git.html”.

This project provides

  • 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.

Showcase

Play multiple animation clips and on multiple animator controllers at runtime

ezgif-5-ab446a8f1d

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.

Customize animation frame rate and animation clip speed at runtime

ezgif-5-3e6e88577d

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.

Also works for non-character animators

ezgif-5-da099ab765

Supports Avatar Mask (layered animation)

ezgif-5-d316fb8c4c

The script handles layer blending through the Playables API.


Setup/Basic usage - Animation Clip Output

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.

  1. To play a specific animation clip at runtime, assign it to the ToClip variable of the AnimationClipOutput component and then invoke the Play method.

ezgif-1-55c94e60bf

  1. 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.

ezgif-1-14adca54ea


IsStatic flag

image

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.


Avatar mask setup

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.

image image

Be careful not to assign multiple avatar masks to the same layer, as this will break the system.*


Animator Output

image

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.

ezgif-3-80e3c11651

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.


Animator Mixer Output

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.

ezgif-3-10d7762ef7

Check the 6th example scene's player control unity-chan and see how it setup.


TODO

  • 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)

License

Code under UPlayableAnimation is MIT.

All the unity-chan! related assets inside the Example folder are under UCL-2.0

About

An animation plugin based on Playables API

License:MIT License


Languages

Language:ShaderLab 52.6%Language:C# 39.3%Language:HLSL 8.1%