- Home /
How to get the Track and the Clip of a Timeline?
Hi all!
I'm trying to get a list of all the tracks and the clips time on those track from my timeline.
I've checked the web for a whole day now and found several API's: TrackAsset, GetClip().start, GetClip().duration. Playable, PlayableAsset and more... they all give me some error in visual studio.
Is there a timeline expert in the crowed? I've managed to get the playabelBinding and the sourceObject bind to that binding "track" but I can't seem to do the leap towards what's on the other side of the timeline (see pic. for reference).
Answer by seant_unity · Jun 19, 2018 at 11:19 AM
The animation track with keys (i.e. infinite track) is a special case in timeline. There is actually no timeline clip on it, just an animation clip.
You can get the duration of the track using the duration property . There is no public API for getting the attached animation clip, but if you use SerializedObject and SerializedProperty, the animation clip reference is serialized under the "m_AnimClip" property name.
Thanks this worked great, here's a snippet of code that might help others trying to get at the animation clips inside these timeline:
for(int i = 0; i < TimelineTo$$anonymous$$odify.outputTrackCount; i++)
{
TrackAsset track = TimelineTo$$anonymous$$odify.GetOutputTrack(i);
AnimationTrack animTrack = track as AnimationTrack;
if(animTrack && !animTrack.inClip$$anonymous$$ode)
{
//try to find the clip
var so = new SerializedObject(animTrack);
SerializedProperty sp = so.FindProperty("m_AnimClip");
if(sp.objectReferenceValue != null)
{
AnimationClip clip = sp.objectReferenceValue as AnimationClip;