How to change Actors in runtime

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Yipikayei
Posts: 6
Joined: Fri Jun 07, 2019 7:43 am

How to change Actors in runtime

Post by Yipikayei »

Hi,

I want to make a default conversation based on who is speaking. I want to start a conversation by script with random actors (or also set the actors by scripting). That conversation will have conditions based on who is speaking.

Is there any way to do this??

Thanks in advance.
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to change Actors in runtime

Post by Tony Li »

Hi,

Yes; that's a fundamental design feature of the Dialogue System.

When you start a conversation, you can specify the GameObjects that will act as the primary actor and conversant, even if they don't correspond to the actors assigned to the conversation in the dialogue database.

You can specify GameObjects in a Dialogue System Trigger's Actions > Start Conversation section, in script using DialogueManager.StartConversation(), or in an equivalent visual scripting action (e.g., PlayMaker).

If the GameObject has a Dialogue Actor component, then the current run of the conversation will use the Dialogue Actor's actor instead of the actor assigned in the dialogue database.

The Dialogue System will automatically create and set four variables when a conversation starts. You don't have to add them to your database, but you can add them if you want to easily reference them in dropdown menus in your conversations.
  • Actor: The display name of the conversation's primary actor (typically the player).
  • Conversant: The display name of the conversation's primary conversant (typically an NPC).
  • ActorIndex: The Actor[] table index of the actor, provided for optional low-level Lua code.
  • ConversantIndex: The Actor[] table index of the conversant.
(This list is copied from the Dialogue Editor > Variables section of the manual.)

A common use case is a general-purpose conversation for villagers or shopkeepers. You can write a single conversation and use it for all the shopkeepers in the game. Then you can use the variables above in your conversation's Dialogue Text, Conditions, and Script fields. For example:
  • Dialogue Text: "I'm [var=Conversant]. Welcome to my shop!"
You can also add custom fields to actors. For example, say you add a field named "City" that specifies where each shopkeeper is located. Here's an example of checking this field to conditionally show a line of dialogue:
  • Dialogue Text: "Psst, want to see some illegal goods?"
  • Conditions: Actor[Variable["ConversantIndex"]].City == "Thief City"
Yipikayei
Posts: 6
Joined: Fri Jun 07, 2019 7:43 am

Re: How to change Actors in runtime

Post by Yipikayei »

Oh, thank you so much. I'll try it now.

Regards.
Post Reply