# new RezBehaviour()
Represents a node in the Rez game engine's behaviour tree system. Behaviours are reusable templates that define game logic and can be composed into trees with parent-child relationships.
Template vs Instance
Behaviours follow a template-instance pattern:
- Templates are defined in Rez source with
@behaviourand registered globally - Instances are created via
instantiate()with specific owner, options, and children - Templates are never executed directly; always instantiate first
Tree Structure
Behaviours form trees through the children property:
- Each behaviour can have zero or more child behaviours
- Parent behaviours control execution flow (sequence, selector, etc.)
- Leaf behaviours perform actual actions
Execution
Behaviours execute via the execute attribute function:
- Must return a boolean:
truefor success,falsefor failure - The behaviour instance is passed as the first argument
- Access the owner object via
this.owner
Options
Options allow parameterizing behaviour instances:
- Set during instantiation
- Retrieved via
option(),numberOption(),intOption() - Enable reusing the same behaviour template with different configurations
Configuration
The optional configure attribute function runs after instantiation:
- Receives the behaviour instance
- Used for setup that depends on options or owner
Usage in Rez
Behaviour trees are typically attached to objects via the bht: attribute prefix,
which automatically instantiates the tree with the object as owner.
Extends
Methods
# childCount() → {number}
Returns the count of child behaviours attached to this behaviour
the number of child behaviours
number
# children(children)
Sets the child behaviours for this behaviour node.
Parameters:
| Name | Type | Description |
|---|---|---|
children |
Array.<RezBehaviour>
|
array of child behaviour instances |
# configure()
Runs the behaviour's configuration function if defined. This is called during instantiation to set up behaviour-specific configuration.
# constructor(id, attributes)
Creates a new behaviour template with empty options and children
Parameters:
| Name | Type | Description |
|---|---|---|
id |
string
|
unique identifier for this behaviour |
attributes |
object
|
behaviour attributes from Rez compilation |
- Overrides:
# executeBehaviour() → {boolean}
Executes this behaviour using the owner's blackboard for context.
if the execute function returns an invalid result format
Error
true if the behaviour succeeded, false otherwise
boolean
# firstChild() → {RezBehaviour|undefined}
Convenience accessor for the first child behaviour
the first child behaviour or undefined if no children
RezBehaviour
|
undefined
# getChildAt(idx) → {RezBehaviour|undefined}
Gets a child behaviour by index
Parameters:
| Name | Type | Description |
|---|---|---|
idx |
number
|
the index of the child to retrieve |
the child behaviour at the specified index
RezBehaviour
|
undefined
# instantiate(owner, options, children) → {RezBehaviour}
Creates a new instance of this behaviour template with the specified owner, options, and children. The instance is configured after creation.
Parameters:
| Name | Type | Description |
|---|---|---|
owner |
object
|
the object that owns this behaviour instance |
options |
object
|
options to configure this behaviour instance |
children |
Array.<RezBehaviour>
|
child behaviours for this instance |
a new configured behaviour instance
# intOption(name) → {number}
Gets an option value as an integer (floors any decimal values)
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string
|
the option name to retrieve |
the option value as an integer
number
# numberOption(name) → {number}
Gets an option value and ensures it's a number
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string
|
the option name to retrieve |
if the option is not defined or not a number
Error
the option value as a number
number
# option(name) → {*}
Gets an option value by name
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string
|
the option name to retrieve |
if the option is not defined
Error
the option value
*
# options(options)
Sets the options for this behaviour instance.
Parameters:
| Name | Type | Description |
|---|---|---|
options |
object
|
options to configure this behaviour |
# secondChild() → {RezBehaviour|undefined}
Convenience accessor for the second child behaviour
the second child behaviour or undefined if fewer than 2 children
RezBehaviour
|
undefined
# setOption(name, value)
Sets an option value by name
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string
|
the option name to set |
value |
*
|
the value to set |