Page 1 of 1
Using DialogueSystemEvents
Posted: Mon Feb 14, 2022 1:41 pm
by HunterTom
Hi,
I want to some event that can be called whenever a new conversation node shows up. Is onConversationLine the right event?
How can I subscribe my own C# function to that event using code? Can I do it in a class that doesn't inherit from Monobehavior?
Here is my attempt
Code: Select all
public static event DialogueSystemEvents.ConversationEvents.onConversationLine testEvent =
new DialogueSystemEvents.SubtitleEvent();
However, the "onConversationLine " doesn't seem to be accessible from DialogueSystemEvents.ConversationEvents
Re: Using DialogueSystemEvents
Posted: Mon Feb 14, 2022 3:09 pm
by Tony Li
Hi,
DialogueSystemEvents is a MonoBehaviour, so it must be on a GameObject. Assuming it's on the Dialogue Maanger GameObject, you could do something like this:
Code: Select all
void RegisterForEvents()
{
var events = DialogueManager.instance.GetComponent<DialogueSystemEvents>();
events.conversationEvents.onConversationLine.AddListener(HandleNewSubtitle);
}
void UnregisterFromEvents()
{
var events = DialogueManager.instance.GetComponent<DialogueSystemEvents>();
events.conversationEvents.onConversationLine.RemoveListener(HandleNewSubtitle);
}
void HandleNewSubtitle(Subtitle subtitle)
{
Debug.Log("New subtitle: " + subtitle.formattedText.text);
}
Call RegisterForEvents() to register for the event. Remember to UnregisterFromEvents() when you're done.
Re: Using DialogueSystemEvents
Posted: Mon Feb 14, 2022 3:55 pm
by HunterTom
Thank you!
By the way is it safe to call
Code: Select all
dialogueSystemEvents.conversationEvents.onConversationLineEnd.RemoveAllListeners();
? I am just a bit concerned if Dialogue System for Unity has some built-in listerners and if I call that it would destroy the whole system
Re: Using DialogueSystemEvents
Posted: Mon Feb 14, 2022 4:09 pm
by Tony Li
To be safe, I'd remove specific listeners. The core Dialogue System asset doesn't add listeners to DialogueSystemEvents, but it's possible that some addons or utility scripts here in the forum or on the Extras page might do so.