Programmatically Creating a Timeline

You can do this via creating TimelineAssets, TrackAssets, and finally TimelineClips via TimelineAsset’s create API.

var tracks = timelineToUpdate.GetRootTracks();
    DialogueTrack targetTrack = null;

    foreach (TrackAsset track in tracks) {
        Debug.Log("Currently printing track " +;

        if ( == "Dialogue") {
            Debug.Log("Removing existing dialogue track");
            foreach (TimelineClip clip in track.GetClips()) {
            targetTrack = (DialogueTrack)track;

    if (!targetTrack) {
        targetTrack = timelineToUpdate.CreateTrack<DialogueTrack>(null, "Dialogue");
// this section of code creates a new clip on the timeline track
// given some base parameters.
TimelineClip clip = targetTrack.CreateClip<DialogueClip>();
DialogueClip dialogueClip = (DialogueClip)clip.asset;

clip.start = timestamp;
clip.duration = action == "hide" ? 1f : 5f;

// these are public variables on the Behavior attached to the Clip.
dialogueClip.template.character = character;
dialogueClip.template.shouldHideDialogueBox = action == "hide" ? true : false;
dialogueClip.template.dialogueText = dialogueText;
dialogueClip.template.x = x;
dialogueClip.template.y = y;

Note that when you programmatically create a timeline like this, the timeline UI in the editor won’t update until you toggle between different timelines! Be sure to refresh it to avoid looking at invalid clips.



Getting a specific type of a clip from a TimelineClip: