Behavior Designer Support

This page describes integration support for Behavior Designer. The Dialogue System's support package provides methods to control Behaviour Designer from within conversations and sequences. Behavior Designer itself has a corresponding support package that allows you to monitor and control the Dialogue System from within behavior trees. (Behavior Designer is required.)

Behavior Designer copyright © Opsive.

How to Set Up Behavior Designer Support

To enable Behavior Designer support in the Dialogue System:

  1. Download and import the Behavior Designer actions for the Dialogue System, which are maintained by Opsive. To access the integration, use Behavior Designer's welcome window (Tools > Behavior Designer > Welcome Window).
  2. Import the package Third Party Support ► Behavior Designer Support.

Behavior Tree Lua Bridge

The Behavior Tree Lua Bridge component synchronizes a behavior tree's shared variables with the Dialogue System's Lua environment. Attach it to the GameObject that contains the behavior tree. (Component → Pixel Crushers → Dialogue System → Third Party → Behavior Designer → Behavior Tree Lua Bridge)

Synchronization occurs automatically at the beginning and end of conversations. You can also synchronize manually by calling SyncToLua() or SyncFromLua(). Only bools, floats, ints, and strings are synchronized.

The Lua variables will have the name gameObjectName_variableName. All blank spaces and hyphens will be converted to underscores.

For example, say an NPC named Private Hart has a behavior tree with a shared variable named Angry. The Lua variable will be Variable["Private_Hart_Angry"].

You can check the value of Variable["Private_Hart_Angry"] in a dialogue entry's Conditions fields and set the value a User Script field.

Behavior Designer Lua Functions

As long as any behavior tree has a Behavior Tree Lua Bridge, the Lua functions below will be available. If no behavior trees have a Behavior Tree Lua Bridge, you can call BehaviorTreeLuaBridge.RegisterLuaFunctions() manually to make them available.

In the '...' Lua wizard dropdowns, these functions are available in Custom > BD.

Lua Function Description Example
bdSyncToLua(gameObjectName) Syncs values of a behavior tree on a GameObject to Lua variables. bdSyncToLua("Player")
bdSyncFromLua(gameObjectName) Syncs Lua variable values back to a behavior tree on a GameObject. bdSyncFromLua("Player")
bdGetBool(gameObjectName, variableName) Gets the value of a behavior tree variable. bool x = bdGetBool("Player", "invincible")
bdGetFloat(gameObjectName, variableName) Gets the value of a behavior tree variable. float x = bdGetFloat("Player", "health")
bdGetInt(gameObjectName, variableName) Gets the value of a behavior tree variable. int x = bdGetInt("Player", "ammo")
bdGetString(gameObjectName, variableName) Gets the value of a behavior tree variable. string x = bdGetString("Player", "name")
bdSetBool(gameObjectName, variableName, value) Sets a behavior tree variable value. bdSetBool("Player", "invincible", true)
bdSetFloat(gameObjectName, variableName, value) Sets a behavior tree variable value. bdSetFloat("Player", "health", 42.57)
bdSetInt(gameObjectName, variableName, value) Sets a behavior tree variable value. bdSetInt("Player", "ammo", 12)
bdSetString(gameObjectName, variableName, value) Sets a behavior tree variable value. bdSetString("Player", "name", "Bob")
bdGetBoolGroup(gameObjectName, group, variableName) Gets the value from a behavior tree with a specified group ID. bool x = bdGetBoolGroup("Player", 42, "invincible")
bdGetFloatGroup(gameObjectName, group, variableName) Gets the value from a behavior tree with a specified group ID. float x = bdGetFloatGroup("Player", 42, "health")
bdGetIntGroup(gameObjectName, group, variableName) Gets the value from a behavior tree with a specified group ID. int x = bdGetIntGroup("Player", 42, "ammo")
bdGetStringGroup(gameObjectName, group, variableName) Gets the value from a behavior tree with a specified group ID. string x = bdGetStringGroup("Player", 42, "name")
bdSetBoolGroup(gameObjectName, group, variableName, value) Sets the value in behavior tree with a specified group ID. bdSetBoolGroup("Player", 42, "invincible", true)
bdSetFloatGroup(gameObjectName, group, variableName, value) Sets the value in behavior tree with a specified group ID. bdSetFloatGroup("Player", 42, "health", 42.57)
bdSetIntGroup(gameObjectName, group, variableName, value) Sets the value in behavior tree with a specified group ID. bdSetIntGroup("Player", 42, "ammo", 12)
bdSetStringGroup(gameObjectName, group, variableName, value) Sets the value in behavior tree with a specified group ID. bdSetStringGroup("Player", 42, "name", "Bob")

Behavior Designer Sequencer Commands

The support package adds two sequencer commands. You can use these commands within conversations, barks, and other sequences to control behavior trees.

Behavior()

Syntax: Behavior(subject, start|stop|pause|resume, [group])

Description: Controls a Behavior Designer behavior tree.

Parameters:

  • subject: The name of a GameObject containing a behavior tree, or speaker or listener. The behavior tree can be located on a child object.
  • start|stop|pause|resume: Control action for the behavior tree.
    • start: Starts or restarts the behavior tree.
    • stop: Stops the behavior tree.
    • pause: Pauses the behavior tree.
    • resume: Resumes the behavior tree if paused.
  • group: (Optional) Apply to behavior trees with a specific group ID. If omitted, apply to all behavior trees on subject.

Example:

  • Behavior(Sergeant Graves, start) (Starts the behavior tree on Sergeant Graves)
  • Behavior(Terminal, pause) (Pauses the behavior tree on Terminal)

BehaviorVariable()

Syntax: BehaviorVariable(subject, variableName, value)

Description: Sets the value of a behavior tree's shared variable.

Parameters:

  • subject: The name of a GameObject containing a behavior tree, or speaker or listener. The behavior tree can be located on a child object.
  • variableName: The name of a shared variable on the behavior tree. These variable types are supported: Bool, Float, Int, String, GameObject, Object, Transform, Vector3.
  • value: The new value of the variable.

Example:

  • BehaviorVariable(Sergeant Graves, target, speaker) (On Sergeant Graves' behavior tree, sets the variable target to the speaker)
  • Behavior(Terminal, overheating, true) (On Terminal's behavior tree, sets the variable overheating to true)

<< Third Party Integration