UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
AssetDataGatherer.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"
10#include "Containers/Map.h"
17#include "DiskCachedAssetData.h"
18#include "HAL/CriticalSection.h"
19#include "HAL/FileManager.h"
20#include "HAL/Platform.h"
21#include "HAL/Runnable.h"
22#include "Misc/DateTime.h"
23#include "Misc/Optional.h"
27#include "Templates/UniquePtr.h"
28#include "UObject/NameTypes.h"
29
30#include <atomic>
31
32class FArchive;
34class FAssetRegistryWriter; // Not defined if !ALLOW_NAME_BATCH_SAVING
36struct FAssetData;
37namespace UE::AssetDataGather { struct FResults; }
38namespace UE::AssetDataGather::Private { class FAssetDataDiscovery; }
39namespace UE::AssetDataGather::Private { class FFileReadScheduler; }
40namespace UE::AssetDataGather::Private { class FFilesToSearch; }
41namespace UE::AssetDataGather::Private { struct FCachePayload; }
42namespace UE::AssetDataGather::Private { struct FDirectoryReadTaskData; }
43namespace UE::AssetDataGather::Private { struct FGatheredPathData; }
44namespace UE::AssetDataGather::Private { struct FPathExistence; }
45namespace UE::AssetDataGather::Private { struct FReadContext; }
46namespace UE::AssetDataGather::Private { struct FSetPathProperties; }
47namespace UE::AssetDataGather::Private { enum class EPriority : uint8; }
49{
66
67struct FWaitBatchDirectorySetFuncs : BaseKeyFuncs<FWaitBatchDirectory, FString>
68{
69 static FORCEINLINE const FString& GetSetKey(const FWaitBatchDirectory& Element)
70 {
71 return Element.Path;
72 }
73 static FORCEINLINE bool Matches(const FString& A, const FString& B)
74 {
75 return A.Equals(B, ESearchCase::CaseSensitive);
76 }
77 static FORCEINLINE uint32 GetKeyHash(const FString& Key)
78 {
79 return GetTypeHash(Key);
80 }
81};
82
84}
85namespace UE::AssetRegistry { class FAssetRegistryImpl; }
86namespace UE::AssetRegistry::Impl { enum class EGatherStatus : uint8; }
87
88#if DO_CHECK
91#define CHECK_IS_LOCKED_CURRENT_THREAD(CritSec) check(CritSec.IsLockedOnCurrentThread())
92#define CHECK_IS_NOT_LOCKED_CURRENT_THREAD(CritSec) check(!CritSec.IsLockedOnCurrentThread())
93#else
96#define CHECK_IS_LOCKED_CURRENT_THREAD(CritSec) do {} while (false)
97#define CHECK_IS_NOT_LOCKED_CURRENT_THREAD(CritSec) do {} while (false)
98#endif
99
101
119
120namespace UE::AssetDataGather
121{
122
153
167
168} // namespace UE::AssetDataGather
169
170
175{
176public:
178 virtual ~FAssetDataGatherer();
179
188
189 // Controlling Async behavior
190
192 void StartAsync();
193
194 // FRunnable implementation
195 virtual bool Init() override;
196 virtual uint32 Run() override;
197 virtual void Stop() override;
198 virtual void Exit() override;
199
200 bool IsAsyncEnabled() const;
201 bool IsSynchronous() const;
203 void EnsureCompletion();
204
207
219 void WaitOnPath(FStringView LocalPath);
224 void ClearCache();
225
231 void ScanPathsSynchronous(const TArray<FString>& InPaths, bool bForceRescan, bool bIgnoreDenyListScanFilters);
233 void WaitForIdle(float TimeoutSeconds = -1.0f);
239 bool IsComplete() const;
243 bool HasSerializedDiscoveryCache() const;
244
245 // Reading/writing/triggering depot-wide properties and events (possibly while tick is running)
246
250 bool IsGatheringDependencies() const;
252 bool IsCacheReadEnabled() const;
254 bool IsCacheWriteEnabled() const;
256 SIZE_T GetAllocatedSize() const;
257
258
259 // Configuring mount points (possibly while tick is running)
260
262 void AddMountPoint(FStringView LocalPath, FStringView LongPackageName);
264 void RemoveMountPoint(FStringView LocalPath);
267
268
269 // Reading/Writing properties of files and directories (possibly while tick is running)
270
272 void OnDirectoryCreated(FStringView LocalPath);
276 void PrioritizeSearchPath(const FString& PathToPrioritize);
286 void SetIsOnAllowList(FStringView LocalPath, bool bIsAllowed);
288 bool IsOnAllowList(FStringView LocalPath) const;
290 bool IsOnDenyList(FStringView LocalPath) const;
292 bool IsMonitored(FStringView LocalPath) const;
293
295 static bool IsVerseFile(FStringView FilePath);
298
311
315 void PauseProcessing() { IsProcessingPaused.fetch_add(1, std::memory_order_relaxed); }
316 void ResumeProcessing() { IsProcessingPaused.fetch_sub(1, std::memory_order_relaxed); }
317 bool IsProcessingPauseRequested() const { return IsProcessingPaused.load(std::memory_order_relaxed) != 0; }
318
319 void SetGatherOnGameThreadOnly(bool bValue);
320 bool IsGatherOnGameThreadOnly() const;
321
322 /*
323 * Mark that the gatherer is in the process of handling an additional search.
324 */
326
327private:
328 enum class ETickResult
329 {
330 KeepTicking,
331 PollDiscovery,
332 Idle,
333 Interrupt,
334 };
339 ETickResult InnerTickLoop(bool bInSynchronousTick, bool bContributeToCacheSave, double EndTimeSeconds);
344 ETickResult TickInternal(double& TickStartTime, bool bPollDiscovery);
349 UE::AssetRegistry::Impl::EGatherStatus TryTickOnBackgroundThread();
350
352 bool ShouldBackgroundGatherThreadPauseGathering(bool& bOutGathererIsIdle);
353
355 void IngestDiscoveryResults();
356
358 void OnFileCreated(FStringView LocalPath);
359
365 void SetDirectoryProperties(FStringView LocalPath, const UE::AssetDataGather::Private::FSetPathProperties& Properties);
366
372
388 bool ReadAssetFile(const FString& AssetLongPackageName, const FString& AssetFilename,
389 TArray<FAssetData*>& AssetDataList, FPackageDependencyData& DependencyData,
391
393 void ConsumeCacheFiles(TArray<UE::AssetDataGather::Private::FCachePayload> Payloads);
398 void TryReserveSaveCache(bool& bOutShouldSave, TArray<TPair<FName,FDiskCachedAssetData*>>& AssetsToSave);
400 void SaveCacheFile(const TArray<TPair<FName,FDiskCachedAssetData*>>& AssetsToSave);
407 int64 SaveCacheFileInternal(const FString& CacheFilename,
419 void GetCacheAssetsToSave(TArray<TPair<FName,FDiskCachedAssetData*>>& OutAssetsToSave);
420
421 /* Adds the given pair into NewCachedAssetDataMap. Detects collisions for multiple files with the same PackageName */
422 void AddToCache(FName PackageName, FDiskCachedAssetData* DiskCachedAssetData);
423
428 void SetIsIdle(bool IsIdle);
429 void SetIsIdle(bool IsIdle, double& TickStartTime);
430
432 void Shrink();
433
435 struct FScopedGatheringPause
436 {
437 FScopedGatheringPause(const FAssetDataGatherer& InOwner);
438 ~FScopedGatheringPause();
440 };
441
443 static FString NormalizeLocalPath(FStringView LocalPath);
445 static FStringView NormalizeLongPackageName(FStringView LongPackageName);
446
447private:
448
453 mutable FGathererCriticalSection TickLock;
458 mutable FGathererCriticalSection ResultsLock;
459
461 FGatheredResultsEvent GatheredResultsEvent;
462
463 // Variable section for variables that are constant during threading.
465
471 FRunnableThread* Thread;
472
477 bool bAsyncEnabled;
479 bool bGatherAssetPackageData;
481 bool bGatherDependsData;
482
484 FDateTime GatherStartTime;
485
486 // Variable section for variables that are atomics read/writable from outside critical sections.
487
489 std::atomic<uint32> IsStopped;
491 mutable std::atomic<uint32> IsGatheringPaused;
492
494 mutable std::atomic<uint32> IsProcessingPaused;
495
502 std::atomic<bool> bSaveAsyncCacheTriggered;
504 std::atomic<bool> bCacheReadEnabled;
506 std::atomic<bool> bCacheWriteEnabled;
507
508 // Variable section for variables that are read/writable only within ResultsLock.
509
512
514 TArray<TUniquePtr<FAssetData>> AssetResults;
516 TArray<TUniquePtr<FAssetData>> AssetResultsForGameThread;
518 TArray<FPackageDependencyData> DependencyResults;
520 TArray<FPackageDependencyData> DependencyResultsForGameThread;
525 TArray<FString> CookedPackageNamesWithoutAssetDataResults;
527 TArray<FName> VerseResults;
529 TArray<FString> BlockedResults;
530
532 TArray<double> SearchTimes;
534 float CumulativeGatherTime = 0.f;
535
537 TArray<FString> DiscoveredPaths;
538
540 double CurrentSearchTime = 0.;
542 double LastCacheWriteTime;
544 int32 NumPathsToSearchAtLastSyncPoint;
546 int32 NumCachedAssetFiles = 0;
548 int32 NumUncachedAssetFiles = 0;
550 int32 NumUncachedAssetFilesOutstanding = 0;
552 bool bHasLoadedCache;
554 bool bDiscoveryIsComplete;
556 bool bIsComplete;
558 bool bRequestAssetRegistryTick;
560 bool bIsIdle;
562 bool bFirstTickAfterIdle;
564 bool bFinishedInitialDiscovery;
566 std::atomic<bool> bIsInitialSearchCompleted;
568 std::atomic<bool> bIsAdditionalMountSearchInProgress;
569 std::atomic<bool> bGatherOnGameThreadOnly;
570
571 // Variable section for variables that are read/writable only within TickLock.
572
577 TArray<FDiskCachedAssetData*> NewCachedAssetData;
578 TArray<TPair<int32, FDiskCachedAssetData*>> DiskCachedAssetBlocks;
583 TMap<FName, FDiskCachedAssetData*> DiskCachedAssetDataMap;
585 TMap<FName, FDiskCachedAssetData*> NewCachedAssetDataMap;
587 int32 LastCacheSaveNumUncachedAssetFiles;
592 int32 CacheInUseCount;
597 bool bSynchronousTick;
599 bool bIsSavingAsyncCache;
601 bool bFlushedRetryFiles;
606};
607
608
610// Inline implementations
612
614{
615 bSaveAsyncCacheTriggered = true;
616}
617
619{
620 return GatheredResultsEvent;
621}
622
624{
625 bGatherOnGameThreadOnly.store(bValue, std::memory_order_relaxed);
626}
627
629{
630 return bGatherOnGameThreadOnly.load(std::memory_order_relaxed);
631}
632
634{
635 bIsAdditionalMountSearchInProgress.store(bIsInProgress, std::memory_order_relaxed);
636}
#define FORCEINLINE
Definition AndroidPlatform.h:140
FCriticalSection FGathererCriticalSection
Definition AssetDataGatherer.h:94
FScopeLock FGathererScopeLock
Definition AssetDataGatherer.h:95
FPlatformTypes::SIZE_T SIZE_T
An unsigned integer the same size as a pointer, the same as UPTRINT.
Definition Platform.h:1150
FPlatformTypes::int64 int64
A 64-bit signed integer.
Definition Platform.h:1127
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::FPlatformRecursiveMutex FCriticalSection
Definition CriticalSection.h:53
#define DECLARE_TS_MULTICAST_DELEGATE_OneParam(DelegateName, Param1Type)
Definition DelegateCombinations.h:50
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition AssetRegistry.Build.cs:6
Definition Archive.h:1208
Definition AssetDataGatherer.h:175
void RequestAsyncCacheSave()
Definition AssetDataGatherer.h:613
void GetPackageResults(UE::AssetDataGather::FResults &InOutResults)
Definition AssetDataGatherer.cpp:4822
static bool ReadAssetFile(FPackageReader &PackageReader, TArray< FAssetData * > &AssetDataList, FPackageDependencyData &DependencyData, TArray< FString > &CookedPackagesToLoadUponDiscovery, FPackageReader::EReadOptions Options)
Definition AssetDataGatherer.cpp:4698
void PrioritizeSearchPath(const FString &PathToPrioritize)
Definition AssetDataGatherer.cpp:5676
bool IsOnDenyList(FStringView LocalPath) const
Definition AssetDataGatherer.cpp:5746
SIZE_T GetAllocatedSize() const
Definition AssetDataGatherer.cpp:5534
void OnAdditionalMountSearchCompleted()
Definition AssetDataGatherer.cpp:3912
virtual uint32 Run() override
Definition AssetDataGatherer.cpp:3940
void OnDirectoryCreated(FStringView LocalPath)
Definition AssetDataGatherer.cpp:5652
void SetInitialPluginsLoaded()
Definition AssetDataGatherer.cpp:5053
void OnFilesCreated(TConstArrayView< FString > LocalPaths)
Definition AssetDataGatherer.cpp:5661
void ClearCache()
Definition AssetDataGatherer.cpp:4866
void ResumeProcessing()
Definition AssetDataGatherer.h:316
bool IsMonitored(FStringView LocalPath) const
Definition AssetDataGatherer.cpp:5751
virtual ~FAssetDataGatherer()
Definition AssetDataGatherer.cpp:3844
void EnsureCompletion()
Definition AssetDataGatherer.cpp:4230
FGatheredResultsEvent & GetGatheredResultsEvent()
Definition AssetDataGatherer.h:618
void OnInitialSearchCompleted()
Definition AssetDataGatherer.cpp:3900
virtual void Stop() override
Definition AssetDataGatherer.cpp:4210
void PauseProcessing()
Definition AssetDataGatherer.h:315
bool IsComplete() const
Definition AssetDataGatherer.cpp:5040
void SetIsOnAllowList(FStringView LocalPath, bool bIsAllowed)
Definition AssetDataGatherer.cpp:5732
void SetIsAdditionalMountSearchInProgress(bool bIsInProgress)
Definition AssetDataGatherer.h:633
bool IsGatheringDependencies() const
Definition AssetDataGatherer.cpp:5059
virtual void Exit() override
Definition AssetDataGatherer.cpp:4216
bool IsCacheReadEnabled() const
Definition AssetDataGatherer.cpp:5064
void AddRequiredMountPoints(TArrayView< FString > LocalPaths)
Definition AssetDataGatherer.cpp:5629
static TConstArrayView< const TCHAR * > GetVerseFileExtensions()
Definition AssetDataGatherer.cpp:5771
bool IsProcessingPauseRequested() const
Definition AssetDataGatherer.h:317
bool IsOnAllowList(FStringView LocalPath) const
Definition AssetDataGatherer.cpp:5741
bool IsAsyncEnabled() const
Definition AssetDataGatherer.cpp:4220
FAssetGatherDiagnostics GetDiagnostics()
Definition AssetDataGatherer.cpp:4810
void GetAndTrimSearchResults(UE::AssetDataGather::FResults &InOutResults, UE::AssetDataGather::FResultContext &OutContext)
Definition AssetDataGatherer.cpp:4762
void WaitForIdle(float TimeoutSeconds=-1.0f)
Definition AssetDataGatherer.cpp:4992
void RemoveMountPoint(FStringView LocalPath)
Definition AssetDataGatherer.cpp:5624
bool IsCacheWriteEnabled() const
Definition AssetDataGatherer.cpp:5069
void AddMountPoint(FStringView LocalPath, FStringView LongPackageName)
Definition AssetDataGatherer.cpp:5612
void StartAsync()
Definition AssetDataGatherer.cpp:3924
void UpdateCacheForSaving()
Definition AssetDataGatherer.cpp:3862
void WaitOnPath(FStringView LocalPath)
Definition AssetDataGatherer.cpp:4850
bool HasSerializedDiscoveryCache() const
Definition AssetDataGatherer.cpp:5046
bool IsGatherOnGameThreadOnly() const
Definition AssetDataGatherer.h:628
bool IsSynchronous() const
Definition AssetDataGatherer.cpp:4225
void ScanPathsSynchronous(const TArray< FString > &InPaths, bool bForceRescan, bool bIgnoreDenyListScanFilters)
Definition AssetDataGatherer.cpp:4912
virtual bool Init() override
Definition AssetDataGatherer.cpp:3935
static bool IsVerseFile(FStringView FilePath)
Definition AssetDataGatherer.cpp:5759
void SetGatherOnGameThreadOnly(bool bValue)
Definition AssetDataGatherer.h:623
Definition AssetRegistryArchive.h:23
Definition CriticalSectionQueryable.h:13
Definition DiskCachedAssetData.h:24
Definition NameTypes.h:617
Definition PackageDependencyData.h:12
Definition PackageReader.h:20
EReadOptions
Definition PackageReader.h:109
Definition RunnableThread.h:20
Definition Runnable.h:20
Definition CriticalSectionQueryable.h:72
Definition ScopeLock.h:141
Definition ArrayView.h:139
Definition Array.h:670
UE_NODEBUG UE_FORCEINLINE_HINT SIZE_T GetAllocatedSize(void) const
Definition Array.h:1059
UE_FORCEINLINE_HINT void Shrink()
Definition Array.h:1278
Definition UnrealString.h.inl:34
Definition RingBuffer.h:135
void Trim()
Definition RingBuffer.h:259
SIZE_T GetAllocatedSize(void) const
Definition RingBuffer.h:789
Definition UniquePtr.h:107
Definition AssetRegistry.h:21
@ CaseSensitive
Definition CString.h:23
@ Owner
Definition XmppMultiUserChat.h:25
Definition AssetDataGatherer.cpp:50
TSet< FWaitBatchDirectory, FWaitBatchDirectorySetFuncs > FWaitBatchDirectorySet
Definition AssetDataGatherer.h:83
EPriority
Definition AssetDataGathererPrivate.h:25
Definition AssetDataGatherer.cpp:50
Definition AssetDataGatherer.h:86
EGatherStatus
Definition AssetRegistryImpl.h:267
Definition PackageReader.h:15
uint32 GetTypeHash(const FPropertyPathName &Path)
Definition PropertyPathName.cpp:133
Definition SetUtilities.h:23
Definition AssetData.h:162
Definition AssetDataGatherer.h:103
int32 NumCachedDirectories
Definition AssetDataGatherer.h:111
float DiscoveryTimeSeconds
Definition AssetDataGatherer.h:105
float GatherTimeSeconds
Definition AssetDataGatherer.h:107
float WallTimeSeconds
Definition AssetDataGatherer.h:109
int32 NumUncachedAssetFiles
Definition AssetDataGatherer.h:117
int32 NumCachedAssetFiles
Definition AssetDataGatherer.h:115
int32 NumUncachedDirectories
Definition AssetDataGatherer.h:113
Definition DateTime.h:76
Definition Optional.h:131
Definition Tuple.h:652
Definition AssetDataGatherer.h:159
int32 NumFilesToSearch
Definition AssetDataGatherer.h:163
bool bIsDiscoveringFiles
Definition AssetDataGatherer.h:165
TArray< double > SearchTimes
Definition AssetDataGatherer.h:162
int32 NumPathsToSearch
Definition AssetDataGatherer.h:164
bool bIsSearching
Definition AssetDataGatherer.h:160
bool bAbleToProgress
Definition AssetDataGatherer.h:161
Definition AssetDataGatherer.h:125
TMultiMap< FName, TUniquePtr< FAssetData > > Assets
Definition AssetDataGatherer.h:126
TMultiMap< FName, FPackageDependencyData > DependenciesForGameThread
Definition AssetDataGatherer.h:130
TMultiMap< FName, FPackageDependencyData > Dependencies
Definition AssetDataGatherer.h:129
TRingBuffer< FName > VerseFiles
Definition AssetDataGatherer.h:132
TRingBuffer< FString > CookedPackageNamesWithoutAssetData
Definition AssetDataGatherer.h:131
TArray< FString > BlockedFiles
Definition AssetDataGatherer.h:133
void Shrink()
Definition AssetDataGatherer.h:141
SIZE_T GetAllocatedSize() const
Definition AssetDataGatherer.h:135
TMultiMap< FName, TUniquePtr< FAssetData > > AssetsForGameThread
Definition AssetDataGatherer.h:127
TRingBuffer< FString > Paths
Definition AssetDataGatherer.h:128
Definition AssetDataGathererPrivate.h:39
static FORCEINLINE uint32 GetKeyHash(const FString &Key)
Definition AssetDataGatherer.h:77
static FORCEINLINE const FString & GetSetKey(const FWaitBatchDirectory &Element)
Definition AssetDataGatherer.h:69
static FORCEINLINE bool Matches(const FString &A, const FString &B)
Definition AssetDataGatherer.h:73
Definition AssetDataGatherer.h:51
FString Path
Definition AssetDataGatherer.h:63
friend int32 GetTypeHash(const FWaitBatchDirectory &WaitBatchDirectory)
Definition AssetDataGatherer.h:58
FWaitBatchDirectory(const FStringView InPath, const bool InIsRecursive)
Definition AssetDataGatherer.h:52
bool bIsRecursive
Definition AssetDataGatherer.h:64