How to get All Dialogue Entries of a conversation

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
etsapekis
Posts: 39
Joined: Tue Oct 12, 2021 4:21 pm

How to get All Dialogue Entries of a conversation

Post by etsapekis »

Via Dialogue Manager, I cannot even get the current dialogue entry; I have to get it through the StandardUISubtitlePanel. I would like to retrieve all relevant info in all the dialogue entries when the conversation starts, so I need a way of getting references to all of the dialogue entries of a conversation. How can I do this? Also, is there not an event I can subscribe to to detect that a new dialogue is displaying? I have to run an update loop checking the current id of the conversation and dialogue entry, but I'd much prefer having an event to subscribe to in code.
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to get All Dialogue Entries of a conversation

Post by Tony Li »

Hi,

See Script Messages and Events. Some example code you can put in a script on the Dialogue Manager:

Code: Select all

// When conversation starts, log all dialogue entries:
void OnConversationStart(Transform actor)
{
    var conversation = DialogueManager.masterDatabase.Getconversation(DialogueManager.lastConversationStarted);
    foreach (DialogueEntry entry in conversation.dialogueEntries)
    {
        Debug.Log($"[{entry.id}]: {entry.subtitleText}");
    }
}

// On each line, log info about the line:
void OnConversationLine(Subtitle subtitle)
{
    Debug.Log($"[{subtitle.dialogueEntry.id}] {subtitle.speakerInfo.Name}: {subtitle.formattedText.text}");
    // (Current conversation state is also available in DialogueManager.currentConversationState any 
    // time a conversation is active .)
}
etsapekis
Posts: 39
Joined: Tue Oct 12, 2021 4:21 pm

Re: How to get All Dialogue Entries of a conversation

Post by etsapekis »

I'm not seeing how to subscribe to OnConversationLine. It does not seem to be an option for the dialogue manager nor the subtitle panel. I already have conversationStarted without issue, but not the line
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to get All Dialogue Entries of a conversation

Post by Tony Li »

It's not a subscription; it's a message. It's invoked on scripts on the Dialogue Manager GameObject's hierarchy and the participants. (Messages get a bad rap when they're used incorrectly, but they're designed for incidental notifications such as these.)
etsapekis
Posts: 39
Joined: Tue Oct 12, 2021 4:21 pm

Re: How to get All Dialogue Entries of a conversation

Post by etsapekis »

Oh, I see.
Followup question. Is it safe to always assume that DialogueEntry.Id is equal to its index in the conversation's list of dialogue entries? or at least that an entry with Id == 0 is always the start node?
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to get All Dialogue Entries of a conversation

Post by Tony Li »

Entry ID 0 should always be the <START> node. But there is no guarantee that other nodes' IDs will be the same as their indices in the conversation's dialogueEntries list.
Post Reply