[HOWTO] How To: Get Conversation Start/End Notifications On Non-Primary Characters
Posted: Tue Dec 17, 2024 7:31 am
The Dialogue Manager GameObjects and the conversation's primary actor and conversant receive conversation messages such as OnConversationStart and OnConversationEnd. (See Script Messages.) For more info, see Character GameObject Assignments.
If you want notification on another participant at, for example, the end of the conversation, you can use OnConversationEnd on the Dialogue Manager GameObject. It always receives all OnConversationStart/End messages. Or hook into the C# event DialogueManager.instance.conversationEnded. Example: (works best if characters' GameObjects have DialogueActor components)
If you want notification on another participant at, for example, the end of the conversation, you can use OnConversationEnd on the Dialogue Manager GameObject. It always receives all OnConversationStart/End messages. Or hook into the C# event DialogueManager.instance.conversationEnded. Example: (works best if characters' GameObjects have DialogueActor components)
Code: Select all
void OnConversationEnd(Transform actor) // Put this in a script on Dialogue Manager.
{
var conversation = DialogueManager.masterDatabase.GetConversation(DialogueManager.lastConversationID);
var primaryActorIDs = new HashSet<int>() { conversation.ActorID, conversation.ConversantID };
// Identify all non-primary participants:
var otherActorIDs = new HashSet<int>();
foreach (var entry in conversation.dialogueEntries)
{
var actorID = entry.ActorID;
if (!primaryActorIDs.Contains(actorID)) otherActorIDs.Add(actorID);
}
// Send OnConversationEnd messages to them:
foreach (var actorID in otherActorIDs)
{
var actor = DialogueManager.masterDatabase.GetActor(actorID);
var actorTransform = CharacterInfo.GetRegisteredActorTransform(actor.Name);
if (actorTransform != null)
{
actorTransform.BroadcastMessage(DialogueSystemMessages.OnConversationEnd, DialogueManager.currentActor, SendMessageOptions.DontRequireReceiver);
}
}
}