I followed a tutorial to create a text custom track in Unity Timeline. I want to bind the track's key to a subtitle GameObject with TextMeshProUGUI through script. Basically, I am using the method below:
playableDirector.SetGenericBinding(track, subtitle);
This is the outcome in the timeline:
This is the outcome in the timeline, if I just drag the same object:
The component is not appearing in the first picture, why?
Here is another test I did after manually referencing:
var subtitle = playableDirector.GetGenericBinding(track);
playableDirector.ClearGenericBinding(track);
playableDirector.SetGenericBinding(track, subtitle);
Debug.Log(subtitle.GetType());
I was not feeding the TextMeshProUGUI component into the method directly because I was getting an error inside the script editor. But after reading, components are considered Objects, and there wasn't a reason for it not to work, so I ran the script and it worked even though there were was a red line. I don't know why this happened, but here is the solution:
var subtitle = Subtitle.subtitle; // I referenced the component and made it static
playableDirector = GetComponent<PlayableDirector>();
timeline = playableDirector.playableAsset as TimelineAsset;
good = timeline.GetRootTrack(1);
bad = timeline.GetRootTrack(2);
var goodTracks = good.GetChildTracks() as List<TrackAsset>;
var badTracks = bad.GetChildTracks() as List<TrackAsset>;
playableDirector.SetGenericBinding(goodTracks[0], subtitle);
playableDirector.SetGenericBinding(badTracks[0], subtitle);