Search Unity

Timeline best practice question: Branching conversations

Discussion in 'Timeline' started by Drowning-Monkeys, Feb 5, 2018.

  1. Drowning-Monkeys

    Drowning-Monkeys

    Joined:
    Mar 6, 2013
    Posts:
    328
    Howdy,

    So one of the examples for timeline i still haven't seen is how to handle a branching conversation.

    If we use the adventure game example from this Unite presentation:


    Let's use the coffeebot as an example. Let's imagine you walk up to the coffee bot,a timeline activates to make the coffeebot come out of his shell. He asks if you want coffee. You answer yes, he pours the cup, you answer no, he goes back in his shell.

    So my question is what is the best way to handle this? Can it all be handled from 1 timeline? with some kind of pausing and jumping around in the timeline? or do i need 3 separate timeline assets? If i'm using 3 separate timelines, do i replace the timeline asset in the playable director through script and play it?
     
  2. dadude123

    dadude123

    Joined:
    Feb 26, 2014
    Posts:
    789
    Of course one can use all the ideas you already have mentioned. And as always there's no single correct approach, it all depends on the situation.

    Personally I have branching dialogs in my game as well. Every segment is its own timeline (if it even needs one).
    Here's how I have structured it:

    - There's a "global" timeline (a prefab that gets instantiated for every dialog) that handles moving the camera, fading in the UI elements etc.

    - The dialog itself is handled by a dialog-tree which determines what text gets displayed to the player and what options he can select.

    - The transitions from dialog sentence to sentence are not handled by a timeline simply because there's no real need for it and its not a linear "timeline" anyway. The player can press a key to skip the animated text which introduces a event-based component into that system which timeline doesn't really handle too well. And also the length of the text that gets displayed is also always different, so it makes no sense to use a static timeline anyway.

    - Some of the responses the player can select will trigger a sequence, to take your example, a robot could pour some coffee and give it to the player. This is a perfect situation where the timeline system can be used. It's 100% scripted and linear, no branches. The only thing that might change is the actual stuff that gets modified. For example the player selecting a different type of coffee or whatever (maybe some food). For that I'd simply instantiate a different prefab and then set that in the playable director.


    In my opinion the thing to keep in mind here is that timeline - just like every other tool - is a low-level building block that you have to control yourself. Don't be afraid to use many timelines in a single dialog.
    I have one dialog in my game that make use of 6 different timelines for various short sequences.

    Pausing and jumping around is doable as well, but it simply doesn't scale all that well (in my experience, for my game, maybe you'll have a completely different opinion on this). Even if you only use it for just one dialog where it could make sense; you'll eventually come back to it and see that most of your dialogs are done using multiple timelines (because they are more complicated) and then you might ask yourself why this one is so different (and harder to maintain and change if needed).