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

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

uint8: 1

 

bWaitingForAbortingTasks

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

Protected variable

TMap< FGameplayTag, float >

 

CooldownTagsMap

Behavior cooldowns mapped by tag to last time it was set

Protected variable

TArray< TArray< FBehaviorTreeDebuggerInstance::FNodeFlowData > >

 

CurrentRestarts

Protected variable

TArray< TArray< FBehaviorTreeDebuggerInstance::FNodeFlowData > >

 

CurrentSearchFlow

Search flow for debugger

Protected variable

TArray< FBehaviorTreeExecutionStep >

 

DebuggerSteps

Debugger's recorded data

Protected variable

FBTNodeExecutionInfo

 

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< FBehaviorTreeInstance >

 

InstanceStack

Stack of behavior tree instances

Protected variable

TArray< FBehaviorTreeInstanceId >

 

KnownInstances

List of known subtree instances

Protected variable

TArray< UBTNode * >

 

NodeInstances

Instanced nodes

Protected variable

FBTPendingExecutionInfo

 

PendingExecution

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

Protected variable

TArray< FBehaviorTreeDebuggerInstance >

 

RemovedInstances

Protected variable

FBehaviorTreeSearchData

 

SearchData

Search data being currently used

Protected variable

TMap< FName, FString >

 

SearchStartBlackboard

Protected variable

uint8

 

StopTreeLock

If set, StopTree calls will be deferred

Protected variable

TMultiMap< FBTNodeIndex, FAIMessageObserverHandle >

 

TaskMessageObservers

Message observers mapped by instance & execution index

Protected variable

FBTTreeStartInfo

 

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& ObjectInitializer
)

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< FBehaviorTreeSearchUpdate >& UpdateList,
    int32 NewNodeExecutionIndex,
    bool bPostUpdate
)

Apply updates from specific list

Protected function Const

EBTNodeRelativePriority

 

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
)

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 UBTNode *

 

GetActiveNode()

Public function Const

UBehaviorTree *

 

GetCurrentTree()

Public function Const

uint8 *

 

GetNodeMemory

(
    UBTNode* Node,
    int32 InstanceIdx
)

Public function Const

UBehaviorTree *

 

GetRootTree()

Public function Const

float

 

GetTagCooldownEndTime

(
    FGameplayTag CooldownTag
)

Public function Const

EBTTaskStatus::Type

 

GetTaskStatus

(
    const UBTTaskNode* TaskNode
)

Public function Const

bool

 

IsAbortPending()

Public function Const

bool

 

IsAuxNodeActive

(
    const UBTAuxiliaryNode* AuxNodeTemplate,
    int32 InstanceIdx
)

Public function Const

bool

 

IsAuxNodeActive

(
    const UBTAuxiliaryNode* AuxNode
)

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()

END UActorComponent overrides 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

 

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* RequestedBy
)

Request execution change: helpers for decorator nodes

Public function

void

 

RequestExecution

(
    EBTNodeResult::Type ContinueWithResult
)

Request execution change: helpers for task nodes

Public function

void

 

RequestExecution

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

Request execution change

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 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 >& BlackboardValueDesc
)

Describe blackboard's key values

Protected function

void

 

StoreDebuggerExecutionStep

(
    EBTExecutionSnap::Type SnapType
)

Make a snapshot for debugger

Protected function Const

void

 

StoreDebuggerInstance

(
    FBehaviorTreeDebuggerInstance& InstanceInfo,
    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 >& RuntimeDescriptions,
    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

 

UnregisterAuxNodesInBranch

(
    const UBTCompositeNode* Node,
    bool bApplyImmediately
)

Unregister all aux nodes in branch of tree

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 Const

bool

 

IsPaused()

Public function Virtual Const

bool

 

IsRunning()

Public function Virtual

void

 

PauseLogic

(
    const FString& Reason
)

Public function Virtual

void

 

RestartLogic()

Public function Virtual

EAILogicResuming::Type

 

ResumeLogic

(
    const FString& Reason
)

MUST be called by child implementations!

Public function Virtual

void

 

StopLogic

(
    const FString& Reason
)

Overridden from UActorComponent

Name Description

Public function Virtual

void

 

TickComponent

(
    float DeltaTime,
    enum ELevelTick TickType,
    FActorComponentTickFunction* ThisTickFunction
)

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

Select Skin
Light
Dark

Welcome to the new Unreal Engine 4 Documentation site!

We're working on lots of new features including a feedback system so you can tell us how we are doing. It's not quite ready for use in the wild yet, so head over to the Documentation Feedback forum to tell us about this page or call out any issues you are encountering in the meantime.

We'll be sure to let you know when the new system is up and running.

Post Feedback