Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We’re making changes to the Unity Runtime Fee pricing policy that we announced on September 12th. Access our latest thread for more information!
    Dismiss Notice
  3. Dismiss Notice

Question Is it possible to build timeline at runtime?

Discussion in 'Timeline' started by Gunner22, Dec 28, 2021.

  1. Gunner22


    Jan 15, 2020
    I want to create custom timeline based on data I get at runtime so I cant really use prebuild playable. Basically create timeline with track witch length can be set at runtime. It would mostly use activation tracks.
  2. ST_ProductVIz


    Nov 29, 2017
    I would also be very interested in this, I have been trying it for days now!
  3. Gunner22


    Jan 15, 2020
    In the end I scraped the timeline completely because, as I said I mostly needed activation track functionality. What I ended up doing was: I created simple coroutine that turns objects of and on and places them one after another. Every object has length that represents how long it is active and delay parameter that tells the coroutine how log it should wait until it activates another object. I don't know if this is helpful in your case but that is how I resolve it hope it helps.
  4. EmeralLotus


    Aug 10, 2012
    Has anyone found an answer to this?
  5. Invertex


    Nov 7, 2013
    Timelines are basically just Playables on a graph. You can modify or construct that graph how you want at runtime using the Playables API.

    For example, if you get your PlayableDirector component from the object, then you can get access to the Timeline of it by
    TimelineAsset timeline = playableDirector.playableAsset as TimelineAsset;

    Now you can modify the Timeline however you want, such as calling timeline.CreateTrack() or DeleteTrack(). You can get the tracks currently on it with
    var tracks = timeline.GetOutputTracks() as List<TrackAsset>;
    (and GetRootTracks() to include tracks that don't have a target assignment) and iterate through to find Sequences tracks for example to then get sub-timelines (sequences).

    To modify timings, when you have reference to a
    , you can call `trackAsset.GetClips()` to get the clips of that track on the timeline. And from there, clips have properties such as
    which is where on the track the clip should start, and
    , which will give you the end point of the clip by doing
    clip.clipIn + clip.duration
    . These properties can be set to customize it how you want.

    Some tracks have bindings for what they operate on, in which case you can set that by doing
    playableDirector.SetGenericBinding(trackReference, objectToAssign)

    So from here you should get a sense of what to do to construct Timelines at runtime.
    Last edited: Feb 19, 2023
    luispedrofonseca likes this.