Page 1 of 1

Change Actor At Runtime

Posted: Sat Dec 04, 2021 8:03 am
by RetroVertigo
Sorry if this has been answered already, but looking around the forums I didn't see what I was needing.

I am trying to instantiate a NPC object and within that object I have a Dialogue Actor component added. I want to change the Actor field within it based on another variable.

I am assuming I can use something at runtime to change the Actor based on my other variable

Code: Select all

DialogueActor.Actor = "someone";
but I am not sure how to go about this. Any ideas?

Re: Change Actor At Runtime

Posted: Sat Dec 04, 2021 8:25 am
by Tony Li
Hi,

Assuming you have a reference to the instantiated NPC object, try this:

Code: Select all

using PixelCrushers.DialogueSystem; // (Add to top of your script.)
...
DialogueActor dialogueActor = npcObject.GetComponent<DialogueActor>();
if (dialogueActor != null)
{
    dialogueActor.actor = "someone";
}
Here's another tip that I'm not sure is relevant, but I'll mention it. You can include [var=variable] and [lua(code)] markup tags in your Dialogue Actor's actor value.

For example, say you have a DS variable named "Number_Of_Kingdoms_Conquered". You could set an NPC's actor field to:

Code: Select all

dialogueActor.actor = "Emperor of the [var=Number_Of_Kingdoms_Conquered] Kingdoms";

Re: Change Actor At Runtime

Posted: Sat Dec 04, 2021 11:14 am
by RetroVertigo
Thanks again for all the assistance Tony!

Re: Change Actor At Runtime

Posted: Sat Dec 04, 2021 11:40 am
by Tony Li
Happy to help!