Page 1 of 1

OnConversationStart/End events

Posted: Thu Feb 04, 2021 8:42 pm
by bidoofarmy
Hey,

I'd like to subscribe to conversation-starting and conversation-ending events through script so my game manager can know when to enter and when to exit its dialogue state — which is whenever any conversation starts or ends. I'm assuming they're static actions? I'd like to do something that basically amounts to this:

Code: Select all

using PixelCrushers.DialogueSystem;

private State state;

private void Awake()
{
     Wherever.OnConversationStart += EnterDialogueState;
     Wherever.OnConversationEnd += ExitDialogueState;
}

private void EnterDialogueState() => this.state = State.Dialogue;
private void ExitDialogueState() => this.state = State.Main;
From what I gather from documentation, something to that effect does exist but I can't seem to find these particular events — it doesn't appear I can access them from the DialogueManager or anywhere else. I'm probably missing something very obvious here, but search results unfortunately didn't help. Could you please help me out with that? That would be very much appreciated.

Cheers.

Re: OnConversationStart/End events

Posted: Thu Feb 04, 2021 8:48 pm
by Tony Li
Hi,

The Script Events & Messages section has that info. For the C# events:

Code: Select all

DialogueManager.instance.conversationStarted += OnConversationStarted;
DialogueManager.instance.conversationEnded += OnConversationEnded;

void OnConversationStarted(Transform actor) {...}
void OnConversationEnded(Transform actor) {...}

Re: OnConversationStart/End events

Posted: Thu Feb 04, 2021 9:00 pm
by bidoofarmy
Thank you very much for your quick response. Of course, that was it; I'm so used to events starting with "On" that I misread the doc and assumed the events themselves were named "OnConversationStarted". Problem solved. Cheers!

Re: OnConversationStart/End events

Posted: Thu Feb 04, 2021 9:24 pm
by Tony Li
Hi,

Glad to help! Microsoft's convention is that events usually take the form verbed, as in conversationStarted, and event receivers use the form OnVerbed, as in OnConversationStarted. However, that's not to say the rest of the Dialogue System is necessarily Microsoft .NET standard format. It largely tries to follow Unity's conventions instead, such as naming properties in lowercase such as DialogueManager.instance. Same with C# events, which is why it's DialogueManager.instance.conversationStarted with a lowercase 'c'.

Also, the Dialogue System takes advantage of Unity messages, so it supports a lot of useful Unity style message methods such as OnConversationStart and OnConversationEnd.