UBehaviorTreeComponent

Windows
MacOS
Linux

Inheritance Hierarchy

References

Module

AIModule

Header

/Engine/Source/Runtime/AIModule/Classes/BehaviorTree/BehaviorTreeComponent.h

Include

#include "BehaviorTree/BehaviorTreeComponent.h"

Syntax

class UBehaviorTreeComponent : public UBrainComponent

Variables

Name Description

Protected variable

float

 

AccumulatedTickDeltaTime

Accumulated DeltaTime if ticked more than predicted next delta time

Protected variable

uint16

 

ActiveInstanceIdx

Index of last active instance on stack

Protected variable

uint8: 1

 

bDeferredStopTree

If set, StopTree will be called at the end of tick

Protected variable

uint8: 1

 

bIsPaused

If set, execution requests will be postponed

Protected variable

uint8: 1

 

bIsRunning

If set, tree execution is allowed

Protected variable

uint8: 1

 

bLoopExecution

Loops tree execution

Protected variable

uint8: 1

 

bRequestedFlowUpdate

Set when execution update is scheduled for next tick

Protected variable

uint8: 1

 

bRequestedStop

Set when tree stop was called

Protected variable

bool

 

bTickedOnce

Used to tell tickmanager that we want interval ticking

Protected variable

uint8: 1

 

bWaitingForAbortingTasks

Set when execution is waiting for tasks to abort (current or parallel's main)

Protected variable

TMap< FGameplay...

 

CooldownTagsMap

Behavior cooldowns mapped by tag to last time it was set

Protected variable

TArray< TArray<...

 

CurrentRestarts

Protected variable

TArray< TArray<...

 

CurrentSearchFlow

Search flow for debugger

Protected variable

TArray< FBehavi...

 

DebuggerSteps

Debugger's recorded data

Protected variable

UBehaviorTree &...

 

DefaultBehaviorTreeAsset

Data asset defining the tree

Protected variable

FBTNodeExecutio...

 

ExecutionRequest

Execution request, search will be performed when current task finish execution/aborting

Protected variable

friend

 

FBehaviorTreeDebugger

Protected variable

friend

 

FBehaviorTreeInstance

Protected variable

friend

 

FScopedBehaviorTreeLock

Protected variable

TArray< FBehavi...

 

InstanceStack

Stack of behavior tree instances

Protected variable

TArray< FBehavi...

 

KnownInstances

List of known subtree instances

Protected variable

float

 

LastRequestedDeltaTimeGameTime

GameTime of the last DeltaTime request, used for debugging to output warnings about ticking

Protected variable

float

 

NextTickDeltaTime

Predicted next DeltaTime

Protected variable

TArray< UBTNode...

 

NodeInstances

Instanced nodes

Protected variable

FBTPendingExecu...

 

PendingExecution

Result of ExecutionRequest, will be applied when current task finish aborting

Protected variable

FBTPendingAuxNo...

 

PendingUnregisterAuxNodesRequests

List of all pending aux nodes unregistration requests

Protected variable

TArray< FBehavi...

 

RemovedInstances

Protected variable

FBehaviorTreeSe...

 

SearchData

Search data being currently used

Protected variable

TMap< FName, FS...

 

SearchStartBlackboard

Protected variable

uint8

 

StopTreeLock

If set, StopTree calls will be deferred

Protected variable

TMultiMap< FBTN...

 

TaskMessageObservers

Message observers mapped by instance & execution index

Protected variable

FBTTreeStartInf...

 

TreeStartInfo

Stored data for starting new tree, waits until previously running finishes aborting

Protected variable

friend

 

UBTCompositeNode

Protected variable

friend

 

UBTNode

Protected variable

friend

 

UBTTask_RunBehavior

Protected variable

friend

 

UBTTask_RunBehaviorDynamic

Protected variable

friend

 

UBTTaskNode

Constructors

Name Description

Public function

UBehaviorTreeComponent

(
    const FObjectInitializer& ObjectIn...
)

Public function

UBehaviorTreeComponent

(
    FVTableHelper& Helper
)

DO NOT USE. This constructor is for internal usage only for hot-reload purposes.

Functions

Name Description

Protected function

void

 

AbortCurrentTask()

Abort currently executed task

Public function

void

 

AddCooldownTagDuration

(
    FGameplayTag CooldownTag,
    float CooldownDuration,
    bool bAddToExistingDuration
)

Add to the cooldown tag's duration

Protected function

void

 

ApplyDiscardedSearch()

Apply pending node updates required for discarded search

Protected function

void

 

ApplySearchData

(
    UBTNode* NewActiveNode
)

Apply pending node updates from SearchData

Protected function

void

 

ApplySearchUpdates

(
    const TArray< FBehaviorTreeSearchUp...,
    int32 NewNodeExecutionIndex,
    bool bPostUpdate
)

Apply updates from specific list

Protected function Const

EBTNodeRelat...

 

CalculateRelativePriority

(
    const UBTNode* NodeA,
    const UBTNode* NodeB
)

Return NodeA's relative priority in regards to NodeB

Protected function

void

 

CopyInstanceMemoryFromPersistent()

Copy memory block from persistent memory to running instances (rollback)

Protected function

void

 

CopyInstanceMemoryToPersistent()

Copy memory block from running instances to persistent memory

Protected function

bool

 

DeactivateUpTo

(
    UBTCompositeNode* Node,
    uint16 NodeInstanceIdx,
    EBTNodeResult::Type& NodeResult,
    int32& OutLastDeactivatedChildInde...
)

Deactivate all nodes up to requested one

Public function Virtual Const

FString

 

DescribeActiveTasks()

Public function Virtual Const

FString

 

DescribeActiveTrees()

Public function Static

void

 

EndFrame()

Code for timing BT Search for FramePro.

Protected function

void

 

ExecuteTask

(
    UBTTaskNode* TaskNode
)

Execute new task

Public function Const

int32

 

FindInstanceContainingNode

(
    const UBTNode* Node
)

Tries to find behavior tree instance in context

Protected function

UBTTaskNode ...

 

FindNextTask

(
    UBTCompositeNode* ParentNode,
    uint16 ParentInstanceIdx,
    EBTNodeResult::Type LastResult
)

Find next task to execute

Public function Const

UBTNode *...

 

FindTemplateNode

(
    const UBTNode* Node
)

Tries to find template node for given instanced node

Public function Const

uint16

 

GetActiveInstanceIdx()

Get index of active instance on stack

Public function Const

const UBTNod...

 

GetActiveNode()

Public function Const

UBehaviorTre...

 

GetCurrentTree()

Public function Const

uint8 *

 

GetNodeMemory

(
    UBTNode* Node,
    int32 InstanceIdx
)

Public function Const

UBehaviorTre...

 

GetRootTree()

Public function Const

float

 

GetTagCooldownEndTime

(
    FGameplayTag CooldownTag
)

Public function Const

EBTTaskStatu...

 

GetTaskStatus

(
    const UBTTaskNode* TaskNode
)

Public function Const

bool

 

IsAbortPending()

Public function Const

bool

 

IsAuxNodeActive

(
    const UBTAuxiliaryNode* AuxNod...,
    int32 InstanceIdx
)

Public function Const

bool

 

IsAuxNodeActive

(
    const UBTAuxiliaryNode* AuxNod...
)

Protected function Static

bool

 

IsDebuggerActive()

Check if debugger is currently running and can gather data

Public function Const

bool

 

IsExecutingBranch

(
    const UBTNode* Node,
    int32 ChildIndex
)

Public function Const

bool

 

IsInstanceStackEmpty()

Returns true if InstanceStack contains any BT runtime instances

Public function Const

bool

 

IsRestartPending()

Public function

void

 

OnTaskFinished

(
    const UBTTaskNode* TaskNode,
    EBTNodeResult::Type TaskResult
)

Finish latent execution or abort

Protected function

void

 

OnTreeFinished()

Called when tree runs out of nodes to execute

Public function

void

 

ProcessExecutionRequest()

Process execution flow

Protected function

void

 

ProcessPendingExecution()

Apply pending execution from last task search

Protected function

void

 

ProcessPendingInitialize()

Apply pending tree initialization

Protected function

bool

 

ProcessPendingUnregister()

Apply pending unregister aux nodes requests

Protected function

bool

 

PushInstance

(
    UBehaviorTree& TreeAsset
)

Push behavior tree instance on execution stack : should never be called out-side of BT execution, meaning only BT tasks can push another BT instance!

Public function

void

 

RegisterMessageObserver

(
    const UBTTaskNode* TaskNode,
    FName MessageType,
    FAIRequestID MessageID
)

Setup message observer for given task

Public function

void

 

RegisterMessageObserver

(
    const UBTTaskNode* TaskNode,
    FName MessageType
)

Setup message observer for given task

Public function

void

 

RegisterParallelTask

(
    const UBTTaskNode* TaskNode
)

Add active parallel task

Protected function

void

 

RemoveAllInstances()

Remove instanced nodes, known subtree instances and safely clears their persistent memory

Public function

void

 

RequestExecution

(
    const UBTDecorator* RequestedB...
)

Request execution change: helpers for decorator nodes

Public function

void

 

RequestExecution

(
    EBTNodeResult::Type ContinueWithRes...
)

Request execution change: helpers for task nodes

Public function

void

 

RequestExecution

(
    UBTCompositeNode* RequestedOn,
    int32 InstanceIdx,
    const UBTNode* RequestedBy,
    int32 RequestedByChildIndex,
    EBTNodeResult::Type ContinueWithRes...,
    bool bStoreForDebugger
)

Request execution change

Public function

void

 

RequestUnregisterAuxNodesInBranch

(
    const UBTCompositeNode* Node
)

Request unregistration of aux nodes in the specified branch

Public function

void

 

RestartTree()

Restarts execution from root

Protected function

void

 

RollbackSearchChanges()

Restore state of tree to state before search

Public function

void

 

ScheduleExecutionUpdate()

Schedule execution flow update in next tick

Public function

void

 

ScheduleNextTick

(
    float NextDeltaTime
)

END UActorComponent overrides Schedule when will be the next tick, 0.0f means next frame, FLT_MAX means never

Public function Virtual

void

 

SetDynamicSubtree

(
    FGameplayTag InjectTag,
    UBehaviorTree* BehaviorAsset
)

Assign subtree to RunBehaviorDynamic task specified by tag

Public function

void

 

StartTree

(
    UBehaviorTree& Asset,
    EBTExecutionMode::Type ExecuteMode
)

Starts execution from root

Public function

void

 

StopTree

(
    EBTStopMode::Type StopMode
)

Stops execution

Protected function Const

void

 

StoreDebuggerBlackboard

(
    TMap< FName, FString >& Blackboard...
)

Describe blackboard's key values

Protected function

void

 

StoreDebuggerExecutionStep

(
    EBTExecutionSnap::Type SnapType
)

Make a snapshot for debugger

Protected function Const

void

 

StoreDebuggerInstance

(
    FBehaviorTreeDebuggerInstance& Ins...,
    uint16 InstanceIdx,
    EBTExecutionSnap::Type SnapType
)

Make a snapshot for debugger from given subtree instance

Protected function Const

void

 

StoreDebuggerRemovedInstance

(
    uint16 InstanceIdx
)

Protected function

void

 

StoreDebuggerRestart

(
    const UBTNode* Node,
    uint16 InstanceIdx,
    bool bAllowed
)

Store restarting node for debugger

Protected function Const

void

 

StoreDebuggerRuntimeValues

(
    TArray< FString >& RuntimeDescript...,
    UBTNode* RootNode,
    uint16 InstanceIdx
)

Gather nodes runtime descriptions

Protected function Const

void

 

StoreDebuggerSearchStep

(
    const UBTNode* Node,
    uint16 InstanceIdx,
    bool bPassed
)

Store search step for debugger

Protected function Const

void

 

StoreDebuggerSearchStep

(
    const UBTNode* Node,
    uint16 InstanceIdx,
    EBTNodeResult::Type NodeResult
)

Store search step for debugger

Public function Const

bool

 

TreeHasBeenStarted()

Indicates instance has been initialized to work with specific BT asset

Public function

void

 

UnregisterAuxNodesInRange

(
    const FBTNodeIndex& FromIndex,
    const FBTNodeIndex& ToIndex
)

Unregister all aux nodes between given execution index range: FromIndex < AuxIndex < ToIndex

Public function

void

 

UnregisterAuxNodesUpTo

(
    const FBTNodeIndex& Index
)

Unregister all aux nodes less important than given index

Public function

void

 

UnregisterMessageObserversFrom

(
    const UBTTaskNode* TaskNode
)

Remove message observers registered with task

Public function

void

 

UnregisterMessageObserversFrom

(
    const FBTNodeIndex& TaskIdx
)

Remove message observers registered with task

Public function

void

 

UnregisterParallelTask

(
    const UBTTaskNode* TaskNode,
    uint16 InstanceIdx
)

Remove parallel task

Protected function

void

 

UpdateAbortingTasks()

Update state of aborting tasks

Protected function Const

void

 

UpdateDebuggerAfterExecution

(
    const UBTTaskNode* TaskNode,
    uint16 InstanceIdx
)

Update runtime description of given task node in latest debugger's snapshot

Protected function

uint8

 

UpdateInstanceId

(
    UBehaviorTree* TreeAsset,
    const UBTNode* OriginNode,
    int32 OriginInstanceIdx
)

Add unique Id of newly created subtree to KnownInstances list and return its index

Overridden from UBrainComponent

Name Description

Public function Virtual

void

 

Cleanup()

AI logic won't be needed anymore, stop all activity and run cleanup

Public function Virtual Const

void

 

DescribeSelfToVisLog

(
    FVisualLogEntry* Snapshot
)

Public function Virtual Const

FString

 

GetDebugInfoString()

Public function Virtual

void

 

HandleMessage

(
    const FAIMessage& Message
)

Public function Virtual Const

bool

 

IsPaused()

Public function Virtual Const

bool

 

IsRunning()

Public function Virtual

void

 

PauseLogic

(
    const FString& Reason
)

Pause logic and blackboard updates.

Public function Virtual

void

 

RestartLogic()

Restarts currently running or previously ran brain logic.

Public function Virtual

EAILogicResu...

 

ResumeLogic

(
    const FString& Reason
)

Resumes paused brain logic. MUST be called by child implementations!

Public function Virtual

void

 

StartLogic()

Starts brain logic. If brain is already running, will not do anything.

Public function Virtual

void

 

StopLogic

(
    const FString& Reason
)

Stops currently running brain logic.

Overridden from UActorComponent

Name Description

Public function Virtual

void

 

RegisterComponentTickFunctions

(
    bool bRegister
)

Virtual call chain to register all tick functions

Public function Virtual

void

 

SetComponentTickEnabled

(
    bool bEnabled
)

Set this component's tick functions to be enabled or disabled.

Public function Virtual

void

 

TickComponent

(
    float DeltaTime,
    enum ELevelTick TickType,
    FActorComponentTickFunction* T...
)

BEGIN UActorComponent overrides

Public function Virtual

void

 

UninitializeComponent()

Handle this component being Uninitialized.

Constants

Name

Description

ActiveDebuggerCounter

Set when at least one debugger window is opened

bAddedEndFrameCallback

Code for timing BT Search for FramePro.

FrameSearchTime

NumSearchTimeCalls

Deprecated Functions

Name Description

Public function

void

 

UnregisterAuxNodesInBranch

(
    const UBTCompositeNode* Node,
    bool bApplyImmediately
)

This function is deprecated. Please use RequestUnregisterAuxNodesInBranch instead.

Help shape the future of Unreal Engine documentation! Tell us how we're doing so we can serve you better.
Take our survey
Dismiss