Sequences - Mid Coversation

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Ary
Posts: 5
Joined: Sat Jun 01, 2019 7:15 pm

Sequences - Mid Coversation

Post by Ary »

Hi there, apologies I tried searching for this but couldn’t find an answer easily.

Is it possible to run a sequence in the middle of a conversation?

Example:

“What are YOU doing man!?”

Imagine the text is being revealed via the typewriter reveal. The ‘YOU’ would have a some custom rich text tag like<Shake>YOU<\Shake> to emphasise the text and it would also trigger an animation.

I wouldn’t want to use a delay from the start as once localised the ‘YOU’ would appear at different times.

If this is possible, I’m not sure the otherwise excellent documentation gets this across, as from reading through it seems sequences all just happen at once at the start of a conversation node unless you add delays?

Many thanks in advance!

Ary
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Sequences - Mid Coversation

Post by Tony Li »

Hi Ary,

There isn't anything built-in for this.

Here are two options:

Then choose one of these:

1. This option adjusts the subtitle's text and sequence before playing. It extracts a custom tag "<SHAKE>" and adds an AnimatorPlay() sequencer command. Add a script to the Dialogue Manager that has an OnConversationLine method. It should look similar to this:

Code: Select all

void OnConversationLine(Subtitle subtitle)
{
    // Just an example. Your code will need to be more flexible.
    string dialogueText = subtitle.formattedText.text;
    int characterIndex = dialogueText.IndexOf("<SHAKE>"); // Look for <SHAKE> tag.
    if (characterIndex != -1) // Found <SHAKE>, so adjust subtitle;
    {
        subtitle.formattedText.text = dialogueText.Remove("<SHAKE>"); // Remove tag from text.
        if (string.IsNullOrEmpty(subtitle.sequence)) subtitle.sequence = "{{default}}";
        int timeToShake = characterIndex * (1 / 50f); // Compute time to shake. Assumes 50 chars/sec.
        subtitle.sequence += "; AnimatorPlay(Shake)@" + timeToShake; // Adjust sequence.
    }
}
2. Or make a copy of UnityUITypewriterEffect (or the corresponding script for whatever text type you're using, such as TextMeshProTypewriterEffect). Customize it to extract "<SHAKE>" and handle it specially.


Here's more info that may be helpful. To handle #1 more generically:

You can also use the "@Message" syntax in your dialogue entry's Sequence field. For example:

Code: Select all

{{default}};
AnimatorPlay(Shake)@Message(ANIM)
The first line plays the Dialogue Manager's Default Sequence, which by default keeps the subtitle visible for a duration based on the text length.

The second line waits for a sequencer message "ANIM" and then plays the "Shake" animator state on the speaker.

Then give the Dialogue Manager a script method like this:

Code: Select all

void OnConversationLine(Subtitle subtitle)
{
    string dialogueText = subtitle.formattedText.text;
    int characterIndex = dialogueText.IndexOf("<ANIM>"); // Look for <ANIM> tag.
    if (characterIndex != -1) // Found <ANIM>, so adjust subtitle;
    {
        subtitle.formattedText.text = dialogueText.Remove("<ANIM>"); // Remove tag from text.
        if (string.IsNullOrEmpty(subtitle.sequence)) subtitle.sequence = "{{default}}";
        int timeToAnim = characterIndex * (1 / 50f); // Compute time to shake.
        subtitle.sequence += "; Delay(" + timeToAnim + ")->Message(ANIM)"; // Adjust sequence.
    }
}
Using this more general approach, you can set different dialogue entries' Sequence fields differently:

Code: Select all

{{default}}; AnimatorPlay(Cower)@Message(ANIM)

Code: Select all

{{default}}; AnimatorPlay(Laugh)@Message(ANIM)
etc.
Ary
Posts: 5
Joined: Sat Jun 01, 2019 7:15 pm

Re: Sequences - Mid Coversation

Post by Ary »

Awesome, thanks for the quick reply, Tony.

Yeah the @message way of doing things looks quite flexible!

Just to see if I am understanding this, one of the scripts is searching the subtitles for the <ANIM> tag. As soon as this is found based off of the typewriter text displaying it (although it will never display it as it’s removed) the sequence field with the @message fires off.

So you could potentially have a dialogue entry with <ANIM01>, <ANIM02> at the appropriate time and @Message(ANIM01) + @Message(ANIM02) and have both animations play at the appropriate time within 1 dialogue entry?

This would be the same for the NPC you are conversing with too?

That would probably do the trick for sure man!

Apologies I read the @message section on the documentation but didn’t notice it’s use cases, I’m not a coder and haven’t started using the asset in anger yet.

Many thanks Tony!
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Sequences - Mid Coversation

Post by Tony Li »

Hi Ary,
Ary wrote: Mon Jun 03, 2019 2:32 pmYeah the @message way of doing things looks quite flexible!
Yes, you can do quite a lot with it. Some devs use it to control tutorial "conversations" since you can also send a sequencer message using the C# method Sequencer.Message(). For example, if you were making an RTS and the tutorial wanted the player to build a Farm, your gameplay code could do this:

Code: Select all

Sequencer.Message("BuiltFarm");
And the conversation could wait for that message like this:
  • Dialogue Text: "Build a farm."
  • Sequence: Audio(Congratulations)@Message(BuiltFarm)
Ary wrote: Mon Jun 03, 2019 2:32 pmJust to see if I am understanding this, one of the scripts is searching the subtitles for the <ANIM> tag. As soon as this is found based off of the typewriter text displaying it (although it will never display it as it’s removed) the sequence field with the @message fires off.

So you could potentially have a dialogue entry with <ANIM01>, <ANIM02> at the appropriate time and @Message(ANIM01) + @Message(ANIM02) and have both animations play at the appropriate time within 1 dialogue entry?
Yes.
Ary wrote: Mon Jun 03, 2019 2:32 pmThis would be the same for the NPC you are conversing with too?
Yes. You can also specify GameObject names and the special keywords 'speaker' and 'listener' in most sequencer commands. (See the Sequencer Command Reference page for details.) For example:
  • Dialogue Text: "Alright, this is a bank robbery! Everyone get down!"
  • Sequence:

    Code: Select all

    {{default}};
    AnimatorPlay(ShootGunInAir)@Message(ANIM01);
    AnimatorPlay(LayDown,listener)@Message(ANIM02)
Ary
Posts: 5
Joined: Sat Jun 01, 2019 7:15 pm

Re: Sequences - Mid Coversation

Post by Ary »

Thank you so much for all of your advice Tony, I really appreciate the effort.

All the best,

Ary.
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Sequences - Mid Coversation

Post by Tony Li »

Happy to help!
Post Reply