Page 1 of 1

Showing Conversant Name without Gameobject

Posted: Fri Jul 27, 2018 7:40 pm
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.

Re: Showing Conversant Name without Gameobject

Posted: Fri Jul 27, 2018 9:11 pm
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";
}

Re: Showing Conversant Name without Gameobject

Posted: Sat Jul 28, 2018 8:24 am
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.