- Home /
How to get a track from a timeline from a playable director?
I want to insert a new clip into a track after pressing a button during runtime so I don't have to manually key in the start frame of every clip from a notepad.
Problem is, I can't find a method for getting the reference to the track to add the clip in. Drag and drop into a public TrackAsset property doesn't work, and I tried this mthod of TimelineAsset.GetOutputTracks() but trying to get the TimelineAsset from PlayableDirector property (PlayableDirector.playableAsset) gets the timeline as PlayableAsset type instead, so I can't use the method.
I also can't create a new track asset from dragging and dropping the interested track into the assets folder.
Is there a way to get a track from a timeline from a playble director?
Version is 2020.3.17f1
Answer by pepipe · Nov 02, 2021 at 05:54 PM
@Chocfudges You can cast the timeline playableAsset to TimelineAsset (TimelineAsset is also a PlayableAsset):
var timelineAsset = ((TimelineAsset)timeline.playableAsset)
And like you said with the TimelineAsset you can call the GetOutputTracks to get the timeline playable tracks list (Group tracks and Sub tracks are not included in this list).
You can use Linq to get the track by using the track's name, something like this:
var trackAssets = ((TimelineAsset)timeline.playableAsset).GetOutputTracks().Where(e => e.name.Equals("trackName"));
Your answer
Follow this Question
Related Questions
How to get the Track and the Clip of a Timeline? 1 Answer
Peculiar Bleed-through of Exposed References on different Timeline Tracks 2 Answers
Timelines and DollyTracks - Set Frame and Pause 2 Answers
How to reference a TrackAsset or PlayableAsset 2 Answers
How to Set the Animator for a Timeline Animation Track through script? 1 Answer