Interrupt conversation with lower priority

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
OceaneM
Posts: 9
Joined: Thu Apr 27, 2023 11:08 am

Interrupt conversation with lower priority

Post by OceaneM »

Hello there,
I saw that there was a priority system between entries in the same conversation. I was wondering if there was a priority system between the conversations themselves?
There is an option in the DialogueSystemController "interruptActiveConversations" that lets you interrupt an active conversation. I'd like to be able to interrupt it only if the new conversation has a higher priority than the current one.
Is this possible?
What would be the best way to do this?

Thanks a lot for your help!
User avatar
Tony Li
Posts: 22118
Joined: Thu Jul 18, 2013 1:27 pm

Re: Interrupt conversation with lower priority

Post by Tony Li »

Hi,

There isn't anything built in. However, the Dialogue System is easily extended. You can add a custom field to your conversation template (see Templates) to specify priority. Then, if you're using Dialogue System Trigger components, override the DoConversationAction() method. For example, if your conversations have a custom Number field named "Priority", you could make a subclass of DialogueSystemTrigger similar to this:

Code: Select all

public class PrioritizedDialogueSystemTrigger : DialogueSystemTrigger
{
    protected override void DoConversationAction(Transform actor)
    {
        if (DialogueManager.isConversationActive)
        {
            var currentConversation = DialogueManager.masterDatabase.GetConversation(DialogueManager.lastConversationStarted);
            var newConversation = DialogueManager.masterDatabase.GetConversation(conversation);
            if (currentConversation.LookupInt("Priority") > newConversation.LookupInt("Priority"))
            {
                return; // Current conversation's priority is higher, so don't start new one.
            }
        }
        base.DoConversationAction(actor);
    }
}
OceaneM
Posts: 9
Joined: Thu Apr 27, 2023 11:08 am

Re: Interrupt conversation with lower priority

Post by OceaneM »

This looks exactly like what I needed. Thank you a lot
User avatar
Tony Li
Posts: 22118
Joined: Thu Jul 18, 2013 1:27 pm

Re: Interrupt conversation with lower priority

Post by Tony Li »

Glad to help!
Post Reply