Search Unity

Accessing a track's binding type via script

Discussion in 'Timeline' started by AdamBL, Dec 10, 2018.

  1. AdamBL

    AdamBL

    Joined:
    Oct 27, 2016
    Posts:
    29
    Hey all, been banging my head against this one for a while and was hoping someone can help.

    What I want to do is this: At runtime, get a list of all of a timeline's tracks. Then, iterate through that list, see if the track is of a certain type (in my case, a modified version of the Time Machine track found here), and if it is that type, add the start time of that clip to a list.

    Right now, what I have is this:

    Code (CSharp):
    1.         TimelineAsset timelineAsset =
    2.             (TimelineAsset) activeDirector.playableAsset;
    3.         foreach (TrackAsset trackAsset in timelineAsset.GetOutputTracks()){
    4.         }
    It gets the TimelineAsset of a given PlayableDirector and then iterates through all the Tracks. My problem is how do I access the Track binding type? Or is there another way of going about this that's simpler?

    Thanks!
     
  2. julienb

    julienb

    Unity Technologies

    Joined:
    Sep 9, 2016
    Posts:
    177
    You can get access to all the tracks in a timeline with

    GetOutputTracks()


    You can then check the type of each track too see if it matches the type you want.

    Code (CSharp):
    1. var asset = activeDirector.playableAsset as TimelineAsset;
    2. if (asset != null)
    3. {
    4.     var tracks = asset.GetOutputTracks();
    5.     foreach (var track in tracks)
    6.     {
    7.         if (track is TimeMachineTrack)
    8.         {
    9.             var clips = track.GetClips();
    10.             //here you have access to all clips in a TimeMachineTrack
    11.         }
    12.     }
    13. }
     
    SADAF_AFREEN and senkal_ like this.
  3. AdamBL

    AdamBL

    Joined:
    Oct 27, 2016
    Posts:
    29
    That's awesome, thanks! I also found an alternate solution using OnGraphStart() to register each track with the manager, but this looks a lot nicer, thanks!