Page 1 of 1

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

Posted: Tue Dec 20, 2022 5:10 pm
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!

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

Posted: Tue Dec 20, 2022 7:18 pm
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.

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

Posted: Tue Dec 20, 2022 8:08 pm
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!

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

Posted: Tue Dec 20, 2022 9:25 pm
by Tony Li
Happy to help!

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

Posted: Tue Dec 20, 2022 10:15 pm
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

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

Posted: Wed Dec 21, 2022 8:45 am
by Tony Li
There's a simpler way: use [var=Actor]
  • Dialogue Text: "Hello, [var=Actor]."