Search Unity

Using Timeline for dialog cutscenes

Discussion in 'Timeline' started by R40ul_OSG, Apr 24, 2017.

  1. R40ul_OSG

    R40ul_OSG

    Joined:
    Sep 2, 2016
    Posts:
    43
    Hello,

    I have downloaded Timeline, and I’ve started to play around with it. What I’ve seen so far really impresses me! I would like to use it to create in-game cutscenes, and even though I’m pretty pleased with the result so far, I have a few minors issues.


    The first problem is that I would like to have dialogs in a bubble that require an input for the player to continue the cutscene. (eg. Character 1 moves to a position, then speaks. Subtitles are displayed on screen, the player is asked to tap to skip. Player taps, character 1 moves to an other position).

    - My first idea was to create a ScriptPlayable that pauses the PlayableDirector in its OnPlayStateChanged.
    It does the job, but it freezes the character in the current frame of their animation.

    - My second idea was to create a ScriptPlayable with a given duration that forces the PlayableDirector to change its time to go back to the beginning of the ScriptPlayable until the player has tapped the screen.
    It works too, but I have can have glitches in my animation as all the characters need to have an animation that loops exactly in the same timing.

    - My last idea, which I haven’t tried yet is to pause the PlayableDirector and use the animator of each character to loop an animation independently. I am not sure it will work, especially when I will transition from Timeline to « normal » animation and back.


    What do you think of that issue and the solutions I tried? Have you done anything like that using Timeline so far?
     
    Ash-Blue likes this.
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,010
    Hi,

    I think your ideas are on the right track, but you may want to consider creating a state machine to control the animation, and using a script playable to cause transitions to happen. That would allow you to keep the idles going when the timeline is paused, and have smoother transitions between idles and animation states.
     
    Corvwyn likes this.
  3. David-J-Foster

    David-J-Foster

    Joined:
    Jan 13, 2014
    Posts:
    18
    Yes, this is totally possible, and like seant_unity says, you're on the right track (excuse the pun!).

    I have found that when controlling an animator's animation using the timeline's animation track, as long as that timeline is active (that is, either playing or paused), you will lose control of your animator. Phrased another way, the animator will continue to be in whichever Mecanim state it last was, but the animation will be overridden by the timeline. This also means that if your animation track doesn't have a clip on it, your animator simply won't animate.

    Check this out:



    My solution was to create a custom playable which invokes an event when its first frame is processed ("Congrats" on the timeline). It will keep track of the timeline playback position, work out the duration of the event (the 'width' of the "Congrats" timeline clip), then invoke the event passing the relevant information.

    When I receive that event, I stop the timeline to regain control over the animator and enter the Idle state. Now at this point the player can be doing whatever they want, and when an interesting event happens, I cross fade the animator into the next state on the timeline and, on completion, tell the timeline to resume at the end of the "Congrats" event plus the cross fade duration.

    And it works. Not a single animation frame is skipped (I did a lot of testing). Try it yourself!

    As an aside, you'll see in the video that I have also implemented a custom audio source track that takes an audio source and plays clips on it, enabling 3D audio. It was quite painful to support dropping audio clips onto it which automatically resize based on the underlying clip's duration! If anyone's interested I might turn it into a little Asset Store plugin.

    EDIT: Based on this forum post: https://forum.unity3d.com/threads/issue-with-mixing-animator-and-timeline-animations.468955/

    It seems that the fact that the underlying Mechanim animations are not playing when the animation track is empty (or eased out) points to a bug in the latest beta. I'm waiting to hear back from thierry_unity.
     
    Last edited: May 14, 2017
  4. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,010
    In the video, the infinite symbol between the fourth and fifth clip indicates that the pose from the fourth clip is being held. If you click on that clip and change it's post-extrapolation to None, then the state machine should drive the animation.
     
    David-J-Foster likes this.
  5. David-J-Foster

    David-J-Foster

    Joined:
    Jan 13, 2014
    Posts:
    18
    This same topic is being discussed between myself and seant_unity in another thread but I am responding here again in case someone arrives here from a Google search or something.

    Thanks seant_unity. I have set all of my extrapolation values to none. Still, any empty space on the track while in play mode results in a static pose. Any other ideas, settings to watch out for, etc.?
     
  6. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,010
    Can you submit a bug with a repro project? I've tried to replicate the problem (based on what I see in the video), and the state machine is playing fine inside the gaps in timeline.
     
  7. R40ul_OSG

    R40ul_OSG

    Joined:
    Sep 2, 2016
    Posts:
    43
    Thanks for your answers.
    In the end, I did what seant_unity suggested in his message and it works fine.