Search Unity

Unity Timeline script control

Discussion in 'Animation' started by Lu_Atar, May 6, 2019.

  1. Lu_Atar

    Lu_Atar

    Joined:
    May 16, 2017
    Posts:
    8
    Is there a way to play the Unity Timeline at a certain frame/time/normalized progress via script?

    Example scenario:

    I have a castle which is fully animated by different animation, e.g. walking people, moving vehicles, torches etc. All the animations are put inside a Unity timeline. The user can pan with a camera around in the castle and has access to a custom timeline UI on the screen. This UI timeline plays/pauses the animations in the castle, and can even skip to certain frames in the UI timeline, to play the animations from different key times. I want this UI timeline to be linked to the Unity Timeline via script. E.g. timeline.PlayAt(0.2) valuerange 0-1 where 0 is the beginning, 1 is the end of all the animations. Is this possible? Thanks in advance for any advice, I have looked around on the net, and no simple solution, this is making me nuts.
     
    SobhanNili likes this.
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    I haven't used Timeline itself, but I have used the underlying Playables API and this sort of thing is definitely possible there.

    I believe the PlayableDirector class is involved somewhere and it looks like it has properties for this sort of thing.
     
  3. Lu_Atar

    Lu_Atar

    Joined:
    May 16, 2017
    Posts:
    8
    Yes, the PlayableDirecdtor is the answer. Received an explanation from seant_unity. The progress can be set via script by changing the time property in PlayableDirector:

    playableDirector.Play();
    playableDirector.time = playableDirector.duration * normalizedTime;

    Thanks for all the answers, really appreciate it!
     
    cherstvyd and SobhanNili like this.