Change Actor At Runtime

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
RetroVertigo
Posts: 55
Joined: Fri Apr 16, 2021 4:32 pm

Change Actor At Runtime

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

Re: Change Actor At Runtime

Post 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";
RetroVertigo
Posts: 55
Joined: Fri Apr 16, 2021 4:32 pm

Re: Change Actor At Runtime

Post by RetroVertigo »

Thanks again for all the assistance Tony!
User avatar
Tony Li
Posts: 22154
Joined: Thu Jul 18, 2013 1:27 pm

Re: Change Actor At Runtime

Post by Tony Li »

Happy to help!
Post Reply