UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ValueOrBBKey.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
9#include "Misc/Guid.h"
12
13#include "ValueOrBBKey.generated.h"
14
16class FValueOrBBKeyDetails;
17
18struct FPropertyTag;
19struct FConstStructView;
20
21// Drop in replacement for Property in bt nodes that allows easy binding to blackboard key. Replace the old property with the corresponding type and call the GetValue() function to retrieve the value.
33
34namespace FBlackboard
35{
36 template <typename T>
38 {
40 {
41 InOutCachedKey = Blackboard.GetKeyID(Name);
42 }
43 if (Blackboard.GetKeyType(InOutCachedKey) == T::StaticClass())
44 {
45 return { Blackboard.GetValue<T>(InOutCachedKey) };
46 }
47 return {};
48 }
49
50 template <typename T>
51 typename T::FDataType GetValue(const UBlackboardComponent& Blackboard, const FName& Name, FBlackboard::FKey& InOutCachedKey, const typename T::FDataType& DefaultValue)
52 {
53 if (!Name.IsNone())
54 {
55 if (const TOptional<typename T::FDataType> KeyValue = FBlackboard::TryGetBlackboardKeyValue<T>(Blackboard, Name, InOutCachedKey))
56 {
57 return KeyValue.GetValue();
58 }
59 }
60 return DefaultValue;
61 }
62
63 template <typename T>
64 typename T::FDataType GetValue(const UBehaviorTreeComponent& BehaviorComp, const FName& Name, FBlackboard::FKey& InOutCachedKey, const typename T::FDataType& DefaultValue)
65 {
66 if (const UBlackboardComponent* Blackboard = BehaviorComp.GetBlackboardComponent())
67 {
68 return GetValue<T>(*Blackboard, Name, InOutCachedKey, DefaultValue);
69 }
70 return DefaultValue;
71 }
72
74
75 FConstStructView GetStructValue(const UBlackboardComponent& Blackboard, const FName& Name, FBlackboard::FKey& InOutCachedKey, const FConstStructView& DefaultValue);
76
78} // namespace FBlackboard
79
80// Base struct to simplify edition in the editor, shouldn't be used elsewhere
81USTRUCT(BlueprintType)
83{
85
86 friend FValueOrBBKeyDetails;
87
88#if WITH_EDITOR
89 virtual ~FValueOrBlackboardKeyBase() = default;
90 virtual bool IsCompatibleType(const UBlackboardKeyType* KeyType) const { return false; };
91 virtual FString ToString() const { return FString(); }
92 AIMODULE_API void PreSave(const UObject* Outer, const UBlackboardData& Blackboard, FName PropertyName);
93#endif // WITH_EDITOR
94
95 const FName& GetKey() const { return Key; }
96 void SetKey(FName NewKey) { Key = NewKey; }
97
98 AIMODULE_API FBlackboard::FKey GetKeyId(const UBehaviorTreeComponent& OwnerComp) const;
99
100protected:
101 template <typename T>
102 FString ToStringInternal(const T& DefaultValue) const
103 {
104 if (!Key.IsNone())
105 {
106 return ToStringKeyName();
107 }
108 else
109 {
110 return FString::Format(TEXT("{0}"), { DefaultValue });
111 }
112 }
113
114 AIMODULE_API FString ToStringKeyName() const;
115
116 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Value")
117 FName Key;
118
119 mutable FBlackboard::FKey KeyId = FBlackboard::InvalidKey;
120};
121
122USTRUCT(BlueprintType)
124{
126
128 : DefaultValue(Default) {}
129 AIMODULE_API bool GetValue(const UBehaviorTreeComponent& BehaviorComp) const;
130 AIMODULE_API bool GetValue(const UBehaviorTreeComponent* BehaviorComp) const;
131 AIMODULE_API bool GetValue(const UBlackboardComponent& Blackboard) const;
132 AIMODULE_API bool GetValue(const UBlackboardComponent* Blackboard) const;
133
134#if WITH_EDITOR
135 AIMODULE_API virtual bool IsCompatibleType(const UBlackboardKeyType* KeyType) const override;
136#endif // WITH_EDITOR
137
138 bool SerializeFromMismatchedTag(const FPropertyTag& Tag, FStructuredArchive::FSlot Slot);
139
140 FString ToString() const { return ToStringInternal(DefaultValue); }
141
142 UE_DEPRECATED_FORGAME(5.5, "Implicit conversion will be removed next version. Call GetValue instead")
143 operator bool() const { return DefaultValue; }
144
145protected:
146 UPROPERTY(EditAnywhere, Category = "Value")
147 bool DefaultValue = false;
148};
149
150USTRUCT(BlueprintType)
152{
154
155 friend class FValueOrBBKeyDetails_Class;
156
158
161 : DefaultValue(Default), BaseClass(T::StaticClass()) {}
162
163 template <typename T>
168
171 AIMODULE_API UClass* GetValue(const UBlackboardComponent& Blackboard) const;
172 AIMODULE_API UClass* GetValue(const UBlackboardComponent* Blackboard) const;
173
174 bool SerializeFromMismatchedTag(const FPropertyTag& Tag, FStructuredArchive::FSlot Slot);
175
176#if WITH_EDITOR
177 AIMODULE_API virtual bool IsCompatibleType(const UBlackboardKeyType* KeyType) const override;
178#endif // WITH_EDITOR
179
180 AIMODULE_API FString ToString() const;
181
182 UE_DEPRECATED_FORGAME(5.5, "Implicit conversion will be removed next version. Call GetValue instead")
183 operator UClass*() const { return DefaultValue; }
184
185 AIMODULE_API void SetBaseClass(UClass* NewBaseClass);
186
187protected:
188 UPROPERTY(EditAnywhere, Category = "Value")
189 TObjectPtr<UClass> DefaultValue = nullptr;
190
191 UPROPERTY(EditDefaultsOnly, Category = "Value", meta = (AllowAbstract = "1"))
193};
194
195USTRUCT(BlueprintType)
197{
199
200 friend class FValueOrBBKeyDetails_Enum;
201
203
206 : DefaultValue(static_cast<uint8>(Default)), EnumType(StaticEnum<T>()), NativeEnumTypeName(GetNameSafe(EnumType)) {}
207
208 template <typename T>
210 {
211 return static_cast<T>(GetValue(BehaviorComp));
212 }
213
216 AIMODULE_API uint8 GetValue(const UBlackboardComponent& Blackboard) const;
217 AIMODULE_API uint8 GetValue(const UBlackboardComponent* Blackboard) const;
218
219 bool SerializeFromMismatchedTag(const FPropertyTag& Tag, FStructuredArchive::FSlot Slot);
220
221#if WITH_EDITOR
222 AIMODULE_API virtual bool IsCompatibleType(const UBlackboardKeyType* KeyType) const override;
223#endif // WITH_EDITOR
224
225 AIMODULE_API FString ToString() const;
226
227 UE_DEPRECATED_FORGAME(5.5, "Implicit conversion will be removed next version. Call GetValue instead")
228 operator uint8() const { return DefaultValue; }
229
230 AIMODULE_API void SetEnumType(UEnum* NewEnumType);
231
232protected:
233 UPROPERTY(EditAnywhere, Category = "Value")
234 uint8 DefaultValue = 0;
235
236 UPROPERTY(EditDefaultsOnly, Category = "Value")
237 TObjectPtr<UEnum> EnumType = nullptr;
238
240 UPROPERTY(EditDefaultsOnly, Category = "Value")
241 FString NativeEnumTypeName = TEXT("");
242};
243
244USTRUCT(BlueprintType)
246{
248
250 : DefaultValue(Default) {}
251 AIMODULE_API float GetValue(const UBehaviorTreeComponent& BehaviorComp) const;
252 AIMODULE_API float GetValue(const UBehaviorTreeComponent* BehaviorComp) const;
253 AIMODULE_API float GetValue(const UBlackboardComponent& Blackboard) const;
254 AIMODULE_API float GetValue(const UBlackboardComponent* Blackboard) const;
255
256 bool SerializeFromMismatchedTag(const FPropertyTag& Tag, FStructuredArchive::FSlot Slot);
257
258#if WITH_EDITOR
259 AIMODULE_API virtual bool IsCompatibleType(const UBlackboardKeyType* KeyType) const override;
260#endif // WITH_EDITOR
261
262 AIMODULE_API FString ToString() const;
263 AIMODULE_API bool IsBoundOrNonZero() const;
264
265 UE_DEPRECATED_FORGAME(5.5, "Implicit conversion will be removed next version. Call GetValue instead")
266 operator float() const { return DefaultValue; }
267
268protected:
269 UPROPERTY(EditAnywhere, Category = "Value")
270 float DefaultValue = 0.f;
271};
272
273USTRUCT(BlueprintType)
275{
278 : DefaultValue(Default) {}
281 AIMODULE_API int32 GetValue(const UBlackboardComponent& Blackboard) const;
282 AIMODULE_API int32 GetValue(const UBlackboardComponent* Blackboard) const;
283
284 bool SerializeFromMismatchedTag(const FPropertyTag& Tag, FStructuredArchive::FSlot Slot);
285
286#if WITH_EDITOR
287 AIMODULE_API virtual bool IsCompatibleType(const UBlackboardKeyType* KeyType) const override;
288#endif // WITH_EDITOR
289
290 FString ToString() const { return ToStringInternal(DefaultValue); }
291
292 UE_DEPRECATED_FORGAME(5.5, "Implicit conversion will be removed next version. Call GetValue instead")
293 operator int32() const { return DefaultValue; }
294
295protected:
296 UPROPERTY(EditAnywhere, Category = "Value")
297 int32 DefaultValue = 0;
298};
299
300USTRUCT(BlueprintType)
302{
304
306 : DefaultValue(Default) {}
309 AIMODULE_API FName GetValue(const UBlackboardComponent& Blackboard) const;
310 AIMODULE_API FName GetValue(const UBlackboardComponent* Blackboard) const;
311
312 bool SerializeFromMismatchedTag(const FPropertyTag& Tag, FStructuredArchive::FSlot Slot);
313
314#if WITH_EDITOR
315 AIMODULE_API virtual bool IsCompatibleType(const UBlackboardKeyType* KeyType) const override;
316#endif // WITH_EDITOR
317
318 AIMODULE_API FString ToString() const;
319
320 UE_DEPRECATED_FORGAME(5.5, "Implicit conversion will be removed next version. Call GetValue instead")
321 operator FName() const { return DefaultValue; }
322
323protected:
324 UPROPERTY(EditAnywhere, Category = "Value")
325 FName DefaultValue;
326};
327
328USTRUCT(BlueprintType)
330{
332
333 FValueOrBBKey_String(FString Default = FString())
334 : DefaultValue(MoveTemp(Default)) {}
335 AIMODULE_API FString GetValue(const UBehaviorTreeComponent& BehaviorComp) const;
336 AIMODULE_API FString GetValue(const UBehaviorTreeComponent* BehaviorComp) const;
337 AIMODULE_API FString GetValue(const UBlackboardComponent& Blackboard) const;
338 AIMODULE_API FString GetValue(const UBlackboardComponent* Blackboard) const;
339
340 bool SerializeFromMismatchedTag(const FPropertyTag& Tag, FStructuredArchive::FSlot Slot);
341
342#if WITH_EDITOR
343 AIMODULE_API virtual bool IsCompatibleType(const UBlackboardKeyType* KeyType) const override;
344#endif // WITH_EDITOR
345
346 UE_DEPRECATED_FORGAME(5.5, "Implicit conversion will be removed next version. Call GetValue instead")
347 operator FString() const { return DefaultValue; }
348
349 FString ToString() const { return ToStringInternal(DefaultValue); }
350
351protected:
352 UPROPERTY(EditAnywhere, Category = "Value")
353 FString DefaultValue;
354};
355
356USTRUCT(BlueprintType)
358{
360 friend class FValueOrBBKeyDetails_Object;
361
363
366 : DefaultValue(Default), BaseClass(T::StaticClass()) {}
367
368 template <typename T>
370 {
371 return Cast<T>(GetValue(BehaviorComp));
372 }
373
376 AIMODULE_API UObject* GetValue(const UBlackboardComponent& Blackboard) const;
377 AIMODULE_API UObject* GetValue(const UBlackboardComponent* Blackboard) const;
378
379 bool SerializeFromMismatchedTag(const FPropertyTag& Tag, FStructuredArchive::FSlot Slot);
380
381#if WITH_EDITOR
382 AIMODULE_API virtual bool IsCompatibleType(const UBlackboardKeyType* KeyType) const override;
383#endif // WITH_EDITOR
384
385 AIMODULE_API FString ToString() const;
386
387 UE_DEPRECATED_FORGAME(5.5, "Implicit conversion will be removed next version. Call GetValue instead")
388 operator UObject*() const { return DefaultValue; }
389
390 AIMODULE_API void SetBaseClass(UClass* NewBaseClass);
391
392protected:
393 UPROPERTY(EditAnywhere, Category = "Value")
394 TObjectPtr<UObject> DefaultValue = nullptr;
395
396 UPROPERTY(EditDefaultsOnly, Category = "Value", meta = (AllowAbstract = "1"))
398};
399
400USTRUCT(BlueprintType)
402{
404
406 : DefaultValue(MoveTemp(Default)) {}
409 AIMODULE_API FRotator GetValue(const UBlackboardComponent& Blackboard) const;
410 AIMODULE_API FRotator GetValue(const UBlackboardComponent* Blackboard) const;
411
412 bool SerializeFromMismatchedTag(const FPropertyTag& Tag, FStructuredArchive::FSlot Slot);
413
414#if WITH_EDITOR
415 AIMODULE_API virtual bool IsCompatibleType(const UBlackboardKeyType* KeyType) const override;
416#endif // WITH_EDITOR
417
418 AIMODULE_API FString ToString() const;
419
420 UE_DEPRECATED_FORGAME(5.5, "Implicit conversion will be removed next version. Call GetValue instead")
421 operator FRotator() const { return DefaultValue; }
422
423protected:
424 UPROPERTY(EditAnywhere, Category = "Value")
425 FRotator DefaultValue;
426};
427
428USTRUCT(BlueprintType)
430{
432
434 : DefaultValue(MoveTemp(Default)) {}
437 AIMODULE_API FVector GetValue(const UBlackboardComponent& Blackboard) const;
438 AIMODULE_API FVector GetValue(const UBlackboardComponent* Blackboard) const;
439
440 bool SerializeFromMismatchedTag(const FPropertyTag& Tag, FStructuredArchive::FSlot Slot);
441
442#if WITH_EDITOR
443 AIMODULE_API virtual bool IsCompatibleType(const UBlackboardKeyType* KeyType) const override;
444#endif // WITH_EDITOR
445
446 AIMODULE_API FString ToString() const;
447
448 UE_DEPRECATED_FORGAME(5.5, "Implicit conversion will be removed next version. Call GetValue instead")
449 operator FVector() const { return DefaultValue; }
450
451protected:
452 UPROPERTY(EditAnywhere, Category = "Value")
453 FVector DefaultValue;
454};
455
456USTRUCT(BlueprintType)
458{
460
461public:
462 template <typename T>
464 {
465 DefaultValue.InitializeAs<T>(Value);
466 }
468
469#if WITH_EDITOR
470 AIMODULE_API virtual bool IsCompatibleType(const UBlackboardKeyType* KeyType) const;
471#endif // WITH_EDITOR
472
473 AIMODULE_API FString ToString() const;
474
475 template <typename T>
477 {
478 check(DefaultValue.GetScriptStruct() == TBaseStructure<T>::Get());
479 return GetValue(BehaviorComp).Get<const T>();
480 }
481
482 bool SerializeFromMismatchedTag(const FPropertyTag& Tag, FStructuredArchive::FSlot Slot);
483
486 AIMODULE_API FConstStructView GetValue(const UBlackboardComponent& Blackboard) const;
487 AIMODULE_API FConstStructView GetValue(const UBlackboardComponent* Blackboard) const;
488
489 AIMODULE_API void SetStructType(UScriptStruct* NewStructType);
490
491protected:
492 friend class FValueOrBBKeyDetails_Struct;
493
494 UPROPERTY(EditAnywhere, Category = Value)
495 FInstancedStruct DefaultValue;
496
497#if WITH_EDITORONLY_DATA
499 UPROPERTY(EditDefaultsOnly, Category = Value)
500 bool bCanEditDefaultValueType = false;
501#endif // WITH_EDITORONLY_DATA
502};
503
504template <>
506{
507 enum
508 {
510 };
511};
512
513template <>
515{
516 enum
517 {
519 };
520};
521
522template <>
524{
525 enum
526 {
528 };
529};
530
531template <>
533{
534 enum
535 {
537 };
538};
539
540template <>
542{
543 enum
544 {
546 };
547};
548
549template <>
551{
552 enum
553 {
555 };
556};
557
558template <>
560{
561 enum
562 {
564 };
565};
566
567template <>
569{
570 enum
571 {
573 };
574};
575
576template <>
578{
579 enum
580 {
582 };
583};
584
585template <>
587{
588 enum
589 {
591 };
592};
593
594template <>
596{
597 enum
598 {
600 };
601};
#define check(expr)
Definition AssertionMacros.h:314
#define UE_DEPRECATED_FORGAME
Definition CoreMiscDefines.h:377
FString GetNameSafe(const FField *InField)
Definition Field.h:1230
#define TEXT(x)
Definition Platform.h:1272
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
const bool
Definition NetworkReplayStreaming.h:178
#define UPROPERTY(...)
UObject definition macros.
Definition ObjectMacros.h:744
#define GENERATED_BODY(...)
Definition ObjectMacros.h:765
#define USTRUCT(...)
Definition ObjectMacros.h:746
UEnum * StaticEnum()
UClass * StaticClass()
Definition ReflectedTypeAccessors.h:13
USkinnedMeshComponent float
Definition SkinnedMeshComponent.h:60
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
uint8_t uint8
Definition binka_ue_file_header.h:8
Definition NameTypes.h:617
Definition StructuredArchiveSlots.h:52
Definition SubclassOf.h:30
Definition BehaviorTreeComponent.h:105
Definition BlackboardData.h:46
Definition BlackboardKeyType.h:24
Definition Class.h:3793
Definition Class.h:2791
Definition Object.h:95
Definition Class.h:1720
Definition BlackboardKey.h:8
TOptional< typename T::FDataType > TryGetBlackboardKeyValue(const UBlackboardComponent &Blackboard, const FName &Name, FBlackboard::FKey &InOutCachedKey)
Definition ValueOrBBKey.h:37
FConstStructView TryGetBlackboardKeyStruct(const UBlackboardComponent &Blackboard, const FName &Name, FBlackboard::FKey &InOutCachedKey, const UScriptStruct *TargetStruct)
Definition ValueOrBBKey.cpp:24
constexpr FKey InvalidKey
Definition BlackboardKey.h:33
FConstStructView GetStructValue(const UBlackboardComponent &Blackboard, const FName &Name, FBlackboard::FKey &InOutCachedKey, const FConstStructView &DefaultValue)
Definition ValueOrBBKey.cpp:48
T::FDataType GetValue(const UBlackboardComponent &Blackboard, const FName &Name, FBlackboard::FKey &InOutCachedKey, const typename T::FDataType &DefaultValue)
Definition ValueOrBBKey.h:51
@ false
Definition radaudio_common.h:23
Definition BlackboardKey.h:18
Definition StructView.h:217
Definition InstancedStruct.h:32
Definition InputCoreTypes.h:50
Definition PropertyTag.h:38
Definition ValueOrBBKey.h:124
FString ToString() const
Definition ValueOrBBKey.h:140
Definition ValueOrBBKey.h:152
TSubclassOf< T > GetValue(const UBehaviorTreeComponent &BehaviorComp) const
Definition ValueOrBBKey.h:164
Definition ValueOrBBKey.h:197
T GetValue(const UBehaviorTreeComponent &BehaviorComp) const
Definition ValueOrBBKey.h:209
Definition ValueOrBBKey.h:246
Definition ValueOrBBKey.h:275
FString ToString() const
Definition ValueOrBBKey.h:290
Definition ValueOrBBKey.h:302
Definition ValueOrBBKey.h:358
T * GetValue(const UBehaviorTreeComponent &BehaviorComp) const
Definition ValueOrBBKey.h:369
Definition ValueOrBBKey.h:402
Definition ValueOrBBKey.h:330
FString ToString() const
Definition ValueOrBBKey.h:349
Definition ValueOrBBKey.h:458
FValueOrBBKey_Struct(const T &Value)
Definition ValueOrBBKey.h:463
FValueOrBBKey_Struct()=default
const T & GetValue(const UBehaviorTreeComponent &BehaviorComp) const
Definition ValueOrBBKey.h:476
Definition ValueOrBBKey.h:430
Definition ValueOrBBKey.h:83
void SetKey(FName NewKey)
Definition ValueOrBBKey.h:96
const FName & GetKey() const
Definition ValueOrBBKey.h:95
FString ToStringInternal(const T &DefaultValue) const
Definition ValueOrBBKey.h:102
Definition Class.h:5288
Definition ObjectPtr.h:488
Definition Optional.h:131
constexpr OptionalType & GetValue()
Definition Optional.h:443
Definition StructOpsTypeTraits.h:11
@ WithStructuredSerializeFromMismatchedTag
Definition StructOpsTypeTraits.h:29
Definition StructOpsTypeTraits.h:46