How do I write to script from dialogue option?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
Tank
Posts: 10
Joined: Mon Apr 30, 2018 3:59 pm

How do I write to script from dialogue option?

Post by Tank »

For example if the player picks a certain dialogue option, how do I make it so when that option is selected, something happens in a script? I want this particular choice to dictate the background of the player. I've tried to use an event from the event tab when you have a conversation line selected but I can't drag the script I want to use.

Any help is appreciated.
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: How do I write to script from dialogue option?

Post by Tony Li »

Hi,

There are several options.

Using the OnExecute UnityEvent is not always the best option. Dialogue databases exist outside of scenes, so their UnityEvents can't point to anything inside a scene. You can point them to a ScriptableObject, however, as in this example.

Other options:

Save the background in a custom field of the Player actor. Two advantages: (1) you don't have to write a script, and (2) it's automatically saved in saved games. To do this:
  • Inspect the actor, expand All Fields, and add a custom field.
  • Inspect the dialogue entry node, and click the "..." next to the Script field. Select Actor > (your field) > (value)
Use the SendMessage() sequencer command in the dialogue entry node's Sequence field to call a method on a GameObject's script(s).

Write a custom sequencer command. See Cutscene Sequences and Custom Sequencer Commands.

Register your script method with Lua. Then use it in the Script field. See Lua and Registering Functions.
Post Reply