Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

AnimationClipPlayable stopping behaviour

Discussion in 'Scripting' started by attk0, Jun 22, 2021.

  1. attk0

    attk0

    Joined:
    Apr 16, 2016
    Posts:
    8
    Hi!

    I'm a bit confused on the stopping behaviour of an AnimationClipPlayable. When I play an animation clip via an AnimationClipPlayable and the actual animation/clip/movement eventually ends, the playable's play state remains "Playing".

    Is this intended? Due to this the graph remains playing indefinitely and I cannot for example receive callbacks on when the graph has stopped using custom PlayableBehaviours. I don't understand why the clip ending would not stop the playable.

    Minimal example from Unity docs playable examples:
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Playables;
    3. using UnityEngine.Animations;
    4.  
    5. [RequireComponent(typeof(Animator))]
    6. public class PlayAnimationUtilitiesSample : MonoBehaviour
    7. {
    8.     public AnimationClip clip;
    9.  
    10.     private PlayableGraph playableGraph;
    11.     private AnimationClipPlayable playable;
    12.  
    13.     void Start()
    14.     {
    15.         playable = AnimationPlayableUtilities.PlayClip(GetComponent<Animator>(), clip, out playableGraph);
    16.     }
    17.  
    18.     void OnDisable()
    19.     {
    20.         playableGraph.Destroy();
    21.     }
    22. }
    With the above example, both the PlayableGraph and and the AnimationClipPlayable for the clip will keep on playing indefinitely.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    29,725
    The PlayableGraph has an .isDone and an .isPlaying property... are those possibly of use?

    Disclaimer: I haven't futzed with this stuff yet myself.
     
  3. attk0

    attk0

    Joined:
    Apr 16, 2016
    Posts:
    8
    Unfortunately they aren't. Regardless of if the animation clip has ended or not:
    • PlayableGraph.IsDone() returns false
    • PlayableGraph.IsPlaying() return true
    • AnimationClipPlayable.IsDone() returns false
    • AnimationClipPlayable.GetPlayState() returns PlayState.Playing
    Probably related to this issue, AnimationClipPlayable.GetDuration() returns double max value. Doing AnimationClipPlayable.GetAnimationClip().length returns the actual clip length in seconds. It seems to me as if AnimationClipPlayable are just set up to run indefinitely regardless of the actual animation clip's length. I just don't understand why.

    It's worth noting that the animation clips themselves don't have the "Loop Time" option enabled.
     
  4. rpz

    rpz

    Joined:
    Jul 16, 2020
    Posts:
    1
    bump
     
  5. Wappenull

    Wappenull

    Joined:
    Oct 29, 2013
    Posts:
    42
    This API is a mess, at the time of writing (2022.1.15) the IsDone is still broken like that as OP written.
    Then the way to check if clip has ended is perhaps from this thread
    PlayableGraph: Play simple animation clip, how to find out if its done playing

    To sum it up, suppose you have
    AnimationClipPlayable playable; // like in OP's case

    After playing the clip by any mean (AnimationPlayableUtilities.PlayClip or connect the pin manually)
    You check for:

    if( playable.GetTime( ) > playable.GetAnimationClip( ).length )


    Not sure if this covers the speed adjustment, reader have to check by yourself.
    That IsDone function is surely beginner-bait, me included. o<-<
    Why not making function work as its name intended is beyond me...