Some questions about changing actor name in c# scripts once?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
whbe
Posts: 4
Joined: Tue May 03, 2022 10:28 am

Some questions about changing actor name in c# scripts once?

Post by whbe »

Hi,I'm not native English speaker so my content may has some English error.
I'm new to dialogue system, and I want to create a public speaker actor so I could set different actor attribute to the public one when I come to different conversation node. And I have some problems.
Here is my code

Code: Select all

    public void SetThoughtToPublicSpeaker(string thoughtName)
    {
    //I use variables to record different actor name
        string thoughtValue = DialogueLua.GetVariable(thoughtName).asString;
        Actor publicSpeaker = DialogueManager.masterDatabase.GetActor(publicSpeakerName);
        if (publicSpeaker != null)
        {
            Debug.Log("get speaker and thought");
            publicSpeaker.Name = thoughtValue;
        }
        else
        {
            Debug.LogWarning("actor not setting");
        }
    }
First, could I set displayname in c#? I only find Name attribute to set, so I choose to set Name, and it dose work.
Second, I call this event twice in on conversation, in first called place, it worked. This public actor name change to the name I need.
But in second place, this actor name remain the last name. And in visual studio debug mode, I confirm the publicSpeaker.Name has changed to my second name. So I don't know what happened.
I don't know how to realize it or is impossible in dialogue system?
Please tell me more,. thanks!!!!
User avatar
Tony Li
Posts: 22148
Joined: Thu Jul 18, 2013 1:27 pm

Re: Some questions about changing actor name in c# scripts once?

Post by Tony Li »

Hi,

To change the publicSpeakerName's Display Name use:

Code: Select all

DialogueLua.SetActorField(publicSpeakerName, "Display Name", thoughtValue);
If this happens during an active conversation and you want it to change the dialogue UI's Portrait Name immediately, use the Lua function in the Discover Name example scene on the Dialogue System Extras page.
whbe
Posts: 4
Joined: Tue May 03, 2022 10:28 am

Re: Some questions about changing actor name in c# scripts

Post by whbe »

It's useful! Thanks a lot.
User avatar
Tony Li
Posts: 22148
Joined: Thu Jul 18, 2013 1:27 pm

Re: Some questions about changing actor name in c# scripts once?

Post by Tony Li »

Glad to help!
Post Reply