Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

PlayableGraph: Play simple animation clip, how to find out if its done playing

Discussion in 'Animation' started by fgrizeljigt, Nov 7, 2019.

  1. fgrizeljigt

    fgrizeljigt

    Joined:
    Jul 15, 2019
    Posts:
    2
    Hi,

    I am using playable graph api to play a simple animation clip. How to find out if animation clip is done playing? It is not PlayableGraph.IsPlaying() or PlayableGraph.IsDone(). I can get to the AnimationClip through PlayableOutput and AnimationClipPlayable, but AnimationClip itself doesnt seem to have anything indicating if its playing or not.

    I am using this example from unity manual:
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. using UnityEngine.Playables;
    4.  
    5. using UnityEngine.Animations;
    6.  
    7. [RequireComponent(typeof(Animator))]
    8.  
    9. public class PlayAnimationUtilitiesSample : MonoBehaviour
    10.  
    11. {
    12.  
    13.     public AnimationClip clip;
    14.  
    15.     PlayableGraph playableGraph;
    16.  
    17.     void Start()
    18.  
    19.     {
    20.  
    21.         AnimationPlayableUtilities.PlayClip(GetComponent<Animator>(), clip, out playableGraph);
    22.  
    23.     }
    24.  
    25.     void OnDisable()
    26.  
    27.     {
    28.  
    29.         // Destroys all Playables and Outputs created by the graph.
    30.  
    31.         playableGraph.Destroy();
    32.  
    33.     }
    34.  
    35. }
     
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    596
    PlayClip returns an AnimationClipPlayable and you can then use GetTime on it and compare that to the length of the clip.

    You might also be interested in Animancer (link in my signature) which is built using Playables and would save you a lot of trouble trying to make sense of their API. In particular, it has several easy ways of waiting for animations to finish.
     
  3. fgrizeljigt

    fgrizeljigt

    Joined:
    Jul 15, 2019
    Posts:
    2
    That worked! Thanks very much, Ill be sure to check it out.