How to animate an instantiated object in the timeline/director

Howdy!

I’m having a problem using the Timeline to animate an instantiated object and I can’t find the answer anywhere. The issues is this:

I want to animate my player/npc prefab instantiated during runtime. But the timeline seems to only work with objects, or animators that are in the scene. So what is the best solution for this?

I tried setting the animator via director binding but it asks me for the track name and object, which I was not able to access or set and the information on that is kinda hard to understand.

So I am stuck with this issue. I would really appreciate any help on this issue!!

Thank you!

PlayableDirector.SetGenericBinding(AnimationTrack, Animator) is the correct method to set a track binding for an animation . To find a reference to the track, you can use timelineAsset.GetOutputTracks() and search the tracks, and use the one with the correct name.

var timelineAsset = playableDirector.playableDirector as TimelineAsset;
var track = timelineAsset.GetOutputTracks().FirstOrDefault(t=>t.name == "MyTrackName");

playableDirector.SetGenericBinding(track, myAnimator);

The name can be set in the inspector when a track is selected in the Timeline Editor.

Hi @seant_unity

Thank you so much for replying, I’m trying to use the code but I’m not very good at coding.

What does this do?.. “FirstOrDefault(t=>t.name == “MyTrackName”);”

because it’s not working. I can get as far as timelineAsset.GetOutputTracks() but I don’t get the rest. Can you help me understand this? thank you!