Visual Scripting Support

This page explains how to use Unity's Visual Scripting package with the Dialogue System.

How to Set Up Visual Scripting Support

  • Import the package Third Party Support ► Visual Scripting Support. This will unpack files into the folder Assets ► Pixel Crushers ► Dialogue System ► Third Party Support ► Visual Scripting Support.
  • Then select Edit → Project Settings → Visual Scripting → Node Library → Regenerate Nodes.
  • If you want a Script Machine to react to Dialogue System event messages such as OnConversationStart, add a Dialogue System Visual Scripting Custom Events component. This will invoke Dialogue System messages as Visual Scripting Custom Events. For details, see Dialogue System Visual Scripting Custom Events.
  • If you want to invoke Visual Scripting Custom Events from inside conversations, add a Dialogue System Visual Scripting Lua component to the Dialogue Manager. Do not add Dialogue System Visual Scripting Lua to other GameObjects; just to the Dialogue Manager. For details, see Visual Scripting Lua Functions.

Note:

  • To access the DialogueLua methods such as GetVariable(), edit DialogueLua.cs. Add this line above the class name:
[Unity.VisualScripting.IncludeInSettings(true)] // <-- Add this line.
public static class DialogueLua

Dialogue System Visual Scripting Custom Events

Add a Dialogue System Visual Scripting Custom Events component to GameObject(s) that receive Dialogue System events (see Script Messages & Events) and for which you want to direct those events to Visual Scripting Custom Events. The component can redirect these events:

Event Argument When It Occurs
Conversation Events Conversation-related events.
OnConversationStart Transform When a conversation starts.
OnConversationEnd Transform When a conversation ends.
OnConversationCancelled Transform When a conversation is cancelled.
OnConversationLine Subtitle Just before a conversation shows a line of dialogue.
OnConversationLineEnd Subtitle When a conversation line ends.
OnConversationLineCancelled Subtitle When a conversation line is cancelled.
OnConversationResponseMenu Response[] Just before a conversation response menu appears.
OnConversationTimeout (none) When a conversation times out.
OnLinkedConversationStart Transform When a conversation crosses a cross-conversation link.
Bark Events Bark start, end, and line events.
OnBarkStart Transform When a bark starts.
OnBarkEnd Transform When a bark ends.
OnBarkLine Subtitle Invoked just before showing a bark.
Sequence Events Sequence start and end events.
OnSequenceStart Transform When a sequence starts (except conversation sequences).
OnSequenceEnd Transform When a sequence ends.
Quest Events Quest state change events.
OnQuestStateChange string When a quest or quest entry state has changed. (Argument is quest name.)
OnQuestTrackingEnabled string When the player has toggled tracking on for a quest.
OnQuestTrackingDisabled string When the player has toggled tracking off for a quest.
UpdateTracker (none) When the Dialogue System needs to update the quest tracker HUD.
Pause Events Events related to pausing and unpausing Dialogue Time.
OnDialogueSystemPause (none) When Dialogue Time is paused.
OnDialogueSystemUnpause (none) When Dialogue Time is unpaused.

Visual Scripting Lua Functions

If you want to invoke a Visual Scripting Custom Event from a dialogue entry node's Script field, add a Dialogue System Visual Scripting Lua component to the Dialogue Manager. This will add the following Lua functions:

Lua Function Description
vsEvent(objectName:string, eventName:string) Invokes a custom event on a GameObject.
vsEventString(objectName:string, eventName:string, arg:string) Invokes a custom event on a GameObject with a string argument.
vsEventBool(objectName:string, eventName:string, arg:bool) Invokes a custom event on a GameObject with a Boolean (true/false) argument.
vsEventFloat(objectName:string, eventName:string, arg:float) Invokes a custom event on a GameObject with a floating point number argument.
vsEventInt(objectName:string, eventName:string, arg:int) Invokes a custom event on a GameObject with an integer argument.

These Lua functions invoke a Visual Scripting Custom Event on a GameObject named objectName.

  • If objectName is blank, it will send the event to the GameObject that has the Dialogue System Visual Scripting Lua component (i.e., the Dialogue Manager).
  • If objectName is "speaker", it will send the event to the current dialogue entry node's speaker, or the Dialogue Manager if no conversation is active.
  • If objectName is "listener", it will send the event to the current dialogue entry node's listener, or the Dialogue Manager if no conversation is active.
  • Otherwise it will send it to the named GameObject.

Visual Scripting Lua Example

Let's say you have a GameObject named "InventoryManager" with a Visual Scripting graph. This graph handles a custom event "AddGold" with an integer argument. To invoke this event in a dialogue entry:

  • Dialogue Text: "Here's your 50gp reward."
  • Script: vsEventInt("InventoryManager", "AddGold", 50)

How To Get Lua Values

To get values such as variables, use a "Dialogue Lua > Get Variable" node. The output of this node will be a Lua Result. Use a "Dialogue System Visual Scripting Lua > Lua Result As *Type*" node to convert it to a basic type such as string, bool, float, or int.

Visual Scripting Sequencer Commands

To send an arbitrary custom event to a Visual Scripting machine, use the VSEvent() sequencer command:

Lua Function Description
VSEvent(eventName, [subject]) Invokes a custom event on a subject. Default subject: speaker.

Note that the order of parameters is different for the VSEvent() sequencer command than for the vsEvent***() Lua functions. This is so you can omit the subject if you want to send the event to the speaker. The capitalization of VS is different, too.


<< Third Party Integration