UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
AssetDataMap.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
6#include "Containers/Array.h"
7#include "Containers/Set.h"
9#include "HAL/Platform.h"
10#include "Math/NumericLimits.h"
12#include "Misc/Optional.h"
13#include "Misc/StringBuilder.h"
14#include "Templates/Function.h"
15#include "Templates/UniquePtr.h"
17#include "UObject/NameTypes.h"
18
19struct FSoftObjectPath;
20template <typename ElementType, typename KeyFuncs> class TSetKeyFuncs;
21
47#ifndef UE_ASSETREGISTRY_INDIRECT_ASSETDATA_POINTERS
48#define UE_ASSETREGISTRY_INDIRECT_ASSETDATA_POINTERS 0
49#endif
50
52{
53
54/*
55* Key type for TSet<FAssetData*> in the asset registry.
56* Top level assets are searched for by their asset path as two names (e.g. '/Path/ToPackageName' + 'AssetName')
57* Other assets (e.g. external actors) are searched for by their full path with the whole outer chain as a single name.
58* (e.g. '/Path/To/Package.TopLevel:Subobject' + 'DeeperSubobject')
59*/
61{
62 explicit FCachedAssetKey(const FAssetData* InAssetData);
63 explicit FCachedAssetKey(const FAssetData& InAssetData);
66
67 FString ToString() const;
68 int32 Compare(const FCachedAssetKey& Other) const; // Order asset keys with fast non-lexical comparison
69 void AppendString(FStringBuilderBase& Builder) const;
70
73};
74
76inline bool operator==(const FCachedAssetKey& A, const FCachedAssetKey& B);
77inline bool operator!=(const FCachedAssetKey& A, const FCachedAssetKey& B);
78inline uint32 GetTypeHash(const FCachedAssetKey& A);
79
80/*
81* Policy type for TSet<FAssetData*> to use FCachedAssetKey for hashing/equality.
82* This allows us to store just FAssetData* in the map without storing an extra copy of the key fields to save memory.
83*/
85{
87 using ElementInitType = void; // TSet doesn't actually use this type
88
89 enum { bAllowDuplicateKeys = false };
90
91 static inline KeyInitType GetSetKey(const FAssetData* Element)
92 {
93 return FCachedAssetKey(*Element);
94 }
95
96 static inline bool Matches(KeyInitType A, KeyInitType B)
97 {
98 return A == B;
99 }
100
101 static inline uint32 GetKeyHash(KeyInitType Key)
102 {
103 return GetTypeHash(Key);
104 }
105};
106
107#if !UE_ASSETREGISTRY_INDIRECT_ASSETDATA_POINTERS
108
115
116#else
117
121
124
131class FAssetDataMap
132{
133public:
134 struct FIterator;
135
140
141 ASSETREGISTRY_API void Empty(int32 ReservedSize = 0);
148 ASSETREGISTRY_API void AddKeyLookup(FAssetData* AssetData, FAssetDataPtrIndex AssetIndex, bool* bAlreadyInSet = nullptr);
155
157 ASSETREGISTRY_API SIZE_T GetAllocatedSize() const;
159 ASSETREGISTRY_API int32 GetMaxIndex() const;
160 ASSETREGISTRY_API bool IsValidId(FSetElementId SetId) const;
162
163 ASSETREGISTRY_API bool Contains(const FCachedAssetKey& Key) const;
164 ASSETREGISTRY_API FAssetData* const* Find(const FCachedAssetKey& Key) const;
166 ASSETREGISTRY_API FAssetData* operator[](FAssetDataPtrIndex AssetIndex) const;
167
169 ASSETREGISTRY_API void Enumerate(TFunctionRef<bool(FAssetData& AssetData, FAssetDataPtrIndex AssetIndex)> Callback) const;
170
171 ASSETREGISTRY_API FIterator begin() const;
172 ASSETREGISTRY_API FIterator end() const;
173
174public:
176 struct FIterator
177 {
179
181 ASSETREGISTRY_API FIterator& operator++();
182 ASSETREGISTRY_API bool operator!=(const FIterator& Other) const;
183
184 const FAssetDataMap& Owner;
185 int32 Index;
186 };
187
188private:
196 static bool IsInUse(const FAssetData* DataFromAssetDatas);
200 bool AssetByObjectNameValueMatches(FAssetDataPtrIndex Value, const FCachedAssetKey& Key) const;
201
202private:
203 TUniquePtr<FAssetObjectNameSet> AssetByObjectName; // TUniquePtr for implementation hiding
204 TArray<FAssetData*> AssetDatas;
206 int32 NumFree = 0;
207
208 friend struct FAssetObjectNameKeyFuncs;
209};
210
213
221{
223 FAssetDataOrArrayIndex() = default;
227
228 bool IsEmptyList() const;
229 bool IsAssetDataPtrIndex() const;
230 bool IsAssetDataArrayIndex() const;
231 bool operator==(const FAssetDataOrArrayIndex& Other) const;
232 bool operator!=(const FAssetDataOrArrayIndex& Other) const;
233
236
237public:
238 // Implementation details for classes that need to make assumptions about the conversion
239 static constexpr uint32 EmptyList = 0xffff'ffff;
240 static constexpr uint32 TypeMask = 0x8000'0000;
241 static constexpr uint32 AssetDataType = 0x0000'0000;
242 static constexpr uint32 ArrayType = 0x8000'0000;
243
244private:
245 uint32 Value = EmptyList;
246};
247
255{
256public:
257 struct FIterator;
258
263
264 ASSETREGISTRY_API SIZE_T GetAllocatedSize() const;
267
268private:
269 static constexpr uint32 UnusedIndex = static_cast<uint32>(~0);
270
278 struct FArrayOrNextIndex
279 {
280 union
281 {
283 uint32 NextIndex;
284 };
285 bool bArray;
286
290 FArrayOrNextIndex& operator=(const FArrayOrNextIndex& Other) = delete;
291 FArrayOrNextIndex& operator=(FArrayOrNextIndex&& Other) = delete;
293 };
294
297
298private:
300 uint32 FreeList = UnusedIndex;
301};
302
311
319{
320public:
321 struct FIterator;
322 struct FIterationSentinel;
323 using KeyType = FName;
324
328
329 ASSETREGISTRY_API void Empty(int32 ReservedSize=0);
330 ASSETREGISTRY_API void Add(FName PackageName, FAssetDataPtrIndex AssetIndex);
331 ASSETREGISTRY_API int32 Remove(FName PackageName, FAssetDataPtrIndex AssetIndex);
333
336
337 ASSETREGISTRY_API void GenerateKeyArray(TArray<FName>& OutKeys) const;
344 ASSETREGISTRY_API bool Contains(FName PackageName) const;
345 ASSETREGISTRY_API FIterator begin() const;
346 ASSETREGISTRY_API FIterationSentinel end() const;
347
348public:
349 // We don't handle these copy/moves because we rely on references to some other containers
352 FAssetPackageNameMap& operator=(const FAssetPackageNameMap&& Other) = delete;
353
359 struct FIteratorValue
360 {
361 FName Key;
362 };
364 struct FIterator
365 {
366 public:
367 ASSETREGISTRY_API explicit FIterator(const FAssetPackageNameMap& InOwner);
370 ASSETREGISTRY_API FIterator& operator++();
371 ASSETREGISTRY_API bool operator!=(FIterationSentinel) const;
372 private:
375 };
376 struct FIterationSentinel
377 {
378 };
379
380private:
384
385private:
386 TUniquePtr<FAssetPackageNameSet> AssetOrArrayByPackageName; // TUniquePtr for implementation hiding
389
390 friend struct FAssetPackageNameKeyFuncs;
391};
392
393#endif // UE_ASSETREGISTRY_INDIRECT_ASSETDATA_POINTERS
394
395} // namespace UE::AssetRegistry::Private
396
397
399// Inline implementations
401
402
404{
405
407{
408 return A ^ (B + 0x9e3779b9 + (A << 6) + (A >> 2));
409}
410
412{
413 if (!InAssetData)
414 {
415 return;
416 }
417
418#if WITH_EDITORONLY_DATA
419 if (!InAssetData->GetOptionalOuterPathName().IsNone())
420 {
421 OuterPath = InAssetData->GetOptionalOuterPathName();
422 }
423 else
424#endif
425 {
426 OuterPath = InAssetData->PackageName;
427 }
428 ObjectName = InAssetData->AssetName;
429}
430
435
437 : OuterPath(InAssetPath.GetPackageName())
438 , ObjectName(InAssetPath.GetAssetName())
439{
440}
441
443{
444 if (InObjectPath.GetAssetFName().IsNone())
445 {
446 // Packages themselves never appear in the asset registry
447 return;
448 }
449 else if (InObjectPath.GetSubPathString().IsEmpty())
450 {
451 // If InObjectPath represents a top-level asset we can just take the existing FNames.
452 OuterPath = InObjectPath.GetLongPackageFName();
453 ObjectName = InObjectPath.GetAssetFName();
454 }
455 else
456 {
457 // If InObjectPath represents a subobject we need to split the path into the path of the outer and the name of the innermost object.
459 InObjectPath.ToString(Builder);
460
461 const FAssetPathParts Parts = SplitIntoOuterPathAndAssetName(Builder);
462
463 // This should be impossible as at bare minimum concatenating the package name and asset name should add a separator
464 check(!Parts.OuterPath.IsEmpty() && !Parts.InnermostName.IsEmpty());
465
466 // Don't create FNames for this query struct. If the AssetData exists to find, the FName will already exist due to OptionalOuterPath on FAssetData.
469 }
470}
471inline FString FCachedAssetKey::ToString() const
472{
474 AppendString(Builder);
475 return FString(Builder);
476}
477
479{
480 if (OuterPath == Other.OuterPath)
481 {
482 return ObjectName.CompareIndexes(Other.ObjectName);
483 }
484 else
485 {
486 return OuterPath.CompareIndexes(Other.OuterPath);
487 }
488}
489
494
496{
497 Key.AppendString(Builder);
498 return Builder;
499}
500
501inline bool operator==(const FCachedAssetKey& A, const FCachedAssetKey& B)
502{
503 return A.OuterPath == B.OuterPath && A.ObjectName == B.ObjectName;
504}
505
506inline bool operator!=(const FCachedAssetKey& A, const FCachedAssetKey& B)
507{
508 return A.OuterPath != B.OuterPath || A.ObjectName != B.ObjectName;
509}
510
512{
513 return HashCombineQuick(GetTypeHash(A.OuterPath), GetTypeHash(A.ObjectName));
514}
515
516#if UE_ASSETREGISTRY_INDIRECT_ASSETDATA_POINTERS
517
518inline FAssetDataOrArrayIndex FAssetDataOrArrayIndex::CreateEmptyList()
519{
520 return FAssetDataOrArrayIndex();
521}
522
523inline FAssetDataOrArrayIndex FAssetDataOrArrayIndex::CreateAssetDataPtrIndex(FAssetDataPtrIndex AssetIndex)
524{
525 uint32 InValue = static_cast<uint32>(AssetIndex);
526 checkf((InValue & TypeMask) == 0,
527 TEXT("FAssetDataPtrIndex value is too large. Value == %u. Maximum supported value == 0x7fffffff."),
528 InValue);
530 Result.Value = static_cast<uint32>(InValue) | AssetDataType;
531 return Result;
532}
533
534inline FAssetDataOrArrayIndex FAssetDataOrArrayIndex::CreateArrayIndex(FAssetDataArrayIndex ArrayIndex)
535{
536 uint32 InValue = static_cast<uint32>(ArrayIndex);
537 checkf((InValue & TypeMask) == 0,
538 TEXT("FAssetDataArrayIndex value is too large. Value == %u. Maximum supported value == 0x7fffffff."),
539 InValue);
541 Result.Value = static_cast<uint32>(InValue) | ArrayType;
542 return Result;
543}
544
545inline bool FAssetDataOrArrayIndex::IsEmptyList() const
546{
547 return Value == EmptyList;
548}
549
550inline bool FAssetDataOrArrayIndex::IsAssetDataPtrIndex() const
551{
552 return (Value & TypeMask) == AssetDataType;
553}
554
555inline bool FAssetDataOrArrayIndex::IsAssetDataArrayIndex() const
556{
557 return (Value != EmptyList) & ((Value & TypeMask) == ArrayType);
558}
559
560inline bool FAssetDataOrArrayIndex::operator==(const FAssetDataOrArrayIndex& Other) const
561{
562 return Value == Other.Value;
563}
564
565inline bool FAssetDataOrArrayIndex::operator!=(const FAssetDataOrArrayIndex& Other) const
566{
567 return Value != Other.Value;
568}
569
570inline FAssetDataPtrIndex FAssetDataOrArrayIndex::AsAssetDataPtrIndex() const
571{
572 return static_cast<FAssetDataPtrIndex>(Value & ~TypeMask);
573}
574
575inline FAssetDataArrayIndex FAssetDataOrArrayIndex::AsAssetDataArrayIndex() const
576{
577 return static_cast<FAssetDataPtrIndex>(Value & ~TypeMask);
578}
579
580inline FIndirectAssetDataArrays::FArrayOrNextIndex::FArrayOrNextIndex()
581 : NextIndex(UnusedIndex)
582 , bArray(false)
583{
584}
585
586inline FIndirectAssetDataArrays::FArrayOrNextIndex::FArrayOrNextIndex(FArrayOrNextIndex&& Other)
587{
588 if (Other.bArray)
589 {
590 bArray = true;
592
594 Other.bArray = false;
595 Other.NextIndex = UnusedIndex;
596 }
597 else
598 {
599 bArray = false;
600 NextIndex = Other.NextIndex;
601 Other.NextIndex = UnusedIndex;
602 }
603}
604
605inline FIndirectAssetDataArrays::FArrayOrNextIndex::~FArrayOrNextIndex()
606{
607 if (bArray)
608 {
609 Array.~TArray<FAssetDataPtrIndex>();
610 bArray = false;
611 NextIndex = UnusedIndex;
612 }
613}
614
615#endif // UE_ASSETREGISTRY_INDIRECT_ASSETDATA_POINTERS
616
617} // namespace UE::AssetRegistry::Private
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
#define check(expr)
Definition AssertionMacros.h:314
#define checkf(expr, format,...)
Definition AssertionMacros.h:315
UE_FORCEINLINE_HINT FLinearColor operator*(float Scalar, const FLinearColor &Color)
Definition Color.h:473
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::SIZE_T SIZE_T
An unsigned integer the same size as a pointer, the same as UPTRINT.
Definition Platform.h:1150
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
UE_FORCEINLINE_HINT bool operator!=(const FIndexedPointer &Other) const
Definition LockFreeList.h:76
@ Num
Definition MetalRHIPrivate.h:234
@ FNAME_Find
Definition NameTypes.h:209
#define MAX_uint32
Definition NumericLimits.h:21
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition NameTypes.h:617
FORCEINLINE int32 CompareIndexes(const FName &Other) const
Definition NameTypes.h:935
Definition SetUtilities.h:95
Definition Array.h:670
~TArray()
Definition Array.h:992
Definition AssetRegistryState.h:50
Definition SetKeyFuncs.h:44
const CharType * ToString() UE_LIFETIMEBOUND
Definition StringBuilder.h:135
Definition StringBuilder.h:509
constexpr bool IsEmpty() const
Definition StringView.h:180
Definition UniquePtr.h:107
@ Contains
Definition AutomationTest.h:160
SIZE_T GetAllocatedSize(const T &Value)
Definition ManagedArray.h:93
Definition AssetRegistryImpl.h:48
void ConcatenateOuterPathAndObjectName(FStringBuilderBase &Builder, FName OuterPath, FName ObjectName)
Definition AssetData.cpp:114
FAssetPathParts SplitIntoOuterPathAndAssetName(FStringView InObjectPath)
Definition AssetData.cpp:103
bool operator!=(const FCachedAssetKey &A, const FCachedAssetKey &B)
Definition AssetDataMap.h:506
FStringBuilderBase & operator<<(FStringBuilderBase &Builder, const FCachedAssetKey &Key)
Definition AssetDataMap.h:495
TSet< const FAssetData *, FCachedAssetKeyFuncs > FConstAssetDataMap
Definition AssetDataMap.h:114
uint32 HashCombineQuick(uint32 A, uint32 B)
Definition AssetDataMap.h:406
TSet< FAssetData *, FCachedAssetKeyFuncs > FAssetDataMap
Definition AssetDataMap.h:113
bool operator==(const FCachedAssetKey &A, const FCachedAssetKey &B)
Definition AssetDataMap.h:501
uint32 GetTypeHash(const FCachedAssetKey &A)
Definition AssetDataMap.h:511
FORCEINLINE FStridedReferenceIterator begin(FStridedReferenceView View)
Definition FastReferenceCollector.h:490
FORCEINLINE FStridedReferenceIterator end(FStridedReferenceView View)
Definition FastReferenceCollector.h:491
@ false
Definition radaudio_common.h:23
U16 Index
Definition radfft.cpp:71
Definition AssetData.h:162
Definition SoftObjectPath.h:56
Definition TopLevelAssetPath.h:38
Definition TypeCompatibleBytes.h:17
Definition Optional.h:131
FStringView OuterPath
Definition AssetData.h:133
FStringView InnermostName
Definition AssetData.h:134
void ElementInitType
Definition AssetDataMap.h:87
static KeyInitType GetSetKey(const FAssetData *Element)
Definition AssetDataMap.h:91
@ bAllowDuplicateKeys
Definition AssetDataMap.h:89
static bool Matches(KeyInitType A, KeyInitType B)
Definition AssetDataMap.h:96
static uint32 GetKeyHash(KeyInitType Key)
Definition AssetDataMap.h:101
void AppendString(FStringBuilderBase &Builder) const
Definition AssetDataMap.h:490
FName ObjectName
Definition AssetDataMap.h:72
FName OuterPath
Definition AssetDataMap.h:71
FString ToString() const
Definition AssetDataMap.h:471
int32 Compare(const FCachedAssetKey &Other) const
Definition AssetDataMap.h:478
FCachedAssetKey(const FAssetData *InAssetData)
Definition AssetDataMap.h:411