Search Unity

Access clip timings

Discussion in 'Timeline' started by attar033, Aug 21, 2017.

  1. attar033

    attar033

    Joined:
    Nov 21, 2012
    Posts:
    9
    Following the examples found in the timeline playable Wizard, I am using the new Timeline to create my own custom track which drives a monobehaviour script through a playablebehaviour.
    I am adding several clips to the track and I need to access at runtime the 'start' and 'end' times of each playable inside the track. its easy to get the duration of the playable through the playableBehaviour but I really need to access the clip timings.
    Your help is very much appreciated.
     
  2. attar033

    attar033

    Joined:
    Nov 21, 2012
    Posts:
    9
    Ok, I sort of cheated my way around this but I really do think there is definitely an easier way out there in the wilderness
    What I did is to post a notification (using my own completely decoupled notification system) to send the created clip which is then captured by the respective playableBehaviour:

    Code (CSharp):
    1. [TrackColor(0.855f, 0.8623f, 0.87f)]
    2. [TrackClipType(typeof(MonitorTextAnimatorClip))]
    3. [TrackBindingType(typeof(MonitorOutput))]
    4. public class MonitorTextAnimatorTrack : TrackAsset
    5. {
    6.     public override Playable CreateTrackMixer(PlayableGraph graph, GameObject go, int inputCount)
    7.     {
    8.         return ScriptPlayable<MonitorTextAnimatorMixerBehaviour>.Create (graph, inputCount);
    9.     }
    10.  
    11.     protected override Playable CreatePlayable (PlayableGraph graph, GameObject go, TimelineClip clip)
    12.     {
    13.         var p = base.CreatePlayable (graph, go, clip);
    14.         NotificationCenter.Post (NotificationType.ClipCreated, new object[]{ p, clip });
    15.         return p;
    16.     }
    17. }


    Code (CSharp):
    1. [Serializable]
    2. public class MonitorTextAnimatorBehaviour : PlayableBehaviour
    3. {
    4.     private Playable playable;
    5.     private TimelineClip clip;
    6.     public override void OnPlayableCreate (Playable playable)
    7.     {
    8.         this.playable = playable;
    9.         NotificationCenter.AddListener(OnClipCreated,NotificationType.ClipCreated);
    10.         base.OnPlayableCreate (playable);
    11.     }
    12.  
    13.     public override void OnPlayableDestroy (Playable playable)
    14.     {
    15.         NotificationCenter.RemoveListener(OnClipCreated,NotificationType.ClipCreated);
    16.         base.OnPlayableDestroy (playable);
    17.     }
    18.  
    19.     private void OnClipCreated(Notification note)
    20.     {
    21.         var data = (object[])note.data;
    22.         var clipOwner = (Playable)data [0];
    23.         if (clipOwner.GetHashCode() == playable.GetHashCode()) {
    24.             clip = (TimelineClip)data [1];
    25.             Debug.Log (clip.start + "   " + clip.end);
    26.         }
    27.     }
    28. }

    I know, I know, its uglier then an ugly duckling that decided to let itself go. I really hope someone comes up with the right answer (I know you're definitely somewhere out there, go ahead, start writing that delicious answer). :p:p:p:p:p:p
     
  3. WikkidEdd1

    WikkidEdd1

    Joined:
    Nov 17, 2015
    Posts:
    10
    You can cut out your notification system by setting the clip directly on the behaviour like this:

    Code (CSharp):
    1.     protected override Playable CreatePlayable (PlayableGraph graph, GameObject go, TimelineClip clip)
    2.     {
    3.         ScriptPlayable<MonitorTextAnimatorBehaviour > playable = (ScriptPlayable<MonitorTextAnimatorBehaviour >) base.CreatePlayable(graph, go, clip);
    4.         playable.GetBehaviour().clip = clip;
    5.         return playable;
    6.     }
     
    thierry_unity likes this.
  4. attar033

    attar033

    Joined:
    Nov 21, 2012
    Posts:
    9
    Thanks a lot, that is absolutely great!!!
     
  5. CL_HG

    CL_HG

    Joined:
    Mar 5, 2014
    Posts:
    6
    Hi there,
    I know that this thread is quite old now, but Unity version were you using for this?
    I'm also trying to get the TimelineClip information of a clip but for some reason CreatePlayable(PlayableGraph graph, GameObject go, TimelineClip clip) is internal, not virtual in Unity 2018.1.3 so I'm not able to override it and assign the clip myself.