I'm using a modified version of the JRPG template:
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?
Easiest way to change portrait name?
Re: Easiest way to change portrait name?
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.
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.
Re: Easiest way to change portrait name?
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
Actually add the actor name in the dialogue system's actors tab
It now appears in the dropdown
And correctly changes the name!
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
Actually add the actor name in the dialogue system's actors tab
It now appears in the dropdown
And correctly changes the name!
Re: Easiest way to change portrait name?
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.
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.
Re: Easiest way to change portrait name?
Oh, cool! So something likeSide 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.
Code: Select all
DialogueActor myActor = GetComponent<DialogueActor>();
myActor.actor = "Roland Deschain";
Re: Easiest way to change portrait name?
Yes. Or even this if you want to get over-elaborate:
Code: Select all
myActor.actor = "[var=MainNPCName]";
DialogueLua.SetVariable("MainNPCName", "Roland Deschain");
Re: Easiest way to change portrait name?
Nice! Thanks for the help, Tony! Hopefully these little examples help anyone else who stumbles upon this