User Tools

Site Tools


behaviortrees:nodes:treebinding

Tree Binding

Tree Bindings load an additional sub-tree that is set by each AI in the Basic Mind. This allows you to use a more generic tree for AI that are similar, customizing particular parts of the tree per AI.

Attributes

General

  • Node Type: The type of node this is.
  • Name: The name of the node, useful for labeling larger trees.
  • Repeat: Whether or not this node should repeat.
    • Never: The default, the node behaves normally.
    • Until Success: The node will continue to repeat until it returns success.
    • Until Failure: The node will continue to repeat until it returns failure.
    • Forever: The node will continue to repeat forever.
  • Debug Break (for Debugging): When checked, if this node is started while running in the editor, playback will be paused.

Conditional

  • Weight (for Random): How likely this node is to be selected when in a random node.
  • Priority (for Sequencer/Selector): The priority of this node. The highest priority child will be run first.
  • Starting Priority (for Priority): The initial priority of this node when the Priority node first starts.
  • Running Priority (for Priority): The priority of this node while running, refreshed by the Priority node at a set rate.

Tree Binding

  • Binding Name: The name of the binding. The Basic Mind will show this name and allow you to assign a behavior tree to it.

Usage

Tree Binding

Tree Bindings enable you to load sub-trees and run them in your main behavior tree. These sub-trees will run as if they were part of the main tree, and return the result of their root node. The main advantage of this is that it enables you to create smaller, easier to use trees, that can be used by several AI within their main behavior trees.

It can also be helpful for organizing in larger trees, breaking up sections of the tree that are no longer changing and simply getting in the way.

Expressions

Many options on a behavior tree contain expression fields, which allow you to enter an expression instead of a constant value. For instance, an expression field for a target will often take the name of a Navigation Target, a Transform, a GameObject, or Vector3, and an expression allows you to use any of these.

Expression fields will highlight red if there is an error in the expression. For longer expressions it can be easier if you copy the field out into a larger editor.

See Expressions for more information.

Repeating

Aside from the Never option, repeating has three states it can be in, and is available on most nodes in the behavior tree.

Until Success will cause a node to repeat until it returns Success. This can be used for several purposes: waiting for a Detect to succeed, waiting for a particular Mecanim State to occur, waiting for an Expression to be true, etc.

Until Failure will cause a node to repeat until it returns Failure. Essentially this is used for the same things that Until Success is used for. For instance, if an AI was waiting to detect the player before following them, once they started following you could use another Detect, this one repeating until failure, to determine when the AI has lost the player.

Forever will cause a node to always return Running. Much like its name implies, once this node starts it will continue to run forever. A very common setup for this is in a Parallel, where one node repeats forever and the other one eventually returns Failure or Success. A Constraint is also useful for interrupting a node that is repeating forever.

Pitfalls

Multiple Bindings With the Same Name

Binding names must be unique if they are going to contain different trees. Any binding name that is the same will load the same tree and the editor will only show one field.

Binding Within Bindings are Allowed

If a bound tree also contains a tree binding, the Basic Mind will expose that binding to the user as well, allowing you to having many levels of bindings if desired. Binding names still have to be unique though, and while the editor may allow you to assign a tree to its own binding (or a binding in one of its children), they won't be loaded when the main tree loads.

Expressions

Variables are a very useful part of expressions, but are probably the number one pitfall for three reasons:

  • They are case sensitive
  • They are created on demand
  • They can be used when unassigned

This means if you misspell or incorrectly capitalize your variable, it will treat it as an unassigned new variable and not raise an error of any kind. Keeping your variables names short, concise, and easy to spell will keep this from being too much of a problem.

Another problem this can cause is if you intend to use a string but forget the quotes. If it is a multiple word string it will highlight red, which makes it easy to catch, but if it is a single word string it will be considered a variable instead.

behaviortrees/nodes/treebinding.txt · Last modified: 2022/08/13 18:13 (external edit)