Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug Playable.Pause() not work

Discussion in 'Animation' started by SolarianZ, Sep 2, 2022.

  1. SolarianZ

    SolarianZ

    Joined:
    Jun 13, 2017
    Posts:
    229
    Hello, I'm trying to play an animation clip using Playable and make it paused at the beginning, but the Pause method didn't work. Is it a bug? Or I need call some else method?

    Here's the code:
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Animations;
    3. using UnityEngine.Playables;
    4.  
    5. [RequireComponent(typeof(Animator))]
    6. public class PlayableTest : MonoBehaviour
    7. {
    8.     [SerializeField]
    9.     private AnimationClip _clip;
    10.  
    11.     private Animator _animator;
    12.     private PlayableGraph _graph;
    13.  
    14.     private void Start()
    15.     {
    16.         _animator = GetComponent<Animator>();
    17.         _graph = PlayableGraph.Create(nameof(PlayableTest));
    18.  
    19.         var clipPlayable = AnimationClipPlayable.Create(_graph, _clip);
    20.         clipPlayable.Pause(); // NOT WORK!!
    21.  
    22.         var animOutput = AnimationPlayableOutput.Create(_graph, "Test Pause", _animator);
    23.         animOutput.SetSourcePlayable(clipPlayable);
    24.  
    25.         _graph.Play();
    26.     }
    27.  
    28.     private void OnDestroy()
    29.     {
    30.         _graph.Destroy();
    31.     }
    32. }
     
  2. SolarianZ

    SolarianZ

    Joined:
    Jun 13, 2017
    Posts:
    229
    I found that is because Unity will reset animation Playables to Playing state When the following events occur:
    • When binding a Playable to AnimationPlayableOutput(call 'SetSourcePlayable' method).
    • When Animator's renderer become visible or invisible and its cullingMode is not 'AlwaysAnimate'.
     
  3. SolarianZ

    SolarianZ

    Joined:
    Jun 13, 2017
    Posts:
    229
    In this case, whenever I set a Playable's play state to Paused, it cloud be reset to Playing by OnBecomeVisible/OnBecomeInvisible event. Is this reasonable?
     
  4. SolarianZ

    SolarianZ

    Joined:
    Jun 13, 2017
    Posts:
    229