Page 1 of 2

change Actor's name on runtime

Posted: Mon Oct 19, 2015 7:22 pm
by nishant
Hi ,
I have a trivial issue . In my game I ask the player his/her name; so once player enters the name .. I want to rename an Actor named Player to that name. I want this cause there are few dialogues for player .. and I would like seeing player's name instead of just the player.
Is it possible ??

Thanks.
Nishant

Re: change Actor's name on runtime

Posted: Mon Oct 19, 2015 8:36 pm
by Tony Li
If you only plan to reference it in conversations, I recommend storing the player's name in a variable. For an example, play the scene in Assets/Dialogue System/Examples/Feature Demo/Text Input Example. Private Hart's conversation uses the TextInput sequencer command to get the player's name and store it in a variable named "MyName".

If your dialogue UI uses Portrait Names, it's a little more complicated. The Dialogue System is designed to support generic conversations, such as a "Shopkeeper" conversation that can play on any NPC shopkeeper in the game. The portrait name is the name of the NPC's GameObject, or the value of its Override Actor Name component if it has one.

To make this work, add this script (LuaSetOverrideName.cs) to your Dialogue Manager:

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;

public class LuaSetOverrideName : MonoBehaviour {

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

    public static void SetOverrideName(string gameObjectName, string newActorName)
    {
        var go = GameObject.Find(gameObjectName);
        if (go == null) return;
        var overrideActorName = go.GetComponent<OverrideActorName>() ?? go.AddComponent<OverrideActorName>();
        overrideActorName.overrideName = newActorName;
    }
}
In the dialogue entry after the TextInput command, set the Script field to something like this:

Code: Select all

SetOverrideName("Player", Variable["MyName"])
The first parameter is the name of the Player GameObject. The second parameter is the new actor name.

The catch is that each conversation caches the participants' names at the beginning. The name change will only take effect in the next conversation. So you may want to stop and restart the conversation after changing the name.

Re: change Actor's name on runtime

Posted: Tue Oct 20, 2015 6:15 pm
by nishant
Yes .. I am storing the name , this should fix the issue .. thanks

Re: change Actor's name on runtime

Posted: Tue Oct 20, 2015 6:58 pm
by Tony Li
Happy to help! If you run into any issues, just let me know!

Re: change Actor's name on runtime

Posted: Tue Aug 14, 2018 10:30 pm
by mmopulencia
Heya Tony! sorry if im bumping this thread , you may have provided the info i need, on the above reply , but please do bear with me , my question is fairly simple i hope . Similar to his question .. my welcome NPC's name is ??? , and of course the NPC will then introduce who it is and i wanted that name to be displayed right after my players response , i've tried playing with the script option under the dialogue database script options. pic below.

https://imgur.com/a/ZMpkJlm

that should be it right?? , for some reason it still keeps "???" as its name after my response.

Thanks again!

Re: change Actor's name on runtime

Posted: Tue Aug 14, 2018 11:02 pm
by Tony Li
Hi,

The actor's Name should always remain the same. Instead, change the actor's Display Name. Try this:

1. In the Dialogue Editor window's Actors section, set the actor's Name to Flame.

2. Tick Use Display Name, and set the Display Name to ???.

3. In the dialogue entry node's Script field, use the dropdowns or type this in manually:

Code: Select all

Actor["Flame"].Display_Name = "Flame"

Re: change Actor's name on runtime

Posted: Tue Aug 14, 2018 11:20 pm
by mmopulencia
Heya Tony,

Thank you for your reply , last question . all my child node turned to gray , how do i change them back to blue ??, its now doing all dialogue as NPC.

Re: change Actor's name on runtime

Posted: Tue Aug 14, 2018 11:23 pm
by mmopulencia
Heya forget the last question , got it figured out. Thank you for your help

Re: change Actor's name on runtime

Posted: Tue Aug 14, 2018 11:27 pm
by Tony Li
Happy to help!

Re: change Actor's name on runtime

Posted: Tue Aug 14, 2018 11:51 pm
by mmopulencia
Heya Tony!

I tried the code above and it still retains the display name ???, im getting no error too.

additional question for names with spaces do i use this _ or just space is fine?

https://imgur.com/a/ZMpkJlm


https://imgur.com/tDm4Vjx