BehaviourTree
class in RenownedGames.AITree / Inherits from ScriptableObject
The BehaviourTree class is responsible for defining, managing, and controlling the behavior trees used in AI logic.
Public Methods
Clone()
Description: Clones the entire behavior tree, including all nodes and settings.
Returns:
BehaviourTree
— A new cloned copy of the behavior tree.
Example:
GetBlackboard()
Description: Shared Blackboard reference associated with this behaviour tree reference
Returns:
Blackboard
— The blackboard used by this behavior tree.
Always return shared reference of blackboard. If you need blackboard instance see BehaviourRunner
Example:
GetUpdateMode()
Description: Retrieves the current update mode for the behavior tree.
Returns:
UpdateMode
— The current update mode (e.g., Update, FixedUpdate, LateUpdate, Custom).
Example:
SetUpdateMode(UpdateMode mode)
Description: Sets the update mode for the behavior tree.
Parameters:
UpdateMode mode
— The desired update mode.
Example:
GetTickRate()
Description: Retrieves the tick rate, which defines how often the behavior tree updates.
Returns:
int
— The number of ticks per second.
Example:
SetTickRate(int count)
Description: Sets the tick rate for how often the behavior tree should update.
Parameters:
int count
— The number of ticks per second.
Example:
IsRunning()
Description: Checks whether the behavior tree is currently running.
Returns:
bool
— true
if the tree is running, false
otherwise.
Example:
GetRootNode()
Description: Retrieves the root node of the behavior tree.
Returns:
Node
— The root node of the behavior tree.
Example:
GetNodes()
Description: Returns the list of all nodes in the behavior tree.
Returns:
List<Node>
— The list of all nodes.
Example:
SetNodes(List<Node> value)
Description: Sets the list of nodes in the behavior tree.
Parameters:
List<Node> value
— The list of nodes to assign.
Example:
GetCurrentNode()
Description: Returns the currently executing node.
Returns:
Node
— The node currently being executed.
Example:
Static
TraversePath(Node node, Node searchingNode)
Description: Traverses the path from a specified node to a target node.
Parameters:
Node node
— The starting node.
Node searchingNode
— The target node to find.
Returns:
LinkedList<Node>
— The path of nodes leading to the target.
Example:
Traverse(Node node, Action<Node> visiter)
Not recommended. This method is obsolete.
Use Node.Traverse() implementation.
Description:
Traverses all nodes from the target node with a visitor callback. Note: This method is obsolete; use Node.Traverse()
instead.
Parameters:
Node node
— The starting node.
Action<Node> visiter
— The callback to apply to each node.
Example:
GetChildren(Node node)
Description: Returns all child nodes of a given node.
Parameters:
Node node
— The parent node.
Returns:
List<Node>
— The list of child nodes.
Example:
IterateChildren(Node node)
Description: Iterates through all child nodes of a given node.
Parameters:
Node node
— The parent node.
Returns:
IEnumerable<Node>
— An enumerable collection of child nodes.
Example:
IsSubNode(Node node, Node checkNode)
Description: Checks if a node is a sub-node of another node.
Parameters:
Node node
— The parent node.
Node checkNode
— The potential sub-node.
Returns:
bool
— true
if checkNode
is a sub-node of node
, false
otherwise.
Example:
Create(string name)
Editor only!
If you call this method in build code block, wrap it in UNITY_EDITOR
define.
Description: Creates a new behavior tree asset in the project.
Parameters:
string name
— The name of the new behavior tree asset.
Example:
Protected Virtual Methods
Use the following methods only for overriding when inheritance, it is not recommended not to call these methods manually.
OnEnable()
Description: Called when the behavior tree is loaded.
Example:
Reset()
Description: Called when the user presses the Reset button in the Inspector, or when the component is first added.
Example:
Last updated