The most optimal way to Set Binding reliably?

So I’m trying to set a track to bind to a component during runtime. I expected the track to always be the second track in the GetOutput arrays

playableDirector.SetGenericBinding(currentTimeline.GetOutputTrack(1), this);

But this does not always work. For some reasons, the track is sometime at position 0, sometime at 1. So turn out, there is a Marker track that sometimes appear in the outputs array, even though my timelines do not have any markers in that track.
To reproduce this, I find out that if I add a marker to the Marker track, and then delete the marker, that timeline will have that Marker track added at position 0 in outputs array.

So my method is prone to error. Is there any way to set binding correctly without having to iterate through every track to get the correct one? I’m trying to find the most optimal way

Before calling SetGenericBinding, Make sure the marker track exists using CreateMarkerTrack() - it will only create it if it doesn’t exist. The marker track always is at index 0 when it exists, which will make the index of all other tracks consistent.

1 Like