change Actor's name on runtime

Announcements, support questions, and discussion for the Dialogue System.
nishant
Posts: 55
Joined: Mon Sep 21, 2015 3:16 pm
Location: Canada
Contact:

change Actor's name on runtime

Post 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
User avatar
Tony Li
Posts: 22106
Joined: Thu Jul 18, 2013 1:27 pm

Re: change Actor's name on runtime

Post 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.
nishant
Posts: 55
Joined: Mon Sep 21, 2015 3:16 pm
Location: Canada
Contact:

Re: change Actor's name on runtime

Post by nishant »

Yes .. I am storing the name , this should fix the issue .. thanks
User avatar
Tony Li
Posts: 22106
Joined: Thu Jul 18, 2013 1:27 pm

Re: change Actor's name on runtime

Post by Tony Li »

Happy to help! If you run into any issues, just let me know!
mmopulencia
Posts: 15
Joined: Tue Aug 07, 2018 2:49 am

Re: change Actor's name on runtime

Post 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!
User avatar
Tony Li
Posts: 22106
Joined: Thu Jul 18, 2013 1:27 pm

Re: change Actor's name on runtime

Post 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"
mmopulencia
Posts: 15
Joined: Tue Aug 07, 2018 2:49 am

Re: change Actor's name on runtime

Post 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.
mmopulencia
Posts: 15
Joined: Tue Aug 07, 2018 2:49 am

Re: change Actor's name on runtime

Post by mmopulencia »

Heya forget the last question , got it figured out. Thank you for your help
User avatar
Tony Li
Posts: 22106
Joined: Thu Jul 18, 2013 1:27 pm

Re: change Actor's name on runtime

Post by Tony Li »

Happy to help!
mmopulencia
Posts: 15
Joined: Tue Aug 07, 2018 2:49 am

Re: change Actor's name on runtime

Post 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
Post Reply