Search Unity

Setting `PlayableDirector.time` to `PlayableDirector.duration` when the timeline is done bug?

Discussion in 'Cinemachine' started by _Ayyya, Jul 28, 2017.

  1. _Ayyya

    _Ayyya

    Joined:
    Jul 28, 2017
    Posts:
    8
    I have a timeline with a Cinemachine track on it that does a simple blend from any virtual camera to a specific virtual camera with a duration of 2.5 seconds. The wrap mode for the Playable Director is set to `Hold`.

    What I am trying to do is play the timeline to blend from one camera to another but allow the blend to be interrupted by the user's press of a button. So, if the player pushes a button, I want the timeline to jump to the last frame of the Cinemachine track. I do this by setting `PlayableDirector.time` = `PlayableDirector.duration`.

    There seem to be 2 issues:
    (1) If I wait till the timeline is completed playing and then set the `PlayableDirector.time` to `PlayableDirector.duration`, the Cinemachine clip jumps to a position past the last frame of the clip. Is this a bug?

    (2) As a workaround to this issue, I tried only setting `PlayableDirector.time` = `PlayableDirector.duration` if `PlayableDirector.state == `PlayState.Playing` is true. However, even after the clip is done playing, `PlayableDirector.state == `PlayState.Playing` is still true. Could this be because the wrap mode is set to `Hold`? Is it possible to add a state called `PlayState.Holding` in order to differentiate between the 2 states?

    Thanks
     
  2. sebsmax

    sebsmax

    Joined:
    Sep 8, 2015
    Posts:
    118
    If you need to do an action at the end of a Timeline, the best solution is to do a Coroutine, in the example code provided by unity they do that.

    Code (CSharp):
    1.  
    2.        
    3.  
    4.        public PlayableDirector timeline;
    5.        public Coroutine waitForTimelineToFinish;
    6.  
    7.        public void StartTimeline() {      
    8.              if(timeline==null) return;
    9.              timeline.time = 0;
    10.              timeline.Play();
    11.              if(waitForTimelineToFinish != null) StopCoroutine(waitForTimelineToFinish);
    12.              waitForTimelineToFinish = StartCoroutine(WaitForTimelineToFinish());
    13.        }
    14.    
    15.         IEnumerator WaitForTimelineToFinish()
    16.         {
    17.             float timelineDuration = (float)timeline.duration;
    18.             yield return new WaitForSeconds(timelineDuration);
    19.             //Callback to invoke
    20.         }
     
  3. _Ayyya

    _Ayyya

    Joined:
    Jul 28, 2017
    Posts:
    8
    Yes, I am doing that. However, if I set the `PlayableDirector.time` = `PlayableDirector.duration` after waiting for the timeline to complete, then the timeline jumps to a frame past the end of the clip. If I set the `PlayableDirector.time` = `PlayableDirector.duration` before the timeline has completed, this doesn't happen. The timeline is set to the last frame of the clip. I was wondering if that was a bug or not?
     
  4. FURKANKAHVECI

    FURKANKAHVECI

    Joined:
    May 12, 2013
    Posts:
    27
    Code (CSharp):
    1.     public PlayableDirector t1;
    2.  
    3.     void Start()
    4.     {
    5.     t1.Evaluate();
    6.     t1.time=t1.duration;
    7.  
    8.    
    9.     }
    I think you should evaluate your timeline director. (I know question post in 2017)
     
    BitGamey likes this.