Trigger Script (or Else) at the end of a conversation node (dialogue entry)

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
laurelhach
Posts: 18
Joined: Fri Jan 01, 2021 2:59 pm

Trigger Script (or Else) at the end of a conversation node (dialogue entry)

Post by laurelhach »

Hi Tony,

I'd like to know if there is a way to trigger a script (or something else) at the end of the NPC conversation entry.
Let me explain: Right now, using the typewriter style to display the text, the script is executed when the NPC starts the dialogue. But I'd like to have the script trigger at the end of the entry (or when the typewriter is completed). Right now, the item is given to the player, but the NPC didn't even talk about it :)

Thanks in advance!
User avatar
Tony Li
Posts: 21957
Joined: Thu Jul 18, 2013 1:27 pm

Re: Trigger Script (or Else) at the end of a conversation node (dialogue entry)

Post by Tony Li »

Hi,

Two ideas:

1. Add an empty node after that node, and give the item in the empty node, or

2. Give it using a sequencer command, and wait for the "Typed" message that the typewriter sends. Example:

Code: Select all

GiveItem(Magic Sword)@Message(Typed)
The example above assumes a custom sequencer command GiveItem().
laurelhach
Posts: 18
Joined: Fri Jan 01, 2021 2:59 pm

Re: Trigger Script (or Else) at the end of a conversation node (dialogue entry)

Post by laurelhach »

So I tried the second option :
I've added this in the sequencer:

Code: Select all

GiveItem(item)@Message(TypeEnds)
And I've added in the typewrite an event on end

Code: Select all

    
    public void OnTextEnd()
    {
        Sequencer.Message("TypeEnds");
    }
The Message is sent (Validated with breakpoint), and the GiveItem method works (validated too) if I don't have the @Message(TypeEnds) at the end.
But having the @Message(TypeEnds) never triggers ...

Do you know what I could be doing wrong?
User avatar
Tony Li
Posts: 21957
Joined: Thu Jul 18, 2013 1:27 pm

Re: Trigger Script (or Else) at the end of a conversation node (dialogue entry)

Post by Tony Li »

Hi,

If you're using the UnityUITypewriterEffect or TextMeshProTypewriterEffect (or a TextAnimatorSubtitlePanel if you're using Text Animator), they automatically send the "Typed" sequencer message. You don't need a custom script to send "TypeEnds", and you don't need to set anything in the typewriter's OnEnd() event.

The actual text "GiveItem(item)" in my previous reply was just a hypothetical example that assumes you've written a custom sequencer command named GiveItem.
laurelhach
Posts: 18
Joined: Fri Jan 01, 2021 2:59 pm

Re: Trigger Script (or Else) at the end of a conversation node (dialogue entry)

Post by laurelhach »

Yes I did :) Sorry I didn't put the code.
And I use "TextMeshProTypewriterEffect", but I didn't receive the message "Typed".

Code: Select all

    public class SequencerCommandGiveItem : SequencerCommand
    { 

        public void Awake()
        {
            string itemName = GetParameter(0);
            QuestManager.Instance.GiveItemFromConversation(itemName);
            Stop();
          }
     }

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

Re: Trigger Script (or Else) at the end of a conversation node (dialogue entry)

Post by Tony Li »

Here's an example scene:

DS_TypedExample_2023-02-13.unitypackage

It uses a ShowAlert()@Message(Typed) sequencer command instead of a custom sequencer command, but that shouldn't matter; it still demonstrates the use of @Message(Typed).
laurelhach
Posts: 18
Joined: Fri Jan 01, 2021 2:59 pm

Re: Trigger Script (or Else) at the end of a conversation node (dialogue entry)

Post by laurelhach »

Hi Tony,

So after investigation, the problem is when I press the continue button, the custom command is not triggered, but your internal command is (ShowAlert()).
If I wait the end of the dialogue (typewriting is done) then my custom command is executed.

Not sure if this is intentional ? or is there something I'm missing ?
btw I was using your template, I've just added a custom command script to test it.
User avatar
Tony Li
Posts: 21957
Joined: Thu Jul 18, 2013 1:27 pm

Re: Trigger Script (or Else) at the end of a conversation node (dialogue entry)

Post by Tony Li »

Hi,

It's intentional. Put the keyword 'required' in front of the command to require it to run even if the player skips ahead using the continue button. (The ShowAlert() command just happens to work in this case due to a different reason: when a conversation ends, it checks if an alert message is pending in the "Alert" variable.)

Code: Select all

required GiveItem(item)@Message(TypeEnds)
laurelhach
Posts: 18
Joined: Fri Jan 01, 2021 2:59 pm

Re: Trigger Script (or Else) at the end of a conversation node (dialogue entry)

Post by laurelhach »

Thank you :)

Just out of curiosity, was that information in the doc section ? maybe I didn't pay attention, but I haven't seen it.
At least it works now.
User avatar
Tony Li
Posts: 21957
Joined: Thu Jul 18, 2013 1:27 pm

Re: Trigger Script (or Else) at the end of a conversation node (dialogue entry)

Post by Tony Li »

Glad to help!

Technically it's there under Sequencer Command Syntax, but the Dialogue System has a lot of documentation so it's easy to miss little things like this.
Post Reply