Trouble getting actor name to display within dialogue text.

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Tentakero
Posts: 48
Joined: Wed Sep 23, 2020 12:36 pm

Trouble getting actor name to display within dialogue text.

Post by Tentakero »

Hello, I've been sifting through threads trying to figure this out but haven't had much luck.

I have 3 characters at the moment that are having a conversation. The Player, Character A and Character B.

What is the process for getting the player's name to change to what the player has input as their name, and have it be displayed during dialogue between Character A and B when the player isn't an Actor in that block?

I've read through the Discover Name Example but that method doesn't seem to affect this. When I try to use the [lua(Actor["Player"].Display_Name)], I keep getting a "nil" in the text box for some reason.

I currently have a string value that I save in my own scripts but am just completely lost on how to get that over into the dialogue system in a way that will let me display it within a dialogue node.
Thanks for any help.
User avatar
Tony Li
Posts: 22049
Joined: Thu Jul 18, 2013 1:27 pm

Re: Trouble getting actor name to display within dialogue text.

Post by Tony Li »

Hi,
Tentakero wrote: Fri Jan 29, 2021 12:25 pmI currently have a string value that I save in my own scripts but am just completely lost on how to get that over into the dialogue system in a way that will let me display it within a dialogue node.
The easiest way is to put that value in the actor's Display Name field. Example:

Code: Select all

public string playerName = "Tentakero"; // The player name in your script.

void Start()
{
    DialogueLua.SetActorField("Player", "Display Name", playerName);
}
Tentakero
Posts: 48
Joined: Wed Sep 23, 2020 12:36 pm

Re: Trouble getting actor name to display within dialogue text.

Post by Tentakero »

Tony Li wrote: Fri Jan 29, 2021 2:19 pm Hi,
Tentakero wrote: Fri Jan 29, 2021 12:25 pmI currently have a string value that I save in my own scripts but am just completely lost on how to get that over into the dialogue system in a way that will let me display it within a dialogue node.
The easiest way is to put that value in the actor's Display Name field. Example:

Code: Select all

public string playerName = "Tentakero"; // The player name in your script.

void Start()
{
    DialogueLua.SetActorField("Player", "Display Name", playerName);
}
I'm not sure why but that wasn't working for me. Might be because I'm setting the name outside of the dialogue system. What I did manage to get working was the following:

Code: Select all

Actor actorData = DialogueManager.MasterDatabase.GetActor("Player"); //Player here would be whatever character needs to have the name changed.
Field.SetValue(actorData.fields, "Display Name", playerStringName);
I also saw I had accidentally disabled the checkbox for Use Display Name at first, but it didn't work until the code up above was in place.
User avatar
Tony Li
Posts: 22049
Joined: Thu Jul 18, 2013 1:27 pm

Re: Trouble getting actor name to display within dialogue text.

Post by Tony Li »

If that works, good enough! Keep in mind that if you haven't ticked the Dialogue Manager's Other Settings > Instantiate Database, then every time that code runs will change the actual value in the dialogue database asset.

Setting the Display Name field in Lua should work, though. The example I showed set the Display Name to the value of a C# string variable.
Tentakero
Posts: 48
Joined: Wed Sep 23, 2020 12:36 pm

Re: Trouble getting actor name to display within dialogue text.

Post by Tentakero »

Tony Li wrote: Fri Jan 29, 2021 2:53 pm If that works, good enough! Keep in mind that if you haven't ticked the Dialogue Manager's Other Settings > Instantiate Database, then every time that code runs will change the actual value in the dialogue database asset.

Setting the Display Name field in Lua should work, though. The example I showed set the Display Name to the value of a C# string variable.
Ok thanks! It should be ok in my case since the name change is only applied when the player is creating a character and when loading a saved file.
Tentakero
Posts: 48
Joined: Wed Sep 23, 2020 12:36 pm

Re: Trouble getting actor name to display within dialogue text.

Post by Tentakero »

Sorry to revive this thread but I ran into another issue shortly after.

For some reason, the name that is input isn't immediately put to use and the dialogue system instead uses whatever the last one was. I'm thinking it's keeping it in a cache or something.

The player is asked for their name -> The NPC repeats it to confirm that it's right
When it gets to the repeating part, the NPC says the wrong name until you tell them that it's wrong and reenter it again. Kind of like it's not retaining the first name that's input?

Is there a way of refreshing that cache immediately so that the name is used?
This is the code in question

Code: Select all

public void ConfirmNameInput()
    {
        Actor actorData = DialogueManager.MasterDatabase.GetActor("Player");
        Field.SetValue(actorData.fields, "Display Name", playerNameInputField.text);
        DialogueManager.masterDatabase.ResetCache(); //Testing this here but doesn't change anything
        DialogueManager.StartConversation("NPCNameConfirmation"); //This conversation refuses to use the new display name until inputting it again.
        DialogueManager.masterDatabase.ResetCache();
        DisableNameInput(); //Disables UI InputField component
    }
And this is the dialogue branch for confirmation.
Image

The display name changes immediately in the actual Display Name field within the Actors tab so I'm pretty sure it's kind of working up until the NPC has to repeat the name. Could it be because the conversation is being started in the same method and IEnumerator or something like that is needed to stagger the change?
Tentakero
Posts: 48
Joined: Wed Sep 23, 2020 12:36 pm

Re: Trouble getting actor name to display within dialogue text.

Post by Tentakero »

Gah scratch that, I've been at this too long. It's at this point that I needed to add the extra DialogueLua line

Code: Select all

DialogueLua.SetActorField("Player", "Display Name", playerName);
That did the trick and it's getting it to display properly. Thanks again.
User avatar
Tony Li
Posts: 22049
Joined: Thu Jul 18, 2013 1:27 pm

Re: Trouble getting actor name to display within dialogue text.

Post by Tony Li »

Tentakero wrote: Sat Jan 30, 2021 8:54 pmThanks again.
I'll assume you mean "Thanks, Tentakero" because you answered your own question before I even looked at it. ;-) Glad it's working.
Post Reply