Trigger Script (or Else) at the end of a conversation node (dialogue entry)
-
- Posts: 18
- Joined: Fri Jan 01, 2021 2:59 pm
Trigger Script (or Else) at the end of a conversation node (dialogue entry)
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!
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!
Re: Trigger Script (or Else) at the end of a conversation node (dialogue entry)
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:
The example above assumes a custom sequencer command GiveItem().
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)
-
- Posts: 18
- Joined: Fri Jan 01, 2021 2:59 pm
Re: Trigger Script (or Else) at the end of a conversation node (dialogue entry)
So I tried the second option :
I've added this in the sequencer:
And I've added in the typewrite an event on end
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?
I've added this in the sequencer:
Code: Select all
GiveItem(item)@Message(TypeEnds)
Code: Select all
public void OnTextEnd()
{
Sequencer.Message("TypeEnds");
}
But having the @Message(TypeEnds) never triggers ...
Do you know what I could be doing wrong?
Re: Trigger Script (or Else) at the end of a conversation node (dialogue entry)
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.
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.
-
- Posts: 18
- Joined: Fri Jan 01, 2021 2:59 pm
Re: Trigger Script (or Else) at the end of a conversation node (dialogue entry)
Yes I did Sorry I didn't put the code.
And I use "TextMeshProTypewriterEffect", but I didn't receive the message "Typed".
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();
}
}
Re: Trigger Script (or Else) at the end of a conversation node (dialogue entry)
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).
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).
-
- Posts: 18
- Joined: Fri Jan 01, 2021 2:59 pm
Re: Trigger Script (or Else) at the end of a conversation node (dialogue entry)
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.
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.
Re: Trigger Script (or Else) at the end of a conversation node (dialogue entry)
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.)
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)
-
- Posts: 18
- Joined: Fri Jan 01, 2021 2:59 pm
Re: Trigger Script (or Else) at the end of a conversation node (dialogue entry)
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.
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.
Re: Trigger Script (or Else) at the end of a conversation node (dialogue entry)
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.
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.