This page explains how to use Unity's Visual Scripting package with the Dialogue System.
Note:
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. |
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.
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:
vsEventInt("InventoryManager", "AddGold", 50)
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.
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.