How to interrupt conversation and return conversation after interruption.

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
elda27
Posts: 8
Joined: Fri Nov 17, 2023 11:11 am

How to interrupt conversation and return conversation after interruption.

Post by elda27 »

I tried following code so that I want to interrupt conversation and return conversation after interruption.
But there is not working.
Can I interrupt conversation?
And how can I start original conversation that is keeping node position after interruption?

Code: Select all

void Interrupt(string name)
{
        if (DialogueManager.IsConversationActive)
        {
            ConversationPositionStack.PushConversationPosition();
        }
        DialogueManager.StartConverastion(name)
}

// Callback function attached ConversationEvent
public void OnConversationEnd()
{
    try
    {
        ConversationPositionStack.PopConversationPosition();
    }
    catch
    {
        conversationStarted = false;
    }
}
User avatar
Tony Li
Posts: 21679
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to interrupt conversation and return conversation after interruption.

Post by Tony Li »

Hi,

To interrupt the conversation:

Code: Select all

string savedConversationTitle;
int savedEntryID;
Transform savedActor;
Transform savedConversant;

savedConversationTitle = DialogueManager.lastConversationStarted;
savedEntryID = DialogueManager.currentConversationState.subtitle.dialogueEntry.id;
savedActor = dialogueManager.currentActor;
savedConversant = DialogueManager.currentConversant;
DialogueManager.StopConversation();

// Then start a new conversation:
DialogueManager.StartConversation(...)
To resume the saved conversation:

Code: Select all

DialogueManager.StartConversation(savedConversationTitle, savedActor, savedConversant, savedEntryID);
However, if you want to temporarily dip into another conversation and then pop back to the previous conversation as if it's part of the same conversation, you can use the conversation position stack:

Code: Select all

ConversationPositionStack.PushConversationPosition();
var newEntry = DialogueManager.masterDatabase.GetConversation(name).GetFirstDialogueEntry();
var newState = DialogueManager.conversationModel.GetState(newEntry);
DialogueManager.conversationView.GotoState(newState);
The end of that conversation can call PopConversationPosition() in the Script field, or you can call it in C#. Make sure you've added a ConversationPositionStack component to your Dialogue Manager.
elda27
Posts: 8
Joined: Fri Nov 17, 2023 11:11 am

Re: How to interrupt conversation and return conversation after interruption.

Post by elda27 »

Thanks!

I tried your solution but I can't return previous conversation.
I seem that I use interrupt function at script field of a response panel probably.
I need to continue the next node of response panel.

There are nodes of conversations.
Node "B" is registered a script that Invokes Interrupt function after clicked the response panel.
Now, my code works interrupting another conversation after clicked "B".
But node "E" is not shown after finished another conversation.

A
├── B
│ └── E
├── C
└── D

Does your solution work in my situation?
User avatar
Tony Li
Posts: 21679
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to interrupt conversation and return conversation after interruption.

Post by Tony Li »

If B is a player response node, you may want to record the next node instead of the current node:

Code: Select all

savedEntryID = DialogueManager.currentConversationState.subtitle.speakerInfo.isNPC
    ? DialogueManager.currentConversationState.subtitle.dialogueEntry.id
    : DialogueManager.currentConversationState.firstNPCResponse.destinationEntry.id;
elda27
Posts: 8
Joined: Fri Nov 17, 2023 11:11 am

Re: How to interrupt conversation and return conversation after interruption.

Post by elda27 »

There is a node connection with its corresponding ID.

A (2)
├── B (3)
│ └── E (6)
├── C (4)
└── D (5)

Node B has Intterupt function in its script field (I was registered the Interrupt function from C# script).
If I clicked node B, I expected a scene displaying another conversation and node E after that.
But the scene displayed another conversation and node A in actual.
I understand saveEntryID should be six in my case.
But it is two in actual.

Code: Select all

savedEntryID = DialogueManager.currentConversationState.subtitle.speakerInfo.isNPC
    ? DialogueManager.currentConversationState.subtitle.dialogueEntry.id
    : DialogueManager.currentConversationState.firstNPCResponse.destinationEntry.id;
I attached image created conversation.
https://www.dropbox.com/scl/fi/xx080b0j ... l7pv0&dl=0
User avatar
Tony Li
Posts: 21679
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to interrupt conversation and return conversation after interruption.

Post by Tony Li »

Hi,

Should the conversation always go from B to the other conversation and then back? If so, you can use cross-conversation links:

conversation1.png
conversation1.png (26.52 KiB) Viewed 536 times
conversation2.png
conversation2.png (17.34 KiB) Viewed 536 times

This way you don't need any scripts or special code.
elda27
Posts: 8
Joined: Fri Nov 17, 2023 11:11 am

Re: How to interrupt conversation and return conversation after interruption.

Post by elda27 »

Yes!
Can I confirm the background in my situation?

I think your method cannot continue previous conversation after end of another conversation.
If it goes back previous conversation, I need set link another conversation at end of another conversation.

I cannot set link to fixed conversation at another conversation because another conversation is common conversation in my game.
It means another conversation is linked multiple conversations.

I want to make like this.

Code: Select all

Conversation1 -> Conversation0 -> Conversation 1 (Continue where before interruption)
Conversation2 -> Conversation0 -> Conversation 2 (Continue where before interruption)
Can it be possible to solve without script in my situation?
User avatar
Tony Li
Posts: 21679
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to interrupt conversation and return conversation after interruption.

Post by Tony Li »

Yes, you can use the Conversation Position Stack.

Here's an example:

DS_ConversationPositionStack_Interrupt_Example_2023-11-18.unitypackage

I added a Conversation Position Stack component to the Dialogue Manager.

In the dialogue database, I added a variable:

stack1.png
stack1.png (16.1 KiB) Viewed 527 times

Conversation 1 and Conversation 2 are set up like this:

stack2.png
stack2.png (35.13 KiB) Viewed 527 times

The "<Maybe Conversation 0>" node stores the current conversation position on the stack by calling PushConversationPosition(). When the player clicks the "B" node, it checks the variable value to decide whether to interrupt the conversation or continue to "E".


Conversation 0 is set up like this:

stack3.png
stack3.png (24.98 KiB) Viewed 527 times

It has an initial condition that requires the variable to be false. Then it sets the variable true.

The final node returns to the saved position by calling PopConversationPosition().
elda27
Posts: 8
Joined: Fri Nov 17, 2023 11:11 am

Re: How to interrupt conversation and return conversation after interruption.

Post by elda27 »

Thank you very much!
I solved the problem!
User avatar
Tony Li
Posts: 21679
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to interrupt conversation and return conversation after interruption.

Post by Tony Li »

Glad to help!
Post Reply