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

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.Playingis 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

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.

       public PlayableDirector timeline;
       public Coroutine waitForTimelineToFinish;

       public void StartTimeline() {      
             if(timeline==null) return; 
             timeline.time = 0;
             timeline.Play();
             if(waitForTimelineToFinish != null) StopCoroutine(waitForTimelineToFinish);
             waitForTimelineToFinish = StartCoroutine(WaitForTimelineToFinish());
       }
   
        IEnumerator WaitForTimelineToFinish()
        {
            float timelineDuration = (float)timeline.duration;
            yield return new WaitForSeconds(timelineDuration);
            //Callback to invoke
        }

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?

    public PlayableDirector t1;

    void Start()
    {
    t1.Evaluate();
    t1.time=t1.duration;

   
    }

I think you should evaluate your timeline director. (I know question post in 2017)

1 Like