Page 1 of 1
Switch between conversations using UI buttons
Posted: Fri Jul 07, 2023 2:56 pm
by skuwid
I am designing a game using the SMS UI template and would like to support a list of buttons that allows the player to toggle between ongoing conversations with different NPCs. In other words, a list of portrait images that the player can click on to decide which conversation gets displayed on the main panel.
Currently, I have two buttons on screen that allow the player to trigger one of two different conversations from the same database using the 'OnUse()' function:
However, once one conversation is started, and the button for the other conversation is pressed, I get the following error message: "Dialogue System: Another conversation is already active. Not starting 'Kennedy Test 2'".
It appears that this approach attempts to replace the ongoing conversation with another one, as opposed to switching out which one gets displayed in the message panel.
How can I revise this system so that the player can toggle freely between what conversation gets displayed on the message panel, without starting/stopping the progress in any conversation while switching between them?
Thanks
Re: Switch between conversations using UI buttons
Posted: Fri Jul 07, 2023 3:57 pm
by Tony Li
Hi,
Tick the SMS Dialogue UI's Use Conversation Variable checkbox.
Configure your NPC conversation buttons to run this method, passing it the conversation title:
Code: Select all
public void StartConversation(string conversationTitle)
{
var smsDialogueUI = DialogueManager.standardDialogueUI as SMSDialogueUI;
// In case a conversation is already active, save its history and stop it:
smsDialogueUI.OnRecordPersistentData();
DialogueManager.StopConversation();
// Start the NPC conversation:
DialogueLua.SetVariable("Conversation", conversationTitle);
// Try to resume conversation from saved history:
smsDialogueUI.OnApplyPersistentData();
// If it's not active, start it fresh:
if (!DialogueManager.isConversationActive) DialogueManager.StartConversation(conversationTitle);
}
}
Re: Switch between conversations using UI buttons
Posted: Mon Jul 10, 2023 3:51 pm
by skuwid
Thank you, this method is working for me so far, but I've noticed that when the button of a conversant is pressed while its corresponding conversation is displayed on screen, it continues to call the function each time - one result of this is that when the button is repeatedly pressed for the conversant whose conversation is currently being displayed, the pause time between each new message repeatedly gets retriggered. So the longer the button is repeatedly pressed, the longer it will take for a new message to load.
This also results in the Player Character's responses reloading each time the button is pressed.
Is there a way to expand this function to prevent the player from attempting to display a conversation that is already displayed?
Thank you
Re: Switch between conversations using UI buttons
Posted: Mon Jul 10, 2023 4:04 pm
by Tony Li
Hi,
Yes, you could change the first bit of the method to something like:
Code: Select all
public void StartConversation(string conversationTitle)
{
if (conversationTitle == DialogueManager.lastConversationStarted) return;
//... (the rest here)...
Re: Switch between conversations using UI buttons
Posted: Mon Jul 10, 2023 4:19 pm
by skuwid
This fix appears to have resolved the issue for me so far, thank you!
Re: Switch between conversations using UI buttons
Posted: Mon Jul 10, 2023 4:31 pm
by Tony Li
Glad to help!
Re: Switch between conversations using UI buttons
Posted: Fri Jul 21, 2023 3:38 pm
by skuwid
Hello, I'm following up because since adding this script, I've added the Unity UI Typewriter Effect component to the NPC Subtitle Text object. One thing I've noticed since adding this component, is that now when I switch between which conversation gets displayed in the Messages Panel, as previous messages get displayed again, the typewriter effect plays on each message at once, meaning each message from the conversation you're returning to gets typed out in tandem, and the effect is a bit jarring.
Is there a way to keep the typewriter effect as new messages appear on screen, but disable it when toggling the display of earlier messages from another conversation when the button gets pressed?
Thank you for your help.
Re: Switch between conversations using UI buttons
Posted: Fri Jul 21, 2023 5:14 pm
by Tony Li
Hi,
When resuming a conversation, it shouldn't replay the typewriter effect on old lines. Make sure your typewriter effect's Play On Enable is UNticked.