Class

RezBehaviour

RezBehaviour()

Constructor

# 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 @behaviour and 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: true for success, false for 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.

View Source rez_behaviour.js, line 5

Extends

Methods

# childCount() → {number}

Returns the count of child behaviours attached to this behaviour

View Source rez_behaviour.js, line 124

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

View Source rez_behaviour.js, line 74

# configure()

Runs the behaviour's configuration function if defined. This is called during instantiation to set up behaviour-specific configuration.

View Source rez_behaviour.js, line 134

# 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:

View Source rez_behaviour.js, line 50

# executeBehaviour() → {boolean}

Executes this behaviour using the owner's blackboard for context.

View Source rez_behaviour.js, line 213

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

View Source rez_behaviour.js, line 104

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

View Source rez_behaviour.js, line 201

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

View Source rez_behaviour.js, line 235

a new configured behaviour instance

RezBehaviour

# 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

View Source rez_behaviour.js, line 179

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

View Source rez_behaviour.js, line 163

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

View Source rez_behaviour.js, line 147

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

View Source rez_behaviour.js, line 94

# secondChild() → {RezBehaviour|undefined}

Convenience accessor for the second child behaviour

View Source rez_behaviour.js, line 114

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

View Source rez_behaviour.js, line 190