Changing Actor (Player) Name to a Public String with Button Click

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
DrewThomasArt
Posts: 60
Joined: Thu Mar 24, 2022 12:07 am

Changing Actor (Player) Name to a Public String with Button Click

Post by DrewThomasArt »

My player changes their name on an Input Field in the Character Creation screen, where it's stored as a public string "nameOfPlayer", and saved on clicking the Continue button. The name displays below the player, but I want to change the actor name as well so it shows up in the conversation UI and possibly in conversation text.

This is the code I've been trying to make work, mainly based on very old forum posts from here;

Code: Select all

   void Start() {
        Lua.RegisterFunction("SetOverrideName", null, SymbolExtensions.GetMethodInfo(() => SetOverrideName(string.Empty, string.Empty)));
    }

    public static void SetOverrideName(string Tarul, string nameOfPlayer)
    {
        var go = GameObject.Find("Tarul"); //Tarul is the name of the player game object
         nameOfPlayer = go.GetComponent<PlayerName>().nameOfPlayer; //Getting my player's name from a script on the player
        if (go == null) return;
        var overrideActorName = go.GetComponent<OverrideActorName>() ?? go.AddComponent<OverrideActorName>();
        overrideActorName.overrideName = nameOfPlayer;
    }
But it's not working for me, and perhaps there's an easier way to set the actor name to my "nameOfPlayer" string?
This script above is attached to the Dialogue Manager and "SetOverrideName" doesn't show as an option when I try to apply it to the Continue button.
Thanks for any help!
User avatar
Tony Li
Posts: 21962
Joined: Thu Jul 18, 2013 1:27 pm

Re: Changing Actor (Player) Name to a Public String with Button Click

Post by Tony Li »

Hi,

No need for any of that. Let's assume the player actor in your dialogue database is named "Player". Just use this C# code:

Code: Select all

var go = GameObject.Find("Tarul"); //Tarul is the name of the player game object
var nameOfPlayer = go.GetComponent<PlayerName>().nameOfPlayer; //Getting my player's name from a script on the player
DialogueLua.SetActorField("Player", "Display Name", nameOfPlayer);
Actor field values are included in saved games, so you only need to set it once.
DrewThomasArt
Posts: 60
Joined: Thu Mar 24, 2022 12:07 am

Re: Changing Actor (Player) Name to a Public String with Button Click

Post by DrewThomasArt »

Tony Li wrote: Tue Dec 20, 2022 7:18 pm Hi,

No need for any of that. Let's assume the player actor in your dialogue database is named "Player". Just use this C# code:

Code: Select all

var go = GameObject.Find("Tarul"); //Tarul is the name of the player game object
var nameOfPlayer = go.GetComponent<PlayerName>().nameOfPlayer; //Getting my player's name from a script on the player
DialogueLua.SetActorField("Player", "Display Name", nameOfPlayer);
Actor field values are included in saved games, so you only need to set it once.
Works like a charm, thank you!
User avatar
Tony Li
Posts: 21962
Joined: Thu Jul 18, 2013 1:27 pm

Re: Changing Actor (Player) Name to a Public String with Button Click

Post by Tony Li »

Happy to help!
DrewThomasArt
Posts: 60
Joined: Thu Mar 24, 2022 12:07 am

Re: Changing Actor (Player) Name to a Public String with Button Click

Post by DrewThomasArt »

Tony Li wrote: Tue Dec 20, 2022 9:25 pmHappy to help!
Oh, I forgot to ask,
How would I use their custom name in a conversation node?
Apologies.

EDIT: Scratch that, I found it on another post. I used, [lua(Actor["Tarul"].Display_Name)] in the node.
Thanks again
User avatar
Tony Li
Posts: 21962
Joined: Thu Jul 18, 2013 1:27 pm

Re: Changing Actor (Player) Name to a Public String with Button Click

Post by Tony Li »

There's a simpler way: use [var=Actor]
  • Dialogue Text: "Hello, [var=Actor]."
Post Reply