Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Changing time from playable director in control track

Discussion in 'Timeline' started by TristanLambert, Jan 30, 2021.

  1. TristanLambert

    TristanLambert

    Joined:
    Nov 28, 2017
    Posts:
    1
    I have created a custom timeline playable which changes the time of its director like so:

    Code (CSharp):
    1. [Serializable]
    2. public class TimeJumpBehaviour : PlayableBehaviour
    3. {
    4.     public double newTime = double.NaN;
    5.  
    6.     private PlayableDirector director = null;
    7.  
    8.     public override void OnPlayableCreate (Playable playable)
    9.     {
    10.         // Get the director here, because the graph is not valid when paused.
    11.         director = playable.GetGraph().GetResolver() as PlayableDirector;
    12.     }
    13.  
    14.     public override void PrepareFrame(Playable playable, FrameData info)
    15.     {
    16.         if (!Application.isPlaying)
    17.             return;
    18.  
    19.         // Some code left out for brevity
    20.  
    21.         director.time = newTime;
    22.     }
    23. }
    Now this works fine when used in a "top level" playable director. However, when the playable director (A) that contains this clip is being controlled through a control track of another playable director (B), the director variable will get set to playable director A.

    Setting the time on it has no effect in that case, presumably because it's being controlled by playable director B.

    How can I find the "top level" playable director from code so that changing the time has the desired effect?
    I tried using GetRootPlayable(), but that doesn't seem to make a difference in this case.

    Thanks in advance!
     
  2. andysaia

    andysaia

    Joined:
    Nov 2, 2015
    Posts:
    21
    Did you ever find a solution to this?