Search Unity

How to add a "Custom clip" dynamically from script?

Discussion in 'Timeline' started by Akitohisano, Mar 23, 2018.

  1. Akitohisano


    Sep 11, 2017
    In Timeline, when we want to add a clip dynamically we can use something like:

    var track = timeline.GetOutputTrack(trackIndex);
    var clip = track.CreateDefaultClip();
    AnimationPlayableAsset animationPlayableAsset = clip.asset as AnimationPlayableAsset;
    animationPlayableAsset.clip = animationClip;

    But, that's for the pre-defined tracks from Unity Timeline Engine. If I created a Custom Playable using the Default Playables Wizard, how are we supposed to add a clip on that custom track?

    For example, we can create a custom playable called "Dialogue" using Default Playables Wizard. And it will generate classes like "DialogueClip", "DialogueTrack" automatically. Well, adding a clip could be easily right-click on the track and "add Dialogue Clip", but how could we supposed to do this from script?
  2. seant_unity


    Unity Technologies

    Aug 25, 2015
    For the track, timeline.GetOutputTrack(trackIndex) as DialogueTrack will get you the track of a specific type.

    To create clips, track.CreateDefaultClip() should work. The TrackClipType attribute will let the track know what a default clip is for that type.

    Alternatively you can specify the clip type using the track.CreateClip<DialogueClip>().
    Akitohisano likes this.