UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
BTCompositeNode.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
4#include "CoreMinimal.h"
6#include "BTCompositeNode.generated.h"
7
9class UBTDecorator;
10class UBTService;
11class UBTTaskNode;
12
14
23
24UENUM()
26{
29};
30
31UENUM()
33{
34 // keep in sync with DescribeLogicOp() in BTCompositeNode.cpp
35
36 enum Type : int
37 {
47 };
48}
49
50USTRUCT()
64
65USTRUCT()
67{
69
70
71 UPROPERTY()
72 TObjectPtr<UBTCompositeNode> ChildComposite = nullptr;
73
74 UPROPERTY()
75 TObjectPtr<UBTTaskNode> ChildTask = nullptr;
76
78 UPROPERTY()
80
82 UPROPERTY()
84};
85
86UCLASS(Abstract, MinimalAPI)
88{
90
91
92 UPROPERTY()
94
96 UPROPERTY()
98
100
102 AIMODULE_API void InitializeComposite(uint16 InLastExecutionIndex);
103
105 AIMODULE_API int32 FindChildToExecute(FBehaviorTreeSearchData& SearchData, EBTNodeResult::Type& LastResult) const;
106
108 AIMODULE_API int32 GetChildIndex(FBehaviorTreeSearchData& SearchData, const UBTNode& ChildNode) const;
110 AIMODULE_API int32 GetChildIndex(const UBTNode& ChildNode) const;
111
113 AIMODULE_API void OnChildActivation(FBehaviorTreeSearchData& SearchData, const UBTNode& ChildNode) const;
114 AIMODULE_API void OnChildActivation(FBehaviorTreeSearchData& SearchData, int32 ChildIndex) const;
115
123 AIMODULE_API void OnChildDeactivation(FBehaviorTreeSearchData& SearchData, const UBTNode& ChildNode, EBTNodeResult::Type& NodeResult, const bool bRequestedFromValidInstance) const;
131 AIMODULE_API void OnChildDeactivation(FBehaviorTreeSearchData& SearchData, int32 ChildIndex, EBTNodeResult::Type& NodeResult, const bool bRequestedFromValidInstance) const;
132
134 AIMODULE_API void OnNodeActivation(FBehaviorTreeSearchData& SearchData) const;
135
137 AIMODULE_API void OnNodeDeactivation(FBehaviorTreeSearchData& SearchData, EBTNodeResult::Type& NodeResult) const;
138
140 AIMODULE_API void OnNodeRestart(FBehaviorTreeSearchData& SearchData) const;
141
143 AIMODULE_API void ConditionalNotifyChildExecution(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory, const UBTNode& ChildNode, EBTNodeResult::Type& NodeResult) const;
144
146 AIMODULE_API virtual uint16 GetInstanceMemorySize() const override;
147 AIMODULE_API virtual void InitializeMemory(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory, EBTMemoryInit::Type InitType) const override;
148 AIMODULE_API virtual void CleanupMemory(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory, EBTMemoryClear::Type CleanupType) const override;
149
151 UBTNode* GetChildNode(int32 Index) const;
152
154 int32 GetChildrenNum() const;
155
158
160 uint16 GetLastExecutionIndex() const;
161
163 AIMODULE_API virtual void SetChildOverride(FBehaviorTreeSearchData& SearchData, int8 Index) const;
164
166 AIMODULE_API virtual void DescribeRuntimeValues(const UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory, EBTDescriptionVerbosity::Type Verbosity, TArray<FString>& Values) const override;
167
169 AIMODULE_API virtual bool CanPushSubtree(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory, int32 ChildIdx) const;
170
171#if WITH_EDITOR
173 AIMODULE_API virtual bool CanAbortLowerPriority() const;
174 AIMODULE_API virtual bool CanAbortSelf() const;
175#endif // WITH_EDITOR
176
178 AIMODULE_API int32 GetMatchingChildIndex(int32 ActiveInstanceIdx, FBTNodeIndex& NodeIdx) const;
179
181 AIMODULE_API uint16 GetBranchExecutionIndex(uint16 NodeInBranchIdx) const;
182
184 AIMODULE_API bool DoDecoratorsAllowExecution(UBehaviorTreeComponent& OwnerComp, const int32 InstanceIdx, const int32 ChildIdx) const;
185
186 bool IsApplyingDecoratorScope() const;
187
188 // Deprecated methods
189 UE_DEPRECATED(5.0, "This function is deprecated. Please use RequestBranchDeactivation instead.")
190 void OnChildDeactivation(FBehaviorTreeSearchData& SearchData, const UBTNode& ChildNode, EBTNodeResult::Type& NodeResult) const { OnChildDeactivation(SearchData, ChildNode, NodeResult, /*bRequestedFromValidInstance*/true); }
191 UE_DEPRECATED(5.0, "This function is deprecated. Please use RequestBranchDeactivation instead.")
192 void OnChildDeactivation(FBehaviorTreeSearchData& SearchData, int32 ChildIndex, EBTNodeResult::Type& NodeResult) const { OnChildDeactivation(SearchData, ChildIndex, NodeResult, /*bRequestedFromValidInstance*/true ); }
193
194protected:
195
197 UPROPERTY(EditAnywhere, Category = Composite)
198 uint32 bApplyDecoratorScope : 1;
199
201 uint32 bUseChildExecutionNotify : 1;
202
204 uint32 bUseNodeActivationNotify : 1;
205
207 uint32 bUseNodeDeactivationNotify : 1;
208
210 uint32 bUseDecoratorsActivationCheck : 1;
211
213 uint32 bUseDecoratorsDeactivationCheck : 1;
214
216 uint32 bUseDecoratorsFailedActivationCheck : 1;
217
219 uint16 LastExecutionIndex;
220
224 AIMODULE_API virtual void NotifyChildExecution(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory, int32 ChildIdx, EBTNodeResult::Type& NodeResult) const;
225
229 AIMODULE_API virtual void NotifyNodeActivation(FBehaviorTreeSearchData& SearchData) const;
230
234 AIMODULE_API virtual void NotifyNodeDeactivation(FBehaviorTreeSearchData& SearchData, EBTNodeResult::Type& NodeResult) const;
235
239 AIMODULE_API virtual bool CanNotifyDecoratorsOnActivation(FBehaviorTreeSearchData& SearchData, int32 ChildIdx) const;
240
244 AIMODULE_API virtual bool CanNotifyDecoratorsOnDeactivation(FBehaviorTreeSearchData& SearchData, int32 ChildIdx, EBTNodeResult::Type& NodeResult) const;
245
249 AIMODULE_API virtual bool CanNotifyDecoratorsOnFailedActivation(FBehaviorTreeSearchData& SearchData, int32 ChildIdx, EBTNodeResult::Type& NodeResult) const;
250
252 AIMODULE_API void NotifyDecoratorsOnActivation(FBehaviorTreeSearchData& SearchData, int32 ChildIdx) const;
253
255 AIMODULE_API void NotifyDecoratorsOnDeactivation(FBehaviorTreeSearchData& SearchData, int32 ChildIdx, EBTNodeResult::Type& NodeResult, const bool bIsInSameActiveInstance) const;
256
258 AIMODULE_API void NotifyDecoratorsOnFailedActivation(FBehaviorTreeSearchData& SearchData, int32 ChildIdx, EBTNodeResult::Type& NodeResult) const;
259
261 AIMODULE_API int32 GetNextChild(FBehaviorTreeSearchData& SearchData, int32 LastChildIdx, EBTNodeResult::Type LastResult) const;
262
264 AIMODULE_API void RequestDelayedExecution(UBehaviorTreeComponent& OwnerComp, EBTNodeResult::Type LastResult) const;
265
267 virtual int32 GetNextChildHandler(struct FBehaviorTreeSearchData& SearchData, int32 PrevChild, EBTNodeResult::Type LastResult) const { return BTSpecialChild::ReturnToParent; }
268
269 template<typename NotifyChildExecution, typename NotifyNodeActivation, typename NotifyNodeDeactivation,
270 typename CanNotifyDecoratorsOnActivation, typename CanNotifyDecoratorsOnDeactivation, typename CanNotifyDecoratorsOnFailedActivation>
271 void InitNotifyFlags(NotifyChildExecution, NotifyNodeActivation, NotifyNodeDeactivation,
272 CanNotifyDecoratorsOnActivation, CanNotifyDecoratorsOnDeactivation, CanNotifyDecoratorsOnFailedActivation)
273 {
274 bUseChildExecutionNotify = !std::is_same_v<decltype(&UBTCompositeNode::NotifyChildExecution), NotifyChildExecution>;
275 bUseNodeActivationNotify = !std::is_same_v<decltype(&UBTCompositeNode::NotifyNodeActivation), NotifyNodeActivation>;
276 bUseNodeDeactivationNotify = !std::is_same_v<decltype(&UBTCompositeNode::NotifyNodeDeactivation), NotifyNodeDeactivation>;
277 bUseDecoratorsActivationCheck = !std::is_same_v<decltype(&UBTCompositeNode::CanNotifyDecoratorsOnActivation), CanNotifyDecoratorsOnActivation>;
278 bUseDecoratorsDeactivationCheck = !std::is_same_v<decltype(&UBTCompositeNode::CanNotifyDecoratorsOnDeactivation), CanNotifyDecoratorsOnDeactivation>;
279 bUseDecoratorsFailedActivationCheck = !std::is_same_v<decltype(&UBTCompositeNode::CanNotifyDecoratorsOnFailedActivation), CanNotifyDecoratorsOnFailedActivation>;
280 }
281};
282
283#define INIT_COMPOSITE_NODE_NOTIFY_FLAGS() \
284 do { \
285 using NodeType = TRemovePointer<decltype(this)>::Type; \
286 InitNotifyFlags(&NodeType::NotifyChildExecution,\
287 &NodeType::NotifyNodeActivation,\
288 &NodeType::NotifyNodeDeactivation, \
289 &NodeType::CanNotifyDecoratorsOnActivation,\
290 &NodeType::CanNotifyDecoratorsOnDeactivation,\
291 &NodeType::CanNotifyDecoratorsOnFailedActivation); \
292 } while (false)
293
295// Inlines
296
297inline UBTNode* UBTCompositeNode::GetChildNode(int32 Index) const
298{
299 return Children.IsValidIndex(Index) ?
300 (Children[Index].ChildComposite ?
301 static_cast<UBTNode*>(Children[Index].ChildComposite) :
302 static_cast<UBTNode*>(Children[Index].ChildTask)) :
303 nullptr;
304}
305
306inline int32 UBTCompositeNode::GetChildrenNum() const
307{
308 return Children.Num();
309}
310
311inline uint16 UBTCompositeNode::GetLastExecutionIndex() const
312{
313 return LastExecutionIndex;
314}
315
316inline bool UBTCompositeNode::IsApplyingDecoratorScope() const
317{
319}
EBTChildIndex
Definition BTCompositeNode.h:26
#define UE_DEPRECATED(Version, Message)
Definition CoreMiscDefines.h:302
FPlatformTypes::int8 int8
An 8-bit signed integer.
Definition Platform.h:1121
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define DECLARE_DELEGATE_RetVal_ThreeParams(ReturnValueType, DelegateName, Param1Type, Param2Type, Param3Type)
Definition DelegateCombinations.h:72
#define UPROPERTY(...)
UObject definition macros.
Definition ObjectMacros.h:744
#define GENERATED_UCLASS_BODY(...)
Definition ObjectMacros.h:768
#define UCLASS(...)
Definition ObjectMacros.h:776
#define UENUM(...)
Definition ObjectMacros.h:749
#define USTRUCT(...)
Definition ObjectMacros.h:746
#define GENERATED_USTRUCT_BODY(...)
Definition ObjectMacros.h:767
uint8_t uint8
Definition binka_ue_file_header.h:8
uint16_t uint16
Definition binka_ue_file_header.h:7
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Array.h:670
UE_REWRITE SizeType Num() const
Definition Array.h:1144
UE_NODEBUG UE_FORCEINLINE_HINT bool IsValidIndex(SizeType Index) const
Definition Array.h:1122
Definition EnumAsByte.h:22
Definition BTCompositeNode.h:88
virtual AIMODULE_API void NotifyNodeDeactivation(FBehaviorTreeSearchData &SearchData, EBTNodeResult::Type &NodeResult) const
Definition BTCompositeNode.cpp:325
virtual AIMODULE_API bool CanNotifyDecoratorsOnActivation(FBehaviorTreeSearchData &SearchData, int32 ChildIdx) const
Definition BTCompositeNode.cpp:661
uint32 bApplyDecoratorScope
Definition BTCompositeNode.h:198
virtual AIMODULE_API bool CanNotifyDecoratorsOnDeactivation(FBehaviorTreeSearchData &SearchData, int32 ChildIdx, EBTNodeResult::Type &NodeResult) const
Definition BTCompositeNode.cpp:666
uint16 LastExecutionIndex
Definition BTCompositeNode.h:219
void InitNotifyFlags(NotifyChildExecution, NotifyNodeActivation, NotifyNodeDeactivation, CanNotifyDecoratorsOnActivation, CanNotifyDecoratorsOnDeactivation, CanNotifyDecoratorsOnFailedActivation)
Definition BTCompositeNode.h:271
virtual AIMODULE_API void NotifyChildExecution(UBehaviorTreeComponent &OwnerComp, uint8 *NodeMemory, int32 ChildIdx, EBTNodeResult::Type &NodeResult) const
Definition BTCompositeNode.cpp:317
virtual AIMODULE_API void NotifyNodeActivation(FBehaviorTreeSearchData &SearchData) const
Definition BTCompositeNode.cpp:321
virtual AIMODULE_API bool CanNotifyDecoratorsOnFailedActivation(FBehaviorTreeSearchData &SearchData, int32 ChildIdx, EBTNodeResult::Type &NodeResult) const
Definition BTCompositeNode.cpp:671
Definition BTDecorator.h:38
Definition BTNode.h:48
Definition BTService.h:35
Definition BTTaskNode.h:34
Definition BehaviorTreeComponent.h:105
constexpr int32 ReturnToParent
Definition BehaviorTreeTypes.h:77
Definition BTCompositeNode.h:33
Type
Definition BTCompositeNode.h:37
@ Not
Definition BTCompositeNode.h:46
Type
Definition BehaviorTreeTypes.h:217
Type
Definition BehaviorTreeTypes.h:135
Type
Definition BehaviorTreeTypes.h:126
Definition BehaviorTreeTypes.h:84
Type
Definition BehaviorTreeTypes.h:87
Definition TestUtils.cpp:8
U16 Index
Definition radfft.cpp:71
Definition BTCompositeNode.h:67
Definition BTCompositeNode.h:16
int8 CurrentChild
Definition BTCompositeNode.h:18
int8 OverrideChild
Definition BTCompositeNode.h:21
Definition BTCompositeNode.h:52
FBTDecoratorLogic(uint8 InOperation, uint16 InNumber)
Definition BTCompositeNode.h:62
Definition BehaviorTreeTypes.h:450
Definition BehaviorTreeTypes.h:534
Definition ObjectPtr.h:488