Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Animations;
using UnityEngine.Timeline;
[RequireComponent (typeof(Animator))]
public class PlaySingleAnimation : MonoBehaviour
PlayableGraph graph;
void OnEnable ()
var animator = GetComponent<Animator> ();
if (animator.runtimeAnimatorController == null) {
graph = GetComponent<Animator> ().playableGraph;
} else {
graph = PlayableGraph.Create ();
var output = AnimationPlayableOutput.Create (graph, name, animator);
void OnDisable()
graph.Destroy ();
public void Play (AnimationClip newAnimation)
public IEnumerator PlayAnimation (AnimationClip newAnimation)
var playable = AnimationClipPlayable.Create (graph, newAnimation);
var output = graph.GetOutput (0);
output.SetSourcePlayable (playable);
graph.Play ();
yield return new WaitForSeconds (newAnimation.length);
graph.DestroyPlayable (playable);
graph.Stop ();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.