Script Messages

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.


Conversation, Bark, and Sequence Messages

The Dialogue System sends these messages to the participants involved:

Conversation Messages

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

Bark Messages

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

Sequence Messages

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

Other Messages

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

Example: Conversation Logger

The sample script below logs conversation activity. Add it to an actor such as the player.

using UnityEngine;
 
public class LogConversation : MonoBehaviour {
 
public void OnConversationStart(Transform actor) {
Debug.Log(string.Format("Starting conversation with {0}", actor.name));
}
 
public void OnConversationLine(Subtitle subtitle) {
Debug.Log(string.Format("{0}: {1}", subtitle.speakerInfo.transform.name, subtitle.formattedText.text));
}
 
public void OnConversationEnd(Transform actor) {
Debug.Log(string.Format("Ending conversation with {0}", actor.name));
}
 
}

Notes:

  • An extended version of this script is located in Scripts/Supplemental/Utility.
  • The string DialogueManager.LastConversationStarted records the last conversation that was started, or the current conversation if a conversation is active.

Subtitle Continue Button

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:

  1. In your UI, add Continue Buttons to the NPC and/or PC subtitle panels.
  2. Assign those buttons to the Continue Button properties on the UI component.
  3. In the Dialogue Manager's Display Settings, select an option for Continue Button other than Never.

To manually simulate a click of the continue button, send "OnConversationContinue" to the Dialogue Manager:

DialogueManager.Instance.SendMessage("OnConversationContinue");

Quest Messages

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.


Lua Messages

You can also set watches on Lua expressions using DialogueManager.AddLuaObserver(). See How to Use Lua in Scripts for more details, including performance considerations.


IsDialogueEntryValid Delegate

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:

DialogueManager.Instance.IsDialogueEntryValid = IsMyDialogueEntryValid;
public bool IsMyDialogueEntryValid(DialogueEntry dialogueEntry) {
// Return true if the entry is valid to use right now;
// otherwise return false.
}

IsDialogueEntryValid 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.

  • The Start() method registers the delegate IsSpeakerNearby().
  • Whenever the Dialogue System considers using a dialogue entry, it calls this delegate. If it returns true, the entry is kept in consideration. If it returns false, the entry is rejected.
  • In this example, IsSpeakerNearby() examines the entry's Actor ID. If the actor isn't close enough to the player, it returns false. The functions to check distance aren't shown in this example.
public class MyDialogueUI : UnityDialogueUI {
// In Start, set up the extra line-checking delegate (to make sure actors are nearby):
public override void Start () {
base.Start();
DialogueManager.IsDialogueEntryValid = IsSpeakerNearby;
}
// This is an additional check on dialogue entries. If the actor isn't nearby, the entry is rejected:
public bool IsSpeakerNearby(DialogueEntry entry) {
if (entry == null) return false;
// Always return true for the conversation's primary Actor and Conversant:
if (IsAPrimaryConversationActor(entry)) return true;
// Now that we have the isActorNearby[] value, check it:
if (IsActorNearby(entry.ActorID)) {
return true;
} else {
if (DialogueDebug.LogInfo) Debug.Log(string.Format("{0}: IsSpeakerNearby: actor {1} (ID {2}) is NOT nearby", DialogueDebug.Prefix, GetActorTag(entry.ActorID), entry.ActorID));
return false;
}
}
}

UpdateResponses()

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.


<< Script Component Overview | Custom Property Drawers >>

PixelCrushers.DialogueSystem.DialogueTriggerEvent.OnConversationEnd
Trigger when the GameObject receives an OnConversationEnd message
PixelCrushers.DialogueSystem
Definition: ArticyConverterWindow.cs:8
PixelCrushers
Definition: ArticyConverterWindow.cs:8