Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Timeline Notifications aren't sent in PlayableDirector Manual Mode

Discussion in 'Timeline' started by Kleptine, Jul 16, 2019.

  1. Kleptine

    Kleptine

    Joined:
    Dec 23, 2013
    Posts:
    19
    I'm using the following script to step my Timeline in alignment with physics (so that physics can nicely be affected by animations).
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Playables;
    3.  
    4. /// <summary>
    5. /// Simply steps a <see cref="PlayableDirector"/> once every FixedUpdate, rather than on the display frame, which is the default.
    6. /// </summary>
    7. [RequireComponent(typeof(PlayableDirector))]
    8. public class FixedUpdatePlayableDirector : MonoBehaviour
    9. {
    10.     private void FixedUpdate()
    11.     {
    12.         PlayableDirector playableDirector = GetComponent<PlayableDirector>();
    13.         if (playableDirector != null)
    14.         {
    15.             playableDirector.playableGraph.Evaluate(Time.fixedDeltaTime);
    16.         }
    17.     }
    18. }

    This does update the animation, but doesn't send any signals. The Unity blog post also mentions that Signals/Notifys aren't set when using Evaluate.

    Is there a way to manually send signals to workaround this? Or can an API be added that properly sends notifies when calling Evaluate (ie. a boolean in that function?).
     
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    909
    Unfortunately there is no way to do this right now. The notification playable that sends the trigger explicitly ignores Evaluate calls.

    It sounds like the solution you want is really a FixedUpdate timeline update.
     
  3. Kleptine

    Kleptine

    Joined:
    Dec 23, 2013
    Posts:
    19
    Thanks for the information. Yes, a FixedUpdate option would be fantastic, although the better solution is just a specialized method for manually stepping an PlayableGraph that doesn't conflict with scrubbing. Seems like notifications are disabled to avoid scrubbing notifies (makes sense), but scrubbing should just use a different flag.

    I've worked around all of this by just disabling the check in the TimeNotificationBehaviour (after pulling timeline into a custom package):

    Code (CSharp):
    1. ...
    2.         /// <summary>
    3.         /// This method is called during the PrepareFrame phase of the PlayableGraph.
    4.         /// </summary>
    5.         /// <remarks>
    6.         /// Called once before processing starts.
    7.         /// </remarks>
    8.         /// <param name="playable">The reference to the playable associated with this PlayableBehaviour.</param>
    9.         /// <param name="info">Playable context information such as weight, evaluationType, and so on.</param>
    10.         public override void PrepareFrame(Playable playable, FrameData info)
    11.         {
    12.             // Never trigger on scrub
    13.             // ASG: Only check for scrubbing when in the editor. This is technically incorrect, as you can scrub at playtime,
    14.             // but this is a workaround to allow a manually stepped timeline in FixedUpdate to send notifications of markers.
    15.             if (!Application.isPlaying && info.evaluationType == FrameData.EvaluationType.Evaluate)
    16.             {
    17.                 return;
    18.             }
    19.  
    20.             SyncDurationWithExternalSource(playable);
    21. ...
    It obviously going to break if I try scrubbing in PlayMode, but seems to work fine for my purposes? I now manually step the timeline in FixedUpdate and notifies are sent as expected.
     
  4. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    909
    Spot on. As long as you aren't using AudioTracks that should work just fine.

    Manually evaluating the graph is considered a 'scrub', but having a way to advance the graph as a 'playback' is definitely needed.
     
  5. Kleptine

    Kleptine

    Joined:
    Dec 23, 2013
    Posts:
    19
    What are the complexities / consequences if we end up using AudioTracks? We haven't yet, but just curious.

    Is the audio system a bit more complex because it needs to inject audio events into the audio system (which has its own time, etc)?
     
  6. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    909
    Audio doesn't play back on an Evaluate call. The audio system is more complicated because it is always scheduled against the DSP clock, and an evaluate call doesn't guarantee the timeline is actually playing. Evaluate is great for discrete systems like Animation, but complex for continuous systems.

    A timeline playing on the game clock can have longer audio clips 'drift' for that reason, and we included the DSP clock on playable director in the cases where audio tracks need to sync perfectly (i.e. make everything else match the audio).
     
  7. Kleptine

    Kleptine

    Joined:
    Dec 23, 2013
    Posts:
    19
    Gotcha, makes sense. Thanks for the info and help!

    (You folks should consider moving Timeline open source like InputSystem and SRP! :))