Create timeline assets through script?

Is it possible to generate a new timeline and populate it with tracks/behaviors through script?

The use-case which is driving this question is we have about 50 short timelines we are creating. They have 1 looping animation, 1 track for blinking (custom), and 1 track for lip sync data (custom extension on Rogo LipSync I put together).

It would be fantastic if we could batch process these in a script which loops through all the assets and assembles each timeline. The ability to use code/editor tooling to create these would be very powerful.

Yes, Timeline has a complete API for generating tracks clips, setting bindings etc:

etc

1 Like

Hi, is there anyway to get the TimelineClip name ( in the debug inspector this falls under Display Name ).
thanks

Hellow,
I’m trying to generate timelines through script to avoid some user interactions on the scene.
The generation is working well, the created timeline has the same look as when I create it manually, and the preview works fine, but when I hit play, all my generated tracks disappear in the timeline and nothing is played after (but the length is kept, check the screenshot : ).
Here is a part of my code :

GameObject directorGO = new GameObject("Timeline");
directorGO.AddComponent<CutsceneDirector>();
PlayableDirector director = directorGO.AddComponent<PlayableDirector>();
PlayableGraph graph = PlayableGraph.Create();

TimelineAsset timeline = new TimelineAsset();
AnimationTrack track = null;
for (int i = 0; i < clips.Count; ++i)
{
    AnimationClip clip = ImportMotion(clips[i]);
    AnimationPlayableOutput output = AnimationPlayableOutput.Create(graph, clip.name, model.GetComponent<Animator>());
    AnimationClipPlayable playable = AnimationClipPlayable.Create(graph, clip);
    output.SetSourcePlayable<AnimationPlayableOutput, AnimationClipPlayable>(playable);

    TimelineClip timelineClip = track.CreateClip(clip);
    timelineClip.duration = clip.averageDuration;
    timelineClip.displayName = clip.name;

    director.SetGenericBinding(track, model);
}

AssetDatabase.CreateAsset(timeline, timelinesFolder + "/Timeline.playable");
director.playableAsset = timeline;

Do you have any idea ? Actually I don’t understand how to use the “PlayableGraph.Create()” method, maybe this is where my problem is ?

EDIT : the only difference in the view is when I click on a Track, I don’t have “Asset Labels” displayed in the Inspector window, at the bottom.

EDIT 2 : found the solution, actually the timeline save asset must be done first, or the modifications are not saved, like if I were on Play mode

Exactly. The tracks and clips are (hidden) sub assets of the timeline asset. The timeline needs to exist in the asset database before the tracks are added.

1 Like

I do the same as you do, but I have already created a Timeline where I want to add new tracks and clips on runtime. This works great and I can also bind the tracks to the game objects to animate. The tracks are saved correctly. But the bindings are not saved. Does anyone know how to also save the bindings?

That is a bit trickier. Timeline is an asset, so changes to it will be saved, but the bindings are saved in the playable director, which as part of the scene, gets reverted when play mode is exited.

The user can do it by copying the values of the playable director in playmode, then pasting them in one in edit mode.There are some solutions to automate that out there, one of which exists in Cinemachine.

Thanks for your fast reply.
So I will have a look at SaveDuringPlay in Cinemachine, which I also use in the Timeline anyway.

Hi, I’m working on unity 2020.2
this api is no longer valid: Unity - Scripting API: TimelineAsset

I’m trying to create a new SignalTrack and add it to my existing playableGraph, but no results

Go to Package Manger window and select the Timeline and Playables package to see the link to proper docs for the package you are using. That link takes me to 2017 docs before they took the API out and made it separate…

I have related issue :- I am making a game which uses timeline sequence video every time new level loads. And for every level we are making assetbundle , now as these timeline sequences uses common animation , in each level, assetbundle for every level is including common animations in it. is there any way that common animations should not go in assetbundle as it increases the size of assetbundle.