Getting response ID through C# code

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
OwlionDemanix
Posts: 4
Joined: Fri Oct 20, 2023 11:16 am

Getting response ID through C# code

Post by OwlionDemanix »

Hello !
I would like to retrieve in my C# script the ID of the responses that are actually shown on screen.
I was able to get a Response array using this :

Code: Select all

Response[] responses = DialogueManager.CurrentConversationState.pcResponses;
or this :

Code: Select all

public void OnConversationResponseMenu(Response[] responses) { }
But there is no reference to the corresponding DialogueEntry, so I can't get the ID.
Just to explain a bit why I need the responses ID, it is to quickly link them to a corresponding assets, like an image or a sound stored in Resources folder. There is so much Conversations and Nodes in my database, I want to set it up so I don't have to do the links manualy.
Thanks in advance for your help.
User avatar
Tony Li
Posts: 22108
Joined: Thu Jul 18, 2013 1:27 pm

Re: Getting response ID through C# code

Post by Tony Li »

Hi,

The Response object has a destinationEntry property, which is a DialogueEntry. You can also use an OnConversationResponseMenu(Response[]) method in a script on your Dialogue Manager to know when a menu is about to appear. Example:

Code: Select all

void OnConversationResponseMenu(Response[] responses)
{
    foreach (Response response in responses)
    {
        int responseDialogueEntryID = response.destinationEntry.id;
        Debug.Log($"{response.formattedText.text} ID is {responseDialogueEntryID}");
    }
}
OwlionDemanix
Posts: 4
Joined: Fri Oct 20, 2023 11:16 am

Re: Getting response ID through C# code

Post by OwlionDemanix »

Thank you for your answer!
I thought that response.destinationEntry was the DialogueEntry following the response, not the DialogueEntry of the response itself.
I will give it a try!
User avatar
Tony Li
Posts: 22108
Joined: Thu Jul 18, 2013 1:27 pm

Re: Getting response ID through C# code

Post by Tony Li »

Glad to help!
Post Reply