Easiest way to change portrait name?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
cro
Posts: 4
Joined: Wed Aug 05, 2020 10:15 am

Easiest way to change portrait name?

Post by cro »

I'm using a modified version of the JRPG template:

Image

I have a GameObject that I've named NPC and intend to use as a generic prefab. I have an npcName variable set in a script on that object as a string value.

I'd like to either use that npcName variable somehow via script or set the name that shows up in portrait name -- the "(Name)" text. As is it just uses the GameObject's name, so it always shows "NPC" as the speaker. I've tried using the DialogueActor and Usable's "Override Name" field, but to no avail. Is there something else I should be doing?
User avatar
Tony Li
Posts: 22054
Joined: Thu Jul 18, 2013 1:27 pm

Re: Easiest way to change portrait name?

Post by Tony Li »

Hi,

If you assign the NPC GameObject to the Dialogue System Trigger's Start Conversation > Conversation Conversant field, and add a Dialogue Actor component to the NPC GameObject, then you should be able to set the DialogueActor.actor variable to the value of your npcName variable. Note that you must do this before starting the conversation. The conversation will cache the character's name as soon as the conversation starts so it doesn't have to continually look it up.

If you can't set it before starting the conversation, let me know. There are other options.
cro
Posts: 4
Joined: Wed Aug 05, 2020 10:15 am

Re: Easiest way to change portrait name?

Post by cro »

Thanks, Tony!

I definitely overlooked some stuff when searching earlier ^^;;

For anyone else looking for a quick step-by-step:

Add the dialogue actor component to your gameobject

Image

Actually add the actor name in the dialogue system's actors tab

Image

It now appears in the dropdown

Image

And correctly changes the name!

Image
User avatar
Tony Li
Posts: 22054
Joined: Thu Jul 18, 2013 1:27 pm

Re: Easiest way to change portrait name?

Post by Tony Li »

Thanks for sharing!

Side note: If you're setting DialogueActor.actor from code, you should be able to assign any string to it. As long as that GameObject is assigned to the trigger's Conversation Conversant, it will use whatever string you assign to actor.

Extra tangent side note: You can include [var=variable] and [lua(code)] tags in the actor string (or the actor's Display Name in the Dialogue Editor for that matter). This is useful is actor names, or even parts of actor names, can change.
cro
Posts: 4
Joined: Wed Aug 05, 2020 10:15 am

Re: Easiest way to change portrait name?

Post by cro »

Side note: If you're setting DialogueActor.actor from code, you should be able to assign any string to it. As long as that GameObject is assigned to the trigger's Conversation Conversant, it will use whatever string you assign to actor.
Oh, cool! So something like

Code: Select all

DialogueActor myActor = GetComponent<DialogueActor>();
myActor.actor = "Roland Deschain";
would work, yeah?
User avatar
Tony Li
Posts: 22054
Joined: Thu Jul 18, 2013 1:27 pm

Re: Easiest way to change portrait name?

Post by Tony Li »

Yes. Or even this if you want to get over-elaborate:

Code: Select all

myActor.actor = "[var=MainNPCName]";
DialogueLua.SetVariable("MainNPCName", "Roland Deschain");
cro
Posts: 4
Joined: Wed Aug 05, 2020 10:15 am

Re: Easiest way to change portrait name?

Post by cro »

Nice! Thanks for the help, Tony! Hopefully these little examples help anyone else who stumbles upon this :D
Post Reply