Page 1 of 1

How to change Actors in runtime

Posted: Fri Jun 07, 2019 7:50 am
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.

Re: How to change Actors in runtime

Posted: Fri Jun 07, 2019 8:15 am
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"

Re: How to change Actors in runtime

Posted: Fri Jun 07, 2019 8:20 am
by Yipikayei
Oh, thank you so much. I'll try it now.

Regards.