Running a script when a conversation ends

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
harelme2
Posts: 9
Joined: Wed Dec 15, 2021 11:37 am

Running a script when a conversation ends

Post by harelme2 »

What's the right way(s) (using the editor/script) to run a script's function when a conversation ends?

I've tried the Dialogue System Events component, which works perfectly, but using that, the same function would run at the end of any conversation the player has, and not at the end of the specific conversation I need it to..

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

Re: Running a script when a conversation ends

Post by Tony Li »

Hi,

If it's okay to run the script in the last dialogue entry of the conversation, you can use a SendMessage() sequencer command or an OnExecute() scene UnityEvent.

If the script only needs to run after talking with a specific NPC, you can add the Dialogue System Events component to the NPC.

Otherwise, you can add a script with an OnConversationEnd() method to the Dialogue Manager or player, and check if a specific conversation has ended.

Code: Select all

public class RunScriptWhenConversationEnds : MonoBehaviour
{
    [ConversationPopup] public string conversation;
    
    void OnConversationEnd(Transform actor)
    {
        if (DialogueManager.lastConversationStarted == conversation)
        {
            // (run your script)
        }
    }
}
harelme2
Posts: 9
Joined: Wed Dec 15, 2021 11:37 am

Re: Running a script when a conversation ends

Post by harelme2 »

First of all thanks very much for replying during Christmas. Most appreciated!

My Player has the following script as one of it's components -
script.png
script.png (33.42 KiB) Viewed 607 times
But when I use SendMessage(SetSearchingPocketsEvent, speaker), nothing happens -
dialogue.png
dialogue.png (78.07 KiB) Viewed 607 times
Any observations?
User avatar
Tony Li
Posts: 22154
Joined: Thu Jul 18, 2013 1:27 pm

Re: Running a script when a conversation ends

Post by Tony Li »

Since the node is gray, the speaker is almost certainly the NPC, not the player. Assuming Ben is the player, this mean's he's this node's listener. Try this command:

Code: Select all

SendMessage(SetSearchingPocketsEvent, , listener)
Note that the SendMessage() command actually has 3 arguments. The middle argument is blank because SetSearchingPocketsEvent() doesn't have any parameters.
Post Reply