- Home /
Extended Timeline: Get clips from binding object
I have a custom track (TrackAsset) with a binding type that is monobehaviour script. I want to get a list of clips in that track and access that from the monobehaviour script. I know I can use GetClips() in TrackAsset. But, is there a way I can do that from the monobehaviour script. or access the track asset bound to the monobehaviour script and call GetClips() through reference.
Answer by DavidGeoffroy · Jan 14, 2021 at 01:58 PM
No, you need to know what you're looking for. The MonoBehaviour has no idea that anything is bound to it.
You need to know which PlayableDirector owns the Timeline, then you need to go through every track and ask the PlayableDirector what the object bound to that track is and compare it to your MonoBehaviour. Once you have found which track is bound to your MonoBehaviour, then you can ask the track what its clips are.
The pseudocode for a function that finds the clips associated with a monobehaviour looks something like this:
for every PlayableDirector Component in the scene
If it has a Playable asset and that PlayableAsset is a Timeline
For every Track in the Timeline
If the associated binding in the PlayableDirector is my MonoBehaviour
Add all clips from the track to the list of clips
Return the list of clips
There can be more than one track bound to a component, from more than one PlayableDirector, so depending on what you're trying to do, you may want to add more logic.
thanks a lot! This solution worked for me
foreach (var director in GameObject.FindObjectsOfType<PlayableDirector>())
{
if (director.playableAsset.GetType() == typeof(TimelineAsset))
{
var timelineAsset = director.playableAsset;
foreach (var track in timelineAsset.outputs)
{
if (($$anonymous$$yTrack) track.sourceObject)
{
var mytrack= ($$anonymous$$yTrack) track.sourceObject;
foreach (var c in mytrack.GetClips())
{
Debug.Log(c.displayName);
}
}
}
}
}