AI Tree
  • 🏡Home
  • ⭐Getting Started
  • Basic
    • Behaviour Tree
      • Node
      • Decorator
      • Service
    • Blackboard
      • Key (Variable)
    • Perception System
    • Environment Query System
    • Quick Start
    • User Guide
    • Shortcuts
  • Navigation
    • Building a NavMesh
  • Nodes
    • Composite
      • Sequencer
      • Selector
        • Selector
        • Random Selector
      • Parallel
        • Parallel
        • Parallel Selector
        • Parallel Complete
    • Tasks
      • Animator
        • Cross Fade
        • Cross Fade in Fixed time
        • Set Bool
        • Set Float
        • Set Integer
        • Set Trigger
      • Audio
        • Audio Mute
        • Audio Pause
        • Audio Play
        • Audio Stop
        • Play Random Sound
        • Play Sound
        • Set Audio Clip
        • Set Audio Loop
        • Set Audio Pitch
        • Set Audio Volume
      • Audio Source
        • Play Clip At Point
      • Debug
        • Debug Log
        • Debug Draw Line
        • Debug Draw Ray
      • Common
        • Wait
        • Set Key
        • Run Behaviour
        • Wait Blackboard Time
        • Finish With Result
      • EQS
        • Run EQS Query
      • Game Object
        • Activate
        • Add Component
        • Create Object
        • Destroy Component
        • Destroy Object
        • Destroy Self
        • Detach Children
        • Find
        • Find Child
        • Find Closest
        • Get Child
        • Get Child Count
        • Get Distance
        • Get Parent
        • Get Root
        • Get Tag
        • Get Name
        • Set Parent
        • Set Tag
      • Math
        • Bool Flip
        • Bool Operator
        • Float Abs
        • Float Clamp
        • Float Operator
        • Int Abs
        • Int Clamp
        • Int Operator
        • Random Bool
        • Random Float
        • Random Int
        • Sample Curve
        • Get ACos
        • Get ASin
        • Get Atan
        • Get Atan2
        • Get Atan2 From Vector2
        • Get Atan2 From Vector3
        • Get Cos
        • Get Sin
        • Get Tan
      • Movement
        • Move Towards
        • Way Point
      • NavMesh
        • Move To
        • Random Position
      • Object
        • Destroy
        • Instantiate
      • Perception System
        • Detection Signal
      • Physics
        • Box Cast
        • Capsule Cast
        • Line Cast
        • Ray Cast
        • Sphere Cast
      • Physics2D
        • Box Cast 2D
        • Capsule Cast 2D
        • Line Cast 2D
        • Ray Cast 2D
        • Sphere Cast 2D
      • Player Prefs
        • Delete All
        • Delete Key
        • Get Float
        • Get Int
        • Get String
        • Set Float
        • Set Int
        • Set String
      • Quaternion
        • Angle Axis
        • Euler
        • From To Rotation
        • Get Euler Angles
        • Inverse
        • Multiply
        • Multiply By Vector
      • Rigidbody
        • Add Explosion Force
        • Add Force
        • Add Force At Position
        • Add Relative Force
        • Add Relative Torque
        • Add Torque
        • Move Position
        • Move Rotation
        • Sleep
        • Wake Up
      • Rigidbody2D
        • Add Force 2D
        • Add Force At Position 2D
        • Add Relative Force 2D
        • Add Torque 2D
        • Move Position 2D
        • Move Rotation 2D
        • Sleep 2D
        • Wake Up 2D
      • Transform
        • Get Angle To Target
        • Get Position
        • Get Rotation
        • Inverse Transform Direction
        • Set Scale
        • Inverse Transform Point
        • Transform Direction
        • Transform Point
      • Vector2
        • Add
        • Add XY
        • Clamp Magnitude
        • Get Length
        • Get XY
        • Invert
        • Select Random
        • Set Value
        • Set XY
      • Vector3
        • Add
        • Add XYZ
        • Clamp Magnitude
        • Get Length
        • Get XYZ
        • Invert
        • Select Random
        • Set Value
        • Set XYZ
      • Unity
        • Debug
        • Send Message
        • Find Transfrom
    • Decorators
      • Blackboard Condition
      • Compare Blackboard Keys
      • Conditional Loop
      • Cone Check
      • Inverter
      • Is At Location
      • Loop
      • Has Path
      • Object Tag Condition
      • One Time Execution
      • Succeeder
      • Time Limit
  • Perception System
    • Quick Start
    • Useful Components
      • AI Perception Blackboard
      • AI Perception Source
    • Useful Nodes
  • Environment Query System
    • Quick Start
    • Items
    • Useful Components
      • EQS Tester
    • Useful Objects
      • Environment Query
        • Generator
          • Circle
          • Cone
          • Donut
          • Grid
        • Trace Mode
          • Layer
          • NavMesh
        • Tests
          • Distance
          • Dot
          • Has Path
          • Overlap
          • Slope
          • Trace
    • Useful Nodes
  • API
    • Overview
    • User Scripting
      • Custom Task
      • Custom Key
      • ToolbarItem attribute
    • Runtime
      • BehaviourTree
      • BehaviourRunner
      • Blackboard
      • Key
      • Key<T>
      • KeyQuery
      • KeyQuery<T>
      • KeyReceiver
      • KeyReceiver<T>
      • Task Node
      • Decorator Node
      • Condition Decorator
      • Observer Decorator
      • Service Node
      • Interval Service Node
      • NodeContentAttribute
      • AIPerceptionConfig
      • EQGenerator
      • EQTraceMode
      • EQTest
  • INTEGRATIONS
    • Adventure Creator
    • A* Pathfinding Project Pro
      • Move To
    • Dialogue System for Unity
      • Lua Condition Decorator
      • Lua Run
      • Dialogue Behaviour Handler
      • Blackboard Saver
      • Lua Functions
    • Mirror Network
      • Quick Start
      • Network Instantiate
      • Network Destroy
      • Network Play Clip At Point
      • Network Debug
    • Photon Network
      • Quick Start
      • Network Instantiate
      • Network Destroy
      • Network Play Clip At Point
      • Network Debug
    • PlayMaker
      • Set Runner Active
      • Set Perception Active
      • Get Blackboard Key
      • Set Blackboard Key
    • Sensor Toolkit 2
      • Sensor Config
    • Ultimate Horror FPS KIT
      • Quick Start
      • Apply Damage
      • Animator Event Disabler
    • Odin Inspector
Powered by GitBook
On this page
  • Public Methods
  • Clone()
  • GetBlackboard()
  • GetUpdateMode()
  • SetUpdateMode(UpdateMode mode)
  • GetTickRate()
  • SetTickRate(int count)
  • IsRunning()
  • GetRootNode()
  • GetNodes()
  • SetNodes(List<Node> value)
  • GetCurrentNode()
  • Static
  • TraversePath(Node node, Node searchingNode)
  • Traverse(Node node, Action<Node> visiter)
  • GetChildren(Node node)
  • IterateChildren(Node node)
  • IsSubNode(Node node, Node checkNode)
  • Create(string name)
  • Protected Virtual Methods
  • OnEnable()
  • Reset()
  1. API
  2. Runtime

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:

BehaviourTree clonedTree = originalTree.Clone();

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:

Blackboard blackboard = behaviourTree.GetBlackboard();

GetUpdateMode()

Description: Retrieves the current update mode for the behavior tree.

Returns: UpdateMode — The current update mode (e.g., Update, FixedUpdate, LateUpdate, Custom).

Example:

UpdateMode mode = behaviourTree.GetUpdateMode();

SetUpdateMode(UpdateMode mode)

Description: Sets the update mode for the behavior tree.

Parameters: UpdateMode mode — The desired update mode.

Example:

behaviourTree.SetUpdateMode(UpdateMode.Update);

GetTickRate()

Description: Retrieves the tick rate, which defines how often the behavior tree updates.

Returns: int — The number of ticks per second.

Example:

int tickRate = behaviourTree.GetTickRate();

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:

behaviourTree.SetTickRate(5);

IsRunning()

Description: Checks whether the behavior tree is currently running.

Returns: bool — true if the tree is running, false otherwise.

Example:

bool isRunning = behaviourTree.IsRunning();

GetRootNode()

Description: Retrieves the root node of the behavior tree.

Returns: Node — The root node of the behavior tree.

Example:

Node rootNode = behaviourTree.GetRootNode();

GetNodes()

Description: Returns the list of all nodes in the behavior tree.

Returns: List<Node> — The list of all nodes.

Example:

List<Node> nodes = behaviourTree.GetNodes();

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:

behaviourTree.SetNodes(new List<Node> { node1, node2 });

GetCurrentNode()

Description: Returns the currently executing node.

Returns: Node — The node currently being executed.

Example:

Node currentNode = behaviourTree.GetCurrentNode();

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:

LinkedList<Node> path = BehaviourTree.TraversePath(startNode, targetNode);

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:

BehaviourTree.Traverse(rootNode, node => Debug.Log(node.Name));

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:

List<Node> children = BehaviourTree.GetChildren(parentNode);

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:

foreach (var child in BehaviourTree.IterateChildren(parentNode))
{
    Debug.Log(child.Name);
}

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:

bool isSubNode = BehaviourTree.IsSubNode(parentNode, childNode);

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:

#if UNITY_EDITOR
    BehaviourTree newTree = BehaviourTree.Create("New AI Tree");
#endif

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:

protected override void OnEnable()
{
    base.OnEnable();
    Debug.Log("Behaviour Tree Loaded");
}

Reset()

Description: Called when the user presses the Reset button in the Inspector, or when the component is first added.

Example:

protected override void Reset()
{
    base.Reset();
    Debug.Log("Behaviour Tree Reset");
}

Last updated 6 months ago