Search Unity

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:
    270
    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.
  4. xomak96

    xomak96

    Joined:
    Jul 13, 2021
    Posts:
    2
  5. deltaexecutor4

    deltaexecutor4

    Joined:
    Mar 12, 2024
    Posts:
    1
    Here are some tips and tricks for using PlayableDirector in Manual update mode:

    General Workflow:

    1. Set Update Mode: In the PlayableDirector component inspector, set the "Director Update Mode" to "Manual".
    2. Advancement: In your game loop (like Update function), call playableDirector.DeferredEvaluate() to progress the timeline.
    3. Precise Control (Optional): Use playableDirector.time += deltaTime to advance the timeline by a specific amount based on your deltaTime variable (usually Time.unscaledDeltaTime).
     
  6. Nathalie063

    Nathalie063

    Joined:
    Mar 29, 2024
    Posts:
    1
    Certainly! The PlayableDirector component in Unity is a powerful tool for controlling and sequencing animations and other timeline-based actions. When using it in Manual update mode, you have finer control over when the timeline updates occur, which can be useful for certain scenarios. Here are some tips and tricks for using PlayableDirector in Manual update mode:

    1. Understand the Update Mode: In Manual update mode, the PlayableDirector will not automatically update its timeline. Instead, you need to manually trigger updates using script. This can be useful when you need precise control over when timeline updates occur.

    2. Use FixedUpdate or LateUpdate for Updating: Since Manual update mode requires manual updating, you typically want to call PlayableDirector.Evaluate() in FixedUpdate() or LateUpdate() to ensure consistent timing with physics or other game systems.
      Code (CSharp):
      1. void FixedUpdate()
      2. {
      3.     // Update the timeline in FixedUpdate
      4.     myPlayableDirector.Evaluate();
      5. }
      6.  
    3. Control Timeline Playback: You can control the playback of the timeline by setting the time property of the PlayableDirector. This allows you to start, pause, resume, or rewind the timeline as needed.


      Code (CSharp):
      1. // Start the timeline
      2. myPlayableDirector.time = 0f;
      3. myPlayableDirector.Play();
      4.  
      5. // Pause the timeline
      6. myPlayableDirector.Pause();
      7.  
      8. // Resume the timeline
      9. myPlayableDirector.Resume();
      10.  
      11. // Rewind the timeline
      12. myPlayableDirector.time = 0f;
      13.  
    4. Monitor Timeline State: You can monitor the state of the timeline using properties like isPlaying, isPaused, and state. This can be useful for triggering events or performing actions based on the timeline's current state.
    Code (CSharp):
    1. if (myPlayableDirector.isPlaying)
    2. {
    3.     // Timeline is currently playing
    4. }
    5.  
    6. if (myPlayableDirector.state == PlayState.Paused)
    7. {
    8.     // Timeline is currently paused
    9. }
    10.  
    1. Optimize Performance: Since Manual update mode requires scripting to update the timeline, be mindful of performance, especially if you have multiple PlayableDirector instances being updated frequently. Consider optimizing your update logic to minimize performance overhead.
    By following these tips and tricks, you can effectively use PlayableDirector in Manual update mode to create complex and dynamic sequences in your Unity projects.