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
  • GetSharedBehaviourTree()
  • SetSharedBehaviourTree(BehaviourTree tree)
  • GetBehaviourTree()
  • GetSharedBlackboard()
  • GetBlackboard()
  • Protected Virtual Methods
  • Awake()
  • Start()
  • Update()
  • FixedUpdate()
  • LateUpdate()
  • OnDestroy()
  • OnDrawGizmos()
  • OnDrawGizmosSelected()
  • Events Callbacks
  • OnCloneTreeCompleted
  1. API
  2. Runtime

BehaviourRunner

class in RenownedGames.AITree / Inherits from MonoBehaviour

The main component to run created behaviour tree assets. Use Behaviour Runner component to access associated behaviour tree and blackboard of related AI entity at the scene.

Public Methods

GetSharedBehaviourTree()

Description: Get shared reference of behaviour tree.

Returns: Shared reference of behaviour tree.

Example:

BehaviourRunner runner = ai.GetComponent<BehaviourRunner>();
BehaviourTree behaviourTree = runner.GetSharedBehaviourTree();

SetSharedBehaviourTree(BehaviourTree tree)

Description: Set new shared behaviour tree reference.

This action will stop the execution of the current behavior tree and terminate it. The work of the tree, its state and the values of the keys in the blackboard will be destroyed and overwritten by the new tree. This action is irreversible!

Parameters: Reference of behaviour tree.

Example:

BehaviourRunner runner = ai.GetComponent<BehaviourRunner>();
BehaviourTree behaviourTree = runner.SetSharedBehaviourTree(newTree);

GetBehaviourTree()

Description: Associated instance of behaviour tree.

Returns: Associated (local) instance of behaviour tree created by runner after loading.

Example:

BehaviourRunner runner = ai.GetComponent<BehaviourRunner>();
BehaviourTree behaviourTree = runner.GetBehaviourTree();
Node rootNode behaviourTree.GetRootNode();

GetSharedBlackboard()

Description: Get shared reference of blackboard

Returns: Shared reference of blackboard.

Example:

BehaviourRunner runner = ai.GetComponent<BehaviourRunner>();
Blackboard blackboard = runner.GetSharedBlackboard();

GetBlackboard()

Description: Associated instance of blackboard.

Returns: Associated (local) instance of blackboard created by runner after loading.

Example:

BehaviourRunner runner = ai.GetComponent<BehaviourRunner>();
Blackboard  blackboard = runner.GetBlackboard();
if(blackboard.TryGetKey<float>("speed", out FloatKey key))
{
    key.SetValue(10);
}

Protected Virtual Methods

Use the following methods only for overriding when inheritance, it is not recommended not to call these methods manually.

Awake()

Description: Called when an enabled script instance is being loaded.

Example:

protected override void Awake()
{
    base.Awake();
    Debug.Log("Runner fully loaded");
}

Start()

Description: Called on the frame when a script is enabled, just before any of the Update methods are called the first time.

Example:

protected override void Start()
{
    base.Start();
    Debug.Log("Runner started the tree");
}

Update()

Description: Called every frame, if the Behaviour is enabled.

Keep in mind it's Unity pipeline update call, not of selected behaviour tree update mode.

Example:

protected override void Update()
{
    base.Update();
    // Todo you code here...
}

FixedUpdate()

Description: Called every fixed frame-rate frame. 0.02 seconds (50 calls per second) is the default time between calls, if the Behaviour is enabled.

Keep in mind it's Unity pipeline fixed update call, not of selected behaviour tree update mode.

Example:

protected override void FixedUpdate()
{
    base.FixedUpdate();
    // Todo you code here...
}

LateUpdate()

Description: Called every frame, if the Behaviour is enabled after all Update calls.

Keep in mind it's Unity pipeline late update call, not of selected behaviour tree update mode.

Example:

protected override void LateUpdate()
{
    base.LateUpdate();
    // Todo you code here...
}

OnDestroy()

Description: Called when an enabled script instance is being destroyed.

At this point, the associated instance of the behavior tree and the blackboard is still present and can be safely invoked.

Example:

protected override void OnDestroy()
{
    base.OnDestroy();
    Debug.Log("Runner stopped the tree");
}

OnDrawGizmos()

Description: Implement if you want to draw gizmos that are also pickable and always drawn.

Example:

protected override void OnDrawGizmos()
{
    base.OnDrawGizmos();
    // Todo your code here...
}

OnDrawGizmosSelected()

Description: Implement to draw a gizmos if the object is selected.

Example:

protected override void OnDrawGizmosSelected()
{
    base.OnDrawGizmosSelected();
    // Todo your code here...
}

Events Callbacks

OnCloneTreeCompleted

Description: Called when behaviour runner complete cloning of shared beahviour tree.

This callback can be used for making some custom actions with tree before starting the tree of specified AI.

Example:

private void SomeMethod()
{
    // AI entity and runner component disabled (sleeping) at this point.
    BehaviourRunner runner = ai.GetComponent<BehaviourRunner>();
    runner.OnCloneTreeCompleted += OnCloneTreeCompleted;
}

private void OnCloneTreeCompleted(BehaviourTree tree)
{
    List<Node> nodes = tree.GetNodes();
    foreach(Node node in nodes)
    {
        // Just example...
    }
}

Last updated 6 months ago