Showing Conversant Name without Gameobject

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Dmangames
Posts: 20
Joined: Fri Jul 13, 2018 9:55 pm

Showing Conversant Name without Gameobject

Post by Dmangames »

Hi,

In my text adventure game, the player sends messages to many different NPCs and none of them have GameObjects. I'm trying to get the top Header text to display the conversant's name, but only NPC works if I try setting the conversant in the dialogue editor for the conversation. The code I'm using is

Code: Select all

void OnEnable()
    {
        if (DialogueManager.currentConversant != null)
            title.text = DialogueManager.currentConversant.name;
        else
            title.text = "Anonymous";
    }
Basically the currentConversant is always null unless it is NPC and I suspect it is because I do not have GameObjects to go along with my actors.

Is there a way I can just get the string for the currentConversant name?

Thanks.
Attachments
In this case, it should say Ami as the header
In this case, it should say Ami as the header
Capture.PNG (21.96 KiB) Viewed 307 times
User avatar
Tony Li
Posts: 22058
Joined: Thu Jul 18, 2013 1:27 pm

Re: Showing Conversant Name without Gameobject

Post by Tony Li »

Hi,

As you've seen, DialogueManager.currentConversant is the GameObject that's currently assigned as the conversant -- which is this case is none.

Instead, get the name from the conversation itself:

Code: Select all

void OnEnable()
{
    var conversation = DialogueManager.masterDatabase.GetConversation(DialogueManager.lastConversationID);
    var conversant = DialogueManager.masterDatabase.GetActor(conversation.ConversantID);
    if (conversant != null)
        title.text = conversant.Name;
    else
        title.text = "Anonymous";
}
User avatar
Tony Li
Posts: 22058
Joined: Thu Jul 18, 2013 1:27 pm

Re: Showing Conversant Name without Gameobject

Post by Tony Li »

I borrowed your idea and put it into the version 2018-07-28 version of Textline. Now you can assign the heading text to the TextlineDialogueUI component, and it will automatically set it to the current conversation title.
Post Reply