Page 1 of 1

Running a script when a conversation ends

Posted: Fri Dec 24, 2021 2:01 pm
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.

Re: Running a script when a conversation ends

Posted: Fri Dec 24, 2021 2:23 pm
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)
        }
    }
}

Re: Running a script when a conversation ends

Posted: Sat Dec 25, 2021 1:51 pm
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 603 times
But when I use SendMessage(SetSearchingPocketsEvent, speaker), nothing happens -
dialogue.png
dialogue.png (78.07 KiB) Viewed 603 times
Any observations?

Re: Running a script when a conversation ends

Posted: Sat Dec 25, 2021 9:02 pm
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.