UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
MemberReference.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"
7#include "Misc/Guid.h"
8#include "UObject/Class.h"
10#include "UObject/UnrealType.h"
11#include "UObject/Package.h"
13#include "Engine/Blueprint.h"
14#include "EngineLogs.h"
15#include "MemberReference.generated.h"
16
19{
22
25
26 bool operator==(const FFieldRemapInfo& Other) const
27 {
28 return FieldName == Other.FieldName && FieldClass == Other.FieldClass;
29 }
30
32 {
33 return GetTypeHash(RemapInfo.FieldName) + GetTypeHash(RemapInfo.FieldClass) * 23;
34 }
35
41};
42
60
61// @TODO: this can encapsulate globally defined fields as well (like with native
62// delegate signatures); consider renaming to FFieldReference
63USTRUCT()
65{
67
68protected:
74 UPROPERTY(SaveGame)
75 mutable TObjectPtr<UObject> MemberParent;
76
78 UPROPERTY(SaveGame)
79 mutable FString MemberScope;
80
82 UPROPERTY(SaveGame)
83 mutable FName MemberName;
84
86 UPROPERTY(SaveGame)
87 mutable FGuid MemberGuid;
88
90 UPROPERTY(SaveGame)
91 mutable bool bSelfContext;
92
94 UPROPERTY(SaveGame)
95 mutable bool bWasDeprecated;
96
97public:
99 : MemberParent(nullptr)
100 , MemberName(NAME_None)
101 , bSelfContext(false)
102 , bWasDeprecated(false)
103 {
104 }
105
107 template<class TFieldType>
108 void SetFromField(const typename TFieldType::BaseFieldClass* InField, const bool bIsConsideredSelfContext, UClass* OwnerClass=nullptr)
109 {
110 // if we didn't get an owner passed in try to figure out what it should be based on the field
111 if (!OwnerClass)
112 {
113 OwnerClass = InField->GetOwnerClass();
114 }
115 MemberParent = OwnerClass;
116
118 {
119 MemberParent = nullptr;
120 }
121 else if ((MemberParent == nullptr) && InField->GetName().EndsWith(HEADER_GENERATED_DELEGATE_SIGNATURE_SUFFIX))
122 {
123 MemberParent = InField->GetOutermost();
124 }
125
126 MemberName = InField->GetFName();
127 bSelfContext = bIsConsideredSelfContext;
128 bWasDeprecated = false;
129
130#if WITH_EDITOR
131 if (UClass* ParentAsClass = GetMemberParentClass())
132 {
133 MemberParent = ParentAsClass->GetAuthoritativeClass();
134 }
135#endif
136
137 MemberGuid.Invalidate();
138 if (OwnerClass != nullptr)
139 {
140 UBlueprint::GetGuidFromClassByFieldName<TFieldType>(OwnerClass, InField->GetFName(), MemberGuid);
141 }
142 }
143
144#if WITH_EDITOR
145 template<class TFieldType>
146 void SetFromField(const typename TFieldType::BaseFieldClass* InField, UClass* SelfScope)
147 {
148 UClass* OwnerClass = InField->GetOwnerClass();
149
151 if (OwnerClass != nullptr)
152 {
153 UBlueprint::GetGuidFromClassByFieldName<TFieldType>(OwnerClass, InField->GetFName(), FieldGuid);
154 }
155
156 SetGivenSelfScope(InField->GetFName(), FieldGuid, OwnerClass, SelfScope);
157 }
158
160 template<class TFieldType>
162 {
163 UClass* ParentAsClass = GetMemberParentClass();
164 if ((ParentAsClass != nullptr) && (SelfScope != nullptr))
165 {
166 UBlueprint::GetGuidFromClassByFieldName<TFieldType>((ParentAsClass), MemberName, MemberGuid);
167 SetGivenSelfScope(MemberName, MemberGuid, ParentAsClass, SelfScope);
168 }
169 else
170 {
171 // We no longer have enough information to known if we've done the right thing, and just have to hope...
172 }
173 }
174#endif
175
179
181 ENGINE_API void SetGlobalField(FName InFieldName, UPackage* InParentPackage);
182
184 ENGINE_API void SetExternalDelegateMember(FName InMemberName);
185
187 ENGINE_API void SetSelfMember(FName InMemberName);
188 ENGINE_API void SetSelfMember(FName InMemberName, const FGuid& InMemberGuid);
189
191 ENGINE_API void SetLocalMember(FName InMemberName, UStruct* InScope, const FGuid InMemberGuid);
192
194 ENGINE_API void SetLocalMember(FName InMemberName, FString InScopeName, const FGuid InMemberGuid);
195
198
200 ENGINE_API void InvalidateScope();
201
204 {
205 return MemberName;
206 }
207
208#if WITH_EDITOR
210 void SetMemberName(FName NewName)
211 {
212 MemberName = NewName;
213 }
214#endif
215
217 {
218 return MemberGuid;
219 }
220
222 {
223 return Cast<UClass>(MemberParent);
224 }
225
227 {
228 if (UPackage* ParentAsPackage = Cast<UPackage>(MemberParent))
229 {
230 return ParentAsPackage;
231 }
232 else if (MemberParent != nullptr)
233 {
234 return MemberParent->GetOutermost();
235 }
236 return nullptr;
237 }
238
240 bool IsSelfContext() const
241 {
242 return bSelfContext;
243 }
244
246 bool IsLocalScope() const
247 {
248 return !MemberScope.IsEmpty();
249 }
250
252 ENGINE_API bool IsSparseClassData(const UClass* OwningClass) const;
253
254#if WITH_EDITOR
262#endif
263
264private:
265#if WITH_EDITOR
272#endif
273
274protected:
275#if WITH_EDITOR
278#endif
279public:
280
283 {
284 // Local variables with a MemberScope act much the same as being SelfContext, their parent class is SelfScope.
285 return (bSelfContext || !MemberScope.IsEmpty())? SelfScope : GetMemberParentClass();
286 }
287
293
295 FString GetMemberScopeName() const
296 {
297 return MemberScope;
298 }
299
302 {
303 return
304 bSelfContext == InReference.bSelfContext &&
305 MemberParent == InReference.MemberParent &&
306 MemberName == InReference.MemberName &&
307 MemberGuid == InReference.MemberGuid &&
308 MemberScope == InReference.MemberScope;
309 }
310
312 bool IsDeprecated() const
313 {
314 return bWasDeprecated;
315 }
316
318 UClass* GetScope(UClass* SelfScope = nullptr) const
319 {
320 return bSelfContext ? SelfScope : GetMemberParentClass();
321 }
322
328 template<class TFieldType>
329 TFieldType* ResolveMember(UClass* SelfScope = nullptr, const bool bAlwaysFollowRedirects = false) const
330 {
331 return static_cast<TFieldType*>(ResolveMemberProperty(SelfScope, bAlwaysFollowRedirects, TFieldType::StaticClass()));
332 }
333 template<>
335 {
336 return ResolveMemberFunction(SelfScope, bAlwaysFollowRedirects);
337 }
338
340 template<class TFieldType>
342 {
343 return ResolveMember<TFieldType>(SelfScope->SkeletonGeneratedClass);
344 }
345
356 ENGINE_API static UField* FindRemappedField(UClass *FieldClass, UClass* InitialScope, FName InitialName,
358 ENGINE_API static FField* FindRemappedField(FFieldClass* FieldClass, UClass* InitialScope, FName InitialName,
360
362 template<class TFieldType>
369
370#if WITH_EDITOR
372 ENGINE_API static void InitFieldRedirectMap();
373
374protected:
375
378
381#endif
382 template<class TFieldType, class TFieldTypeClass>
384
385 ENGINE_API FProperty* ResolveMemberProperty(UClass* SelfScope, const bool bAlwaysFollowRedirects, FFieldClass* FieldClass) const;
386 ENGINE_API UFunction* ResolveMemberFunction(UClass* SelfScope, const bool bAlwaysFollowRedirects) const;
387
388public:
389 template<class TFieldType>
391 {
392 OutReference.Reset();
393
394 if (InField)
395 {
398
399 OutReference.MemberName = TempMemberReference.MemberName;
400 OutReference.MemberParent = TempMemberReference.MemberParent;
401 OutReference.MemberGuid = TempMemberReference.MemberGuid;
402 }
403 }
404
405 template<class TFieldType>
407 {
409
410 const FName Name = Reference.MemberGuid.IsValid() ? NAME_None : Reference.MemberName; // if the guid is valid don't check the name, it could be renamed
411 TempMemberReference.MemberName = Name;
412 TempMemberReference.MemberGuid = Reference.MemberGuid;
413 TempMemberReference.MemberParent = Reference.MemberParent;
414
415 auto Result = TempMemberReference.ResolveMember<TFieldType>(SelfScope);
416 if (!Result && (Name != Reference.MemberName))
417 {
418 TempMemberReference.MemberName = Reference.MemberName;
419 Result = TempMemberReference.ResolveMember<TFieldType>(SelfScope);
420 }
421
422 return Result;
423 }
424};
425
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define HEADER_GENERATED_DELEGATE_SIGNATURE_SUFFIX
Definition Delegate.h:197
#define UPROPERTY(...)
UObject definition macros.
Definition ObjectMacros.h:744
#define USTRUCT(...)
Definition ObjectMacros.h:746
#define GENERATED_USTRUCT_BODY(...)
Definition ObjectMacros.h:767
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Field.h:66
Definition Field.h:353
T * Get() const
Definition Field.h:465
Definition Field.h:556
Definition NameTypes.h:617
Definition UnrealType.h:174
Definition UnrealString.h.inl:34
Definition SubclassOf.h:30
Definition Blueprint.h:403
Definition Class.h:3793
Definition Class.h:181
COREUOBJECT_API UClass * GetOwnerClass() const
Definition Class.cpp:212
Definition Class.h:2476
COREUOBJECT_API UPackage * GetOutermost() const
Definition UObjectBaseUtility.cpp:224
Definition Object.h:95
Definition Package.h:216
Definition Class.h:480
@ false
Definition radaudio_common.h:23
Definition MemberReference.h:19
friend uint32 GetTypeHash(const FFieldRemapInfo &RemapInfo)
Definition MemberReference.h:31
bool operator==(const FFieldRemapInfo &Other) const
Definition MemberReference.h:26
FName FieldClass
Definition MemberReference.h:24
FFieldRemapInfo()
Definition MemberReference.h:36
FName FieldName
Definition MemberReference.h:21
Definition Guid.h:109
Definition MemberReference.h:65
UStruct * GetMemberScope(UClass *InMemberParentClass) const
Definition MemberReference.h:289
void SetFromField(const typename TFieldType::BaseFieldClass *InField, const bool bIsConsideredSelfContext, UClass *OwnerClass=nullptr)
Definition MemberReference.h:108
FName GetMemberName() const
Definition MemberReference.h:203
FString GetMemberScopeName() const
Definition MemberReference.h:295
UClass * GetMemberParentClass(UClass *SelfScope) const
Definition MemberReference.h:282
static TFieldType * FindRemappedField(UClass *InitialScope, FName InitialName, bool bInitialScopeMustBeOwnerOfFieldForParentScopeRedirect=false)
Definition MemberReference.h:363
bool IsDeprecated() const
Definition MemberReference.h:312
UFunction * ResolveMember(UClass *SelfScope, const bool bAlwaysFollowRedirects) const
Definition MemberReference.h:334
static TFieldType * ResolveSimpleMemberReference(const FSimpleMemberReference &Reference, UClass *SelfScope=nullptr)
Definition MemberReference.h:406
bool IsSelfContext() const
Definition MemberReference.h:240
bool IsLocalScope() const
Definition MemberReference.h:246
UClass * GetScope(UClass *SelfScope=nullptr) const
Definition MemberReference.h:318
TFieldType * ResolveMember(UBlueprint *SelfScope)
Definition MemberReference.h:341
FGuid GetMemberGuid() const
Definition MemberReference.h:216
bool IsSameReference(const FMemberReference &InReference) const
Definition MemberReference.h:301
UClass * GetMemberParentClass() const
Definition MemberReference.h:221
static void FillSimpleMemberReference(const TFieldType *InField, FSimpleMemberReference &OutReference)
Definition MemberReference.h:390
UPackage * GetMemberParentPackage() const
Definition MemberReference.h:226
TFieldType * ResolveMember(UClass *SelfScope=nullptr, const bool bAlwaysFollowRedirects=false) const
Definition MemberReference.h:329
Definition MemberReference.h:45
FName NewParam
Definition MemberReference.h:48
FParamRemapInfo()
Definition MemberReference.h:53
TMap< FString, FString > ParamValueMap
Definition MemberReference.h:50
bool bCustomValueMapping
Definition MemberReference.h:46
FName OldParam
Definition MemberReference.h:47
FName NodeTitle
Definition MemberReference.h:49
Definition EdGraphPin.h:27
Definition ObjectPtr.h:488