Page 1 of 1

"Calling" a dialogue node or another conversation

Posted: Fri May 21, 2021 8:59 am
by lostmushroom
Hey Tony. Is there a way to create some kind of call function to get nodes that need to be used in many conversations? Or to call another conversation instead of linking to it, so that you don't lose your place in the original conversation?

I have a "time of day" variable in my game, so there are several nodes that play whenever a block of time passes: if morning, set to afternoon, if afternoon, set to evening, etc.

Rather than have these nodes in every conversation where time of day can change (there are a lot), I'm wondering if there's a better way to set them up so that they can be called and used wherever required.

Re: "Calling" a dialogue node or another conversation

Posted: Fri May 21, 2021 10:34 am
by Tony Li
Hi,

Here are two ideas:

1. Record the state of the current conversation. Then stop it and play the other conversation. When it's done, resume the recorded conversation. Example:

Code: Select all

private ConversationState recordedConversationState = null;

public void Interrupt(string newConversationTitle)
{
    if (DialogueManager.isConversationActive)
    {
        recordedConversationState = DialogueManager.currentConversationState;
        DialogueManager.StopConversation();
    }
    DialogueManager.StartConversation(newConversationTitle);
}

void OnConversationEnd(Transfor actor)
{
    if (recordedConversationState != null)
    {
        var conversation = DialogueManager.masterDatabase.GetConversation(recordedConversationState.subtitle.dialogueEntry.conversationID);
        DialogueManager.StartConversation(conversation.Title, recordedConversationState.subtitle.speakerInfo.transform, recordedConversationState.subtitle.listenerInfo.transform);
        recordedConversationState=  null;
    }
}
2. Or use the ConversationPositionStack. This lets you push the current conversation state onto a stack. Later, you can pop the state off the stack to resume the conversation at that point. Example:

Code: Select all

public void Interrupt(string newConversationTitle)
{
    if (DialogueManager.isConversationActive)
    { // Assumes the Dialogue Manager has a ConversationPositionStack component.
        FindObjectOfType<ConversationPositionStack>().PushConversationPosition();
        DialogueManager.StopConversation();
    }
    DialogueManager.StartConversation(newConversationTitle);
}
Then add PopConversationPosition() to the last node of your interruption conversation.