This page describes the messages that are sent to various elements of the Dialogue System.
You may also find it convenient to hook up events visually in the inspector using the Dialogue System Events component.
The Dialogue System sends these messages to the participants involved:
Message | Recipient | Description |
---|---|---|
OnConversationStart(Transform actor) | Participants, Dialogue Manager & children | Sent at the start of a conversation. The actor is the other participant in the conversation |
OnConversationEnd(Transform actor) | Participants, Dialogue Manager & children | Sent at the end of a conversation, after the dialogue UI has closed. The actor is the other participant in the conversation |
OnConversationCancelled(Transform actor) | Dialogue Manager & children | Sent if a conversation ended because the player pressed the cancel key or button during the player response menu |
OnPrepareConversationLine(DialogueEntry) | Dialogue Manager only | Sent prior to evaluating a dialogue entry's links and preparing it to be spoken. Note: Also sent prior to preparing a bark |
OnConversationLine(Subtitle subtitle) | Participants, Dialogue Manager & children | Sent just before a line is spoken. See the PixelCrushers.DialogueSystem.Subtitle reference. Your method can modify the subtitle before it's displayed |
OnConversationLineEnd(Subtitle subtitle) | Participants, Dialogue Manager & children | Sent at the end of a line, including if the line is cancelled |
OnConversationLineCancelled(Subtitle subtitle) | Dialogue Manager & children | Sent if the player pressed the cancel key or button while a line was being delivered. Cancelling causes the Dialogue System to jump to the end of the line and continue to the next line or response menu |
OnConversationTimeout() | Dialogue Manager | Sent if the response menu timed out. The DialogueSystemController script handles timeouts according to its display settings. You can add your own scripts to the Dialogue Manager object that also listens for this message |
OnConversationResponseMenu(Response[] responses) | Dialogue Manager & children | Sent before showing a response menu. See the PixelCrushers.DialogueSystem.Response reference. Your method can modify the content of the responses |
OnLinkedConversationStart(Transform actor) | Participants, Dialogue Manager & children | Sent when an active conversation follows a cross-conversation link to a different conversation in the dialogue database |
OnTextChange(UnityEngine.UI.Text) | Only Unity UI Dialogue UI | Sent when a Unity UI Dialogue UI Text element changes |
Message | Recipient | Description |
---|---|---|
OnBarkStart(Transform actor) | Participants, Dialogue Manager & children | Sent at the start of a bark. The actor is the other participant |
OnBarkEnd(Transform actor) | Participants, Dialogue Manager & children | Sent at the end of a bark. The actor is the other participant |
OnBarkLine(Subtitle subtitle) | Speaker, Dialogue Manager & children | Send at the start of a bark before the line is barked. Your method can modify the subtitle before it's barked |
Message | Recipient | Description |
---|---|---|
OnSequenceStart(Transform actor) | Speaker & listener | Sent at the beginning of a cutscene sequence. The actor is the other participant. (Sequences can have an optional speaker and listener) |
OnSequenceEnd(Transform actor) | Speaker & listener | Sent at the end of a sequence. The actor is the other participant |
Message | Recipient | Description |
---|---|---|
OnDialogueSystemPause() | Conversation participants, Dialogue Manager & children | Sent when DialogueManager.Pause() is called |
OnDialogueSystemUnpause() | Conversation participants, Dialogue Manager & children | Sent when DialogueManager.Unpause() is called |
OnUse(Transform actor) | Targeted Usable | Sent by Selector and Proximity Selector |
The sample script below logs conversation activity. Add it to an actor such as the player.
Notes:
Scripts/Supplemental/Utility
.DialogueManager.LastConversationStarted
records the last conversation that was started, or the current conversation if a conversation is active.By default, the Dialogue System automatically advances the conversation when each subtitle's cutscene sequence is finished. If you want to require the player to click a "continue" button to manually advance the conversation, follow these steps:
To manually simulate a click of the continue button, send "OnConversationContinue" to the Dialogue Manager:
DialogueManager.Instance.SendMessage("OnConversationContinue");
Quest log windows broadcast the following messages to the Dialogue Manager when the player toggles quest tracking. You can add a script to the Dialogue Manager object (or a child object) that handles the message – for example, turning on a gameplay HUD.
Message | Recipient | Description |
---|---|---|
OnQuestStateChange(string title) | Dialogue Manager & children | Sent when a quest state or quest entry state changes via the QuestLog class and/or Lua functions SetQuestState and SetQuestEntryState |
OnQuestEntryStateChange(QuestEntryArgs args) | Dialogue Manager & children | Sent when a quest entry state changes. QuestEntryArgs is a struct with two fields: (string)questName and (int)entryNumber |
OnQuestTrackingEnabled(string questTitle) | Dialogue Manager & children | Sent when tracking is enabled |
OnQuestTrackingDisabled(string questTitle) | Dialogue Manager & children | Sent when tracking is disabled or a quest is abandoned |
You can set watches on quest states using QuestLog.AddQuestStateObserver(). See Setting Quest State Observers for more details.
You can also set watches on Lua expressions using DialogueManager.AddLuaObserver(). See How to Use Lua in Scripts for more details, including performance considerations.
Normally, you will add conditions on a dialogue entry using its Conditions field, specified in Lua code. However, if you need to perform extra checking outside of Lua, you can set the Dialogue Manager's IsDialogueEntryValid
delegate. This is a C# method that returns true
or false
. If it returns true
, the dialogue entry is considered for use in the current conversation.
Example:
Here's a real world example of IsDialogueEntryValid
. It's in a subclass of UnityDialogueUI, but you could put it anywhere. This class just happened to be a good place for this developer.
If you need to update the available choices in the player response menu while the response menu is already being displayed, call:
DialogueManager.UpdateResponses();
This updates the responses for the current state of the current conversation. For example, say your player is a shapeshifter in a fantasy game. When she talks to an NPC while in cat form, the response menu may contain choices specific to her cat form. But if she transforms into a dog while the response menu is displayed, call DialogueManager.UpdateResponses()
to remove the cat-specific choices and add the dog-specific choices.