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. Dismiss Notice

Question How to check if a TimelineClip has ended?

Discussion in 'Timeline' started by Pietrofonix, Jan 27, 2023.

  1. Pietrofonix


    Aug 1, 2020
    Hi guys, I'd like to know how to check if a TimelineClip has ended inside a PlayableDirector. What I want to achieve is to restart the PlayableDirector from the beginning of a TimelineClip when that clip has ended. Now I'm trying with this simple if statement but it doesn't work:

    Code (CSharp):
    2. public override TaskStatus OnUpdate()
    3. {
    4.       if (Director.time >= m_timelineClip.end)
    5.       {
    6.           Director.time = m_timelineClip.start;
    7.       }
    8.       return TaskStatus.Running;
    9. }
    The problem is that it doesn't enter in the If statement and I don't know how check in another way. I set the PlayableDirector WrapMode in every mode but nothing. Thank you for your support.
  2. tonytopper


    Jun 25, 2018
    I was really surprised this isn't easier to do myself. For me director.time returns a value between 0 and 1. I have WrapMode of None.

    I started playing around with checking the state and the time to figure this out.

    Code (CSharp):
    1. public override void Update()
    2. {
    3.           if (director.state == PlayState.Playing)
    4.           {
    5.                 Debug.Log($"Director time: {director.time} {director.state}");
    6.           }
    7.           else if (director.state == PlayState.Paused && Mathf.Approximately((float)director.time, 1))
    8.           {
    9.                 director.Stop();
    10.                 Debug.Log($"Director time: {director.time} {director.state}");
    11.           }
    12. }
    Playables sounds really cool and powerful but I don't know why Unity would expect it to get a lot of use in its current state. Seems like PlayableDirector needs a completed event or something like that to me.