Adding Timeline clips through code (with picture)

I would like to know if it’s possible to add timeline clips through code (with an Editor Button).

For example, I have a .txt file that contains a set number of lines. With an Editor button, I currently read the text file and put each line into a List of strings.

What I would like to do is: For each line of text in my List, add a timeline clip (here it would be a dialogue box clip). Currently, the only way to add a clip is to right click on the track and select Add.

Is there a way to call this through code with an Editor button?

Thanks a lot!


TrackAsset.CreateDefaultClip is what you need. It will create a new clip with a default duration on the track. You can use the return value to set the properties you want on the new clip.

1 Like

Awwweeeeeesoooommmme! Thanks man! Have a good week-end!

1 Like

I know this is an old thread, but I’m wondering if there’s a way to approach this from the other end. I’m wondering if there’s some kind of callback I can override on the created TimelineClip to set up default keyframes, etc.

Not easily, but we are currently working on Timeline edition events for our own purposes, so we will keep this in mind.