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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Tips and tricks for using PlayableDirector in Manual update mode

Discussion in 'Timeline' started by doctorpangloss, Aug 4, 2019.

  1. doctorpangloss

    doctorpangloss

    Joined:
    Feb 20, 2013
    Posts:
    267
    The documentation on this is pretty sparse and infuriating so I'm including the completely undocumented things you need to do to actually control a PlayableDirector manually.

    The main thing you're probably missing is that you always call
    Code (CSharp):
    1. playableDirector.DeferredEvaluate()
    once per frame.

    • Set your Update Mode to Manual.
    • In an Update function, call
      Code (CSharp):
      1. playableDirector.DeferredEvaluate();
    • If you want to advance the whole director, use
      Code (CSharp):
      1. playableDirector.time += yourDeltaTime
      .
    • If you want to use the PlayableGraph object, for whatever reason, you must rebuild the graph at least once (try doing it in Start / Awake) or whenever your playable asset changes:
      Code (CSharp):
      1. playableDirector.RebuildGraph();
      2. playableDirector.playableGraph.SetTimeUpdateMode(DirectorUpdateMode.Manual);
     
  2. WendelinReich

    WendelinReich

    Joined:
    Dec 22, 2011
    Posts:
    228
    Glad you took the time to document this doctorpangloss. Is there a reason why you recommend calling DeferredEvaluate instead of Evaluate? The former doesn't seem to be compatible with the Play mode in the editor.
     
  3. Suppenhans24

    Suppenhans24

    Joined:
    Jun 13, 2022
    Posts:
    4
    I tried using the snippet

    Code (CSharp):
    1. playableDirector.time += yourDeltaTime
    2. playableDirector.Evaluate()
    and while seemingly working, it made all my FrameData.deltaTime equal to 0
    (The info that is passed to
    PlayableBehaviour.ProcessFrame()
    ).

    So instead, i used what was proposed here and used
    Code (CSharp):
    1. playableDirector.playableGraph.Evaluate(deltaTime);
    instead, which solved my issue.

    An additional thing to keep in mind is discussed here:
    Manually evaluating the graph is more like a scrub then a playback, so notifications and audiotracks are not working
     
    Last edited: Aug 11, 2022
    Hugo_WS likes this.