How to end a conversation via script

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
gourangas
Posts: 10
Joined: Mon May 04, 2020 9:59 am

How to end a conversation via script

Post by gourangas »

Hey,

First of all I want to congratulate you guys on the product, its amazing.
Now my problem is;
I have an open NPC dialogue panel (so its not a finished conversation) and I would like to end it via script. I've looked around through the code and I've only managed to hide it using
PixelCrushers.DialogueSystem.DialogueManager.instance.DialogueUI.Close();
but that does not update the status of the conversation and when I am trying to trigger it again I get the warning "Another conversation is already active..." of course :). Sorry if this was already answered but I could not find a similar post.
User avatar
Tony Li
Posts: 22054
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to end a conversation via script

Post by Tony Li »

Hi,

Use DialogueManager.StopConversation(). (Most of the main Dialogue System functionality can be accessed through the DialogueManager class.)
gourangas
Posts: 10
Joined: Mon May 04, 2020 9:59 am

Re: How to end a conversation via script

Post by gourangas »

Works like a charm, thanks for the info
User avatar
Tony Li
Posts: 22054
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to end a conversation via script

Post by Tony Li »

Glad to help!
undecode
Posts: 25
Joined: Mon Apr 13, 2020 3:53 pm

Re: How to end a conversation via script

Post by undecode »

Sorry to hijack this thread, but it's a similar question.

I want to use LoadLevel(x) from a conversation node. It gives me an error saying that there is already a conversation going on.

Both scenes have conversation triggered on OnStart(). How do you end the first conversation? I tried allowing multiple conversations but it's a mess, I just want to end the first one.

Thanks!

Update: I removed the sequence command LoadLevel(x) from my conversation nodes. Then added Dialogue System Trigger component on my NPC gameobject to trigger "On Conversation End" and play the LoadLevel sequence command there.
It's working fine, but using LoadLevel directly from a conversation node looks way better, specially when loading a different scene can be used in a middle of a conversation (depending on the user selection).
Maybe i'm doing something wrong?
Last edited by undecode on Mon May 04, 2020 3:02 pm, edited 1 time in total.
User avatar
Tony Li
Posts: 22054
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to end a conversation via script

Post by Tony Li »

Hi,

You'll want to end the conversation in the first scene, then change scenes, then allow the conversation in the second scene to start when the scene starts.

To do this, don't use the LoadLevel() sequencer command in the first conversation. Instead, add a Dialogue System Trigger to the conversation's actor or conversant. Set it to OnConversationEnd. Select Add Action > Play Sequence, and put the LoadLevel() sequencer command there.
undecode
Posts: 25
Joined: Mon Apr 13, 2020 3:53 pm

Re: How to end a conversation via script

Post by undecode »

Hi Tony.

Haha exactly what I tried to do right after I posted my question, nice timing.
Please check the update part, this looks good but what if I want to change to a different scene during the middle of a conversation? I don't need to save the progress from the first conversation, but would like the possibility to change to a nother scene from any conversation node.

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

Re: How to end a conversation via script

Post by Tony Li »

It's fine to change scenes in the middle of a conversation. There are some visual novel style games that run a single conversation throughout the entire game, but change scenes multiple times during that conversation.

Just be aware that if a Dialogue System Trigger in the new scene is set to OnStart, it won't start unless the Dialogue Manager's Allow Simultaneous Conversations checkbox is ticked.
undecode
Posts: 25
Joined: Mon Apr 13, 2020 3:53 pm

Re: How to end a conversation via script

Post by undecode »

I'm having issues trying to use LoadLevel directly from a conversation node. Even using allowing multiple conversations, sometimes the 2nd conversation is played inmediately (like 10 nodes in less than 1 second, no continue button), sometimes it gets stuck in the second node and other times I get the "another conversation is active" error.

It is probably possible to do it so, but I think i'll stick to changing scenes only at the end of a conversation. After giving it some thought, a scene change should be a conversation end (one conversation branch could be shorter, other more detailed).

So for now i'm setting a variable (CurrentChapter) and changing it in the previous node than the End one. And NPC has triggers checking a condition for this variable and playing sequence accordingly.
User avatar
Tony Li
Posts: 22054
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to end a conversation via script

Post by Tony Li »

Sounds good. That's a good way to handle it because it partitions the responsibility:

Conversation 1 // scene change // Conversation 2

If you ever get back into a situation where you need to change scenes in the middle of a conversation and it's causing an issue, let me know. It's totally supported in the Dialogue System, so it's just a matter of identifying what's going on in your setup.
Post Reply