Search Unity

how to pause and resume Timeline clips?

Discussion in 'Timeline' started by Moriarty_x, Nov 8, 2019.

?

is there an another life cycle of timeline different from unity and caused the result?

  1. the life cycle caused the mistake

    0 vote(s)
    0.0%
  2. the life cycle doesn't caused the mistake

    0 vote(s)
    0.0%
  3. not sure

    0 vote(s)
    0.0%
Multiple votes are allowed.
  1. Moriarty_x

    Moriarty_x

    Joined:
    Mar 25, 2019
    Posts:
    2
    I made a pause Function using UGUI, it works well in all projects except projects using timeline animations.
    I use timeline api for pause and resume, it can pause the graphs but when i trigger the proceed button, the next graphs( at the same clip) acts oddly, for example, in an explosion scene clip, some models should have been blown up and fallen down, but the fact is the models becomes relatively static and remain in the scene all the time, just like they are locked, untill the next timeline clip triggered, they are still there, the next timeline clip acts well.


    the following code is what i made to realize pause and resume play functions, i have wasted a whole afternoon tring to fix it, but not solve it yet. is there any resolutions?

    Code (CSharp):
    1. private PlayableDirector[] Pd = null;
    2.  
    3. void Start()
    4. {
    5.     Pd = Resources.FindObjectsOfTypeAll(typeof(PlayableDirector)) as PlayableDirector[];
    6. }
    7.  
    8. void PauseButtonFunc()
    9. {
    10.             if (currentVideoPlayer != null && currentVideoPlayer.isPlaying)
    11.             {
    12.              
    13.                 currentVideoPlayer.Pause();
    14.             }
    15.             AudioListener.pause = true;    
    16.            
    17.    
    18.             if (Pd != null)
    19.             {
    20.                 for (int i = 0; i < Pd.Length; i++)
    21.                 {
    22.                     if (Pd[i].isActiveAndEnabled)
    23.                     {
    24.                         Pd[i].Pause();
    25.                     }
    26.                 }
    27.             }
    28. }
    29.  
    30. void ProceedButtonFunc()
    31. {    
    32.             if (currentVideoPlayer!=null && !currentVideoPlayer.isPlaying)
    33.             {
    34.                 currentVideoPlayer.Play();
    35.             }
    36.             AudioListener.pause = false;
    37.             Time.timeScale = 1;
    38.  
    39.             if (Pd != null)
    40.             {
    41.                 for (int i = 0; i < Pd.Length; i++)
    42.                 {
    43.                     if (!Pd[i].isActiveAndEnabled)
    44.                     {
    45.                         Pd[i].Play();
    46.                     }
    47.                 }
    48.             }
    49. }
     
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    Try using

    Code (CSharp):
    1.  
    2. if (Pd[i].playableGraph.IsValid())
    3.     Pd[i].playableGraph.GetRootPlayable(0).SetSpeed(0); // 1 to renable
    4.  
    instead.

    Pause() can cause activations and de-activations, which I would hazard a guess to be the root cause of the problem. Where as changing the playback speed will simply freeze the objects.
     
  3. Moriarty_x

    Moriarty_x

    Joined:
    Mar 25, 2019
    Posts:
    2
    Many thanks, you've totally solved my problem!