Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Adding Timeline clips through code (with picture)

Discussion in 'Timeline' started by Vezmo, Aug 4, 2017.

  1. Vezmo

    Vezmo

    Joined:
    Aug 4, 2017
    Posts:
    6
    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.

    upload_2017-8-4_12-3-16.png

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

    Thanks a lot!
     

    Attached Files:

  2. julienb

    julienb

    Unity Technologies

    Joined:
    Sep 9, 2016
    Posts:
    177
    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.
     
    Vezmo likes this.
  3. Vezmo

    Vezmo

    Joined:
    Aug 4, 2017
    Posts:
    6
    Awwweeeeeesoooommmme! Thanks man! Have a good week-end!
     
    julienb likes this.
  4. JerrodStorm

    JerrodStorm

    Joined:
    Dec 13, 2018
    Posts:
    4
    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.
     
  5. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    542
    Not easily, but we are currently working on Timeline edition events for our own purposes, so we will keep this in mind.