UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
AnimNodeReference.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "EngineLogs.h"
7#include "AnimNodeReference.generated.h"
8
9struct FAnimNode_Base;
11class UAnimInstance;
12
13// The result of an anim node reference conversion
14UENUM(BlueprintType)
20
21// A reference to an anim node. Does not persist, only valid for the call in which it was retrieved.
22USTRUCT(BlueprintType)
24{
26
27public:
29
30 FAnimNodeReference() = default;
31
33
35
36 // Get the node we wrap. If the context is invalid or the node is not of the specified type then this will return nullptr.
37 template<typename NodeType>
38 NodeType* GetAnimNodePtr() const
39 {
40 if(AnimNode && AnimNodeStruct && AnimNodeStruct->IsChildOf(NodeType::StaticStruct()))
41 {
42 return static_cast<NodeType*>(AnimNode);
43 }
44
45 return nullptr;
46 }
47
48 // Get the node we wrap. If the reference is invalid or node is not of the specified type then this will return assert.
49 template<typename NodeType>
50 NodeType& GetAnimNode() const
51 {
52 check(AnimNodeStruct);
53 check(AnimNode);
54 check(AnimNodeStruct->IsChildOf(NodeType::StaticStruct()));
55 return *static_cast<NodeType*>(AnimNode);
56 }
57
58 // Call a function if this context is valid
59 template<typename NodeType>
61 {
62 if(NodeType* NodePtr = GetAnimNodePtr<NodeType>())
63 {
65 }
66 else
67 {
68 UE_LOG(LogAnimation, Warning, TEXT("%s called on an invalid context or with an invalid type"), InFunctionNameForErrorReporting);
69 }
70 }
71
72 // Convert to a derived type
73 template<typename OtherContextType>
75 {
76 static_assert(TIsDerivedFrom<OtherContextType, FAnimNodeReference>::IsDerived, "Argument ContextType must derive from FAnimNodeReference");
77
78 if(InReference.AnimNodeStruct && InReference.AnimNodeStruct->IsChildOf(OtherContextType::FInternalNodeType::StaticStruct()))
79 {
81
83 Context.AnimNode = InReference.AnimNode;
84 Context.AnimNodeStruct = InReference.AnimNodeStruct;
85 return Context;
86 }
87
89
90 return OtherContextType();
91 }
92
93private:
94 // The node we wrap
95 FAnimNode_Base* AnimNode = nullptr;
96
97 // The struct type of the anim node
98 UScriptStruct* AnimNodeStruct = nullptr;
99};
EAnimNodeReferenceConversionResult
Definition AnimNodeReference.h:16
#define check(expr)
Definition AssertionMacros.h:314
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
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 UE_LOG(CategoryName, Verbosity, Format,...)
Definition LogMacros.h:270
#define GENERATED_BODY(...)
Definition ObjectMacros.h:765
#define UENUM(...)
Definition ObjectMacros.h:749
#define USTRUCT(...)
Definition ObjectMacros.h:746
uint8_t uint8
Definition binka_ue_file_header.h:8
Definition AnimClassInterface.h:193
Definition AssetRegistryState.h:50
Definition AnimInstance.h:353
Definition Class.h:1720
Definition AnimNodeReference.h:24
void CallAnimNodeFunction(const TCHAR *InFunctionNameForErrorReporting, TFunctionRef< void(NodeType &)> InFunction) const
Definition AnimNodeReference.h:60
FAnimNodeReference()=default
NodeType & GetAnimNode() const
Definition AnimNodeReference.h:50
NodeType * GetAnimNodePtr() const
Definition AnimNodeReference.h:38
FAnimNode_Base FInternalNodeType
Definition AnimNodeReference.h:28
static OtherContextType ConvertToType(const FAnimNodeReference &InReference, EAnimNodeReferenceConversionResult &OutResult)
Definition AnimNodeReference.h:74
Definition AnimNodeBase.h:853
Definition UnrealTypeTraits.h:40