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

How To correctly manually Update the PlayableDirector

Discussion in 'Timeline' started by Suppenhans24, Aug 10, 2022.

  1. Suppenhans24

    Suppenhans24

    Joined:
    Jun 13, 2022
    Posts:
    4
    I'm using this method of updating my Playable director manually:

    Code (CSharp):
    1.  
    2. [ExecuteAlways]
    3. public class DirectorUpdater : MonoBehaviour
    4. {
    5.    public void OnEnable()
    6.    {
    7.        UnityEditor.EditorApplication.update += AdvanceDirector;
    8.    }
    9.  
    10.    public void OnDisable()
    11.    {
    12.        UnityEditor.EditorApplication.update -= AdvanceDirector;
    13.    }
    14.  
    15.    public void AdvanceDirector()
    16.    {
    17.        PlayableDirector playableDirector = GetComponent<PlayableDirector>();
    18.  
    19.        if (playableDirector.timeUpdateMode == DirectorUpdateMode.Manual &&
    20.            playableDirector.state == PlayState.Playing)
    21.        {
    22.            playableDirector.playableGraph.Evaluate(0.05);
    23.  
    24.            if (playableDirector.time >= playableDirector.duration)
    25.            {
    26.                playableDirector.Stop();
    27.            }
    28.        }
    29.    }
    30.  
    31.    public void LateUpdate()
    32.    {
    33.        AdvanceDirector();
    34.    }
    35.  

    It seems to almost work as intended, the only thing i noticed that is still off is, that Markers don't trigger their notifications reliably anymore in EditMode. (As soon as i switch back to GameTime Update, the notifications trigger as expected)

    Code (CSharp):
    1. public class MyMarker : Marker, INotification, INotificationOptionProvider
    2. {
    3.     public PropertyName id => "MyMarker";
    4.  
    5.     NotificationFlags INotificationOptionProvider.flags => NotificationFlags.TriggerInEditMode;
    6. }
    7.  
    8. public class MyNotificationReceiver : MonoBehaviour, INotificationReceiver
    9. {
    10.     public void OnNotify(Playable origin, INotification notification, object context)
    11.     {
    12.         Debug.LogWarning("Triggered Marker");
    13.     }
    14. }
    15.  
    Is this a bug i should report, or is my manual update approach flawed?
     
  2. Suppenhans24

    Suppenhans24

    Joined:
    Jun 13, 2022
    Posts:
    4
    I just found this, which more or less explains the problem