Use StopConversation to stop a specific conversation

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
dantuom
Posts: 18
Joined: Fri May 06, 2022 10:06 am

Use StopConversation to stop a specific conversation

Post by dantuom »

Hello,

My project often involves situations where I have two or even three conversation UIs open at the same time. I would like to have a sort of "close" button attached to the two secondary conversation UI windows so that the player can cancel them at any time.

I thought I could achieve this by having the button call DialogueManager.StopConversation(), but I notice that this method doesn't accept arguments and I can't work out another way to specify which conversation to stop. (I'm not sure if this is 100% scientific but I think it might stop the conversation whose UI is highest in the hierarchy??)

Anyway I'd prefer not do it by entering the conversation title as a string, as I'd rather have the button tied to the UI than the conversation. However it's important that the button does stop the conversation rather than just (for example) disabling the UI, because otherwise there are compounding problems when trying to start conversations again.

My C# is poor so I'm not sure how to script this correctly, but I wonder if there would be a way to perform something like:

Code: Select all

if(conversationIsActive in SMSDialogueUI)
{
	DialogueManager.instance.StopConversation();
}
User avatar
Tony Li
Posts: 21975
Joined: Thu Jul 18, 2013 1:27 pm

Re: Use StopConversation to stop a specific conversation

Post by Tony Li »

After you start a conversation, make a note of the current value of DialogueManager.conversationController or DialogueManager.instance.activeConversation. If you failed to record either of those, you can examine the DialogueManager.instance.activeConversations list to find the active conversation record that corresponds to the conversation you want to stop.

To stop it, call the conversationController's Close() method. Example:

Code: Select all

// Start Conversations A and B:
DialogueManager.StartConversation("Conversation A");
var controllerA = DialogueManager.conversationController;
DialogueManager.StartConversation("Conversation B");
var controllerB = DialogueManager.conversationController;
...
// Stop Conversation A early:
controllerA.Close();
...
// Stop Conversation B early:
controllerB.Close();
Post Reply