Universal Dialogue State

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
boz
Posts: 76
Joined: Mon Oct 19, 2020 8:59 pm

Universal Dialogue State

Post by boz »

Is there a way, for example, to detect if the Dialogue Window is currently open and active?

Like if I wanted to prevent things from happening in the game if the dialogue window is open, how might I do that?

I feel like I saw some sort of DialogueSystem.dialogueWindowIsOpen or something somewhere, but I can't find it now.
boz
Posts: 76
Joined: Mon Oct 19, 2020 8:59 pm

Re: Universal Dialogue State

Post by boz »

Wait, wait, I think I found it: DialogueManager.isConversationActive

Is this the best way to do this?
User avatar
Tony Li
Posts: 21980
Joined: Thu Jul 18, 2013 1:27 pm

Re: Universal Dialogue State

Post by Tony Li »

Hi,

Yes, that's a way to check if you only need to check once -- such as if the player has pressed a button to open a menu or perform some action.

If you need to check every frame, there's an alternative. You can register methods with the C# events DialogueManager.instance.conversationStarted and conversationEnded, or add a script with OnConversationStart and OnConversationEnd special methods to the Dialogue Manager.
boz
Posts: 76
Joined: Mon Oct 19, 2020 8:59 pm

Re: Universal Dialogue State

Post by boz »

Oh wow, can I use those like this?

Code: Select all

OnEnable()
{
	DialogueManager.instance.conversationStarted += DoThing;
} 
User avatar
Tony Li
Posts: 21980
Joined: Thu Jul 18, 2013 1:27 pm

Re: Universal Dialogue State

Post by Tony Li »

Yes, absolutely. A common setup is:

Code: Select all

void OnEnable()
{
    DialogueManager.instance.conversationStarted += DoThing;
}

void OnDisable()
{
    DialogueManager.instance.conversationStarted -= DoThing;
}

On the other hand, if you only want to do something once for a single conversation, you can do this:

Code: Select all

void OnEnable()
{
    DialogueManager.instance.conversationStarted += DoThing;
}

void DoThing(Transform actor)
{
    DialogueManager.instance.conversationStarted -= DoThing;
    // Do the thing here....
}
boz
Posts: 76
Joined: Mon Oct 19, 2020 8:59 pm

Re: Universal Dialogue State

Post by boz »

Perrrfect, thank you!
User avatar
Tony Li
Posts: 21980
Joined: Thu Jul 18, 2013 1:27 pm

Re: Universal Dialogue State

Post by Tony Li »

Happy to help!
Post Reply