Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

How to use TimelineAsset as ITimelineClipAsset

Discussion in 'Timeline' started by 5argon, Oct 30, 2019.

  1. 5argon


    Jun 10, 2013
    I saw a new `ILayerable` so I thought finally my ideal "audio combo" authoring would be possible. So my idea is that I want to be able to author reusable audio timings on its own, outside of any usage context.

    What I did is I created a new kind of `TimelineAsset`

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Timeline;
    4. [CreateAssetMenu]
    5. public class AudioCombo : TimelineAsset
    6. {
    7. }
    Then inside it I have my new kind of track, the same but layerable :

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Playables;
    3. using UnityEngine.Audio;
    4. using UnityEngine.Timeline;
    6. public class MultiAudioTrack : AudioTrack, ILayerable
    7. {
    8.     public Playable CreateLayerMixer(PlayableGraph graph, GameObject go, int inputCount)
    9.     {
    10.         return AudioMixerPlayable.Create(graph, inputCount,normalizeInputVolumes: false);
    11.     }
    12. }
    Now I could author and preview my "audio combo" by creating a game object that has Playable Director just for authoring, create a new AudioCombo asset and connect it to the director, then program the timeline. It seems that the requirement to reuse Unity Timeline for other purpose is that it must be a TimelineAsset.


    Something I wish it should be possible : lock a certain track type possible for creation in a derived TimelineAsset. I want to allow only AudioTrack and my MultiAudioTrack inside this AudioCombo timeline type for example. Is it possible already?

    Then, I want to use this TimelineAsset as a clip, inside other timeline. I saw that TimelineAsset is both PlayableAsset and ITimelineClipAsset, so I thought this is possible. But I can't seems to get it working. I created a new track with no behaviour at all, but first I would like to be able to place my authored TimelineAsset as a clip.

    Code (CSharp):
    1. using UnityEngine.Timeline;
    3. [TrackColor(0,0.2f,0.6f)]
    4. [TrackClipType(typeof(AudioCombo), false)]
    5. public class ComboTrack : TrackAsset
    6. {
    7. }
    But I cannot drag that New Audio Combo authored earlier as a new clip onto the track. So this renders the idea of custom TimelineAsset not so useful. Is there anything I am missing?


    I am aware I could hack it out with Control Track since it is essentially a thing that could play a timeline, but it would be very messy and not productive if I need to fallback to Control Track method, which I have to prepare a separated PlayableDirector waiting for every "sub-timeline" I want to add.
    Last edited: Oct 30, 2019
  2. seant_unity


    Unity Technologies

    Aug 25, 2015
    I love the idea of having different types of timelines. This is something that has come up here internally, and this is a great example of where it would be very useful.

    TimelineAsset is a playable asset so it can be used by the playable director, and implement ITimelineClipAsset for ControlTracks (iirc). So they aren't there to make them work with the editor, which is strictly a TimelineAsset editor.
    5argon likes this.
  3. 5argon


    Jun 10, 2013
    Without breaking too much existing code I imagined the feature could come with some constraints, it would still be very useful. For example :
    • New built-in timeline asset type SingleTrackTimelineAsset<T> : TimelineAsset where T : TrackAsset. This is a timeline that contains only a single type of track, and naturally has only one output binding slot.
    • Modify the Timeline editor to allow SingleTrackTimelineAsset<T> to be edited in addition to TimelineAsset.
    • On [CreateAssetMenu] of SingleTrackTimelineAsset<T>, it already instantiate and serialize a single track T in it automatically.
    • Modify the Timeline editor to not allow any track creation when editing SingleTrackTimelineAsset<T>. Forcing you to work with the only one given on creation. (If somehow the track doesn't exist or more than one exists via user hacking the data file, resets to single track.)
    • However T could be ILayerable and it would still preserve the single binding slot rule while allow us to have multiple (sub) tracks of the same type, making it more practical.
    • Or relax so that T is instead an output binding type instead of track type. The Timeline now allows any number of tracks to be created as long as they use the same output binding. (Not just the same type, the same instance connected to all tracks) The editor changes accordingly by removing all slots on the left side of all tracks, save for the first one.
    • New built-in track SubTimelineTrack. This allow you to drop SingleTrackTimelineAsset<T> onto it as a clip. If you drop an another SingleTrackTimelineAsset<T2> (different track type), the editor prevents dropping the asset or not depending on if T and T2 shares the same output binding type or not. (The relaxed T as an output binding type case.)
    • It's binding slot that editor draws then showed up as a type of binding that T wants, effectively just forwards the only slot from SingleTrackTimelineAsset out one level, to the slot of SubTimelineTrack.
    • Allows double clicking to go into the clip just like Control Track's clip. Except this time we don't need any new PlayableDirector "host". It's now the same graph!
    • By treating time flowing into clips in SubTimelineTrack as usual like when time came from PlayableDirector into the main timeline, everything else should still work? (Time stretching or looping the SubTimelineTrack clip should even work automatically?)
    • Extra useful if we can also drop an another instance SingleTrackTimelineAsset<T> into SingleTrackTimelineAsset<T> itself as a clip. (with recursive detection)
    It's been a long time that Timeline didn't receive any more composability feature, other than reusing clips by linking from serialized clip asset or using Control Track. : )
    Last edited: Nov 1, 2019