UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
AssetRegistryConsoleCommands.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
9#include "HAL/FileManager.h"
10#include "Misc/PackageName.h"
11#include "Misc/Paths.h"
12
13#define LOCTEXT_NAMESPACE "AssetRegistry"
14
16{
17public:
18
29
32 TEXT( "AssetRegistry.GetByName" ),
33 *LOCTEXT("CommandText_GetByName", "<PackageName> //Query the asset registry for assets matching the supplied package name").ToString(),
36 TEXT( "AssetRegistry.GetByPath" ),
37 *LOCTEXT("CommandText_GetByPath", "<Path> //Query the asset registry for assets matching the supplied package path").ToString(),
40 TEXT( "AssetRegistry.GetByClass" ),
41 *LOCTEXT("CommandText_GetByClass", "<ClassName> //Query the asset registry for assets matching the supplied class").ToString(),
44 TEXT( "AssetRegistry.GetByTag" ),
45 *LOCTEXT("CommandText_GetByTag", "<TagName> <TagValue> //Query the asset registry for assets matching the supplied tag and value").ToString(),
48 TEXT( "AssetRegistry.GetDependencies" ),
49 *LOCTEXT("CommandText_GetDependencies", "<PackageName> //Query the asset registry for dependencies for the specified package").ToString(),
52 TEXT( "AssetRegistry.GetReferencers" ),
53 *LOCTEXT("CommandText_GetReferencers", "<ObjectPath> //Query the asset registry for referencers for the specified package").ToString(),
56 TEXT( "AssetRegistry.Debug.FindInvalidUAssets" ),
57 *LOCTEXT("CommandText_FindInvalidUAssets", "Finds a list of all assets which are in UAsset files but do not share the name of the package").ToString(),
60 TEXT("AssetRegistry.ScanPath"),
61 *LOCTEXT("CommandText_ScanPath", "<PathToScan> //Scan the given filename or directoryname for package files and load them into the assetregistry. Extra string parameters: -forcerescan, -ignoreDenyLists, -asfile, -asdir").ToString(),
64 TEXT("AssetRegistry.DumpAllocatedSize"),
65 *LOCTEXT("CommandText_DumpAllocatedSize", "Dump the allocations of the asset registry state to the log").ToString(),
68 TEXT("AssetRegistry.DumpState"),
69 *LOCTEXT("CommandText_DumpState", "Dump the state of the asset registry to a file. Pass -log to dump to the log as well. Extra string parameters: All, ObjectPath, PackageName, Path, Class, Tag, Dependencies, DependencyDetails, PackageData, AssetBundles, AssetTags").ToString(),
71 {}
72
73 void GetByName(const TArray<FString>& Args)
74 {
75 if ( Args.Num() < 1 )
76 {
77 UE_LOG(LogAssetRegistry, Log, TEXT("Usage: AssetRegistry.GetByName PackageName"));
78 return;
79 }
80
81 TArray<FAssetData> AssetData;
82 const FName AssetPackageName = FName(*Args[0]);
84 UE_LOG(LogAssetRegistry, Log, TEXT("GetAssetsByPackageName for %s:"), *AssetPackageName.ToString());
85 for (int32 AssetIdx = 0; AssetIdx < AssetData.Num(); ++AssetIdx)
86 {
87 AssetData[AssetIdx].PrintAssetData();
88 }
89 }
90
91 void GetByPath(const TArray<FString>& Args)
92 {
93 if ( Args.Num() < 1 )
94 {
95 UE_LOG(LogAssetRegistry, Log, TEXT("Usage: AssetRegistry.GetByPath Path"));
96 return;
97 }
98
99 TArray<FAssetData> AssetData;
100 const FName AssetPath = FName(*Args[0]);
101 IAssetRegistry::GetChecked().GetAssetsByPath(AssetPath, AssetData);
102 UE_LOG(LogAssetRegistry, Log, TEXT("GetAssetsByPath for %s:"), *AssetPath.ToString());
103 for (int32 AssetIdx = 0; AssetIdx < AssetData.Num(); ++AssetIdx)
104 {
105 AssetData[AssetIdx].PrintAssetData();
106 }
107 }
108
109 void GetByClass(const TArray<FString>& Args)
110 {
111 if ( Args.Num() < 1 )
112 {
113 UE_LOG(LogAssetRegistry, Log, TEXT("Usage: AssetRegistry.GetByClass ClassPathname"));
114 return;
115 }
116
117 TArray<FAssetData> AssetData;
118 const FTopLevelAssetPath ClassPathName(Args[0]);
119 if (!ClassPathName.IsNull())
120 {
122 UE_LOG(LogAssetRegistry, Log, TEXT("GetAssetsByClass for %s:"), *ClassPathName.ToString());
123 for (int32 AssetIdx = 0; AssetIdx < AssetData.Num(); ++AssetIdx)
124 {
125 AssetData[AssetIdx].PrintAssetData();
126 }
127 }
128 else
129 {
130 UE_LOG(LogAssetRegistry, Error, TEXT("not a valid class path name (E.g. /Script/Engine.Actor)"));
131 }
132 }
133
134 void GetByTag(const TArray<FString>& Args)
135 {
136 if ( Args.Num() < 2 )
137 {
138 UE_LOG(LogAssetRegistry, Log, TEXT("Usage: AssetRegistry.GetByTag TagName TagValue"));
139 return;
140 }
141
142 TMultiMap<FName, FString> TagsAndValues;
143 TagsAndValues.Add(FName(*Args[0]), Args[1]);
144
145 TArray<FAssetData> AssetData;
146 IAssetRegistry::GetChecked().GetAssetsByTagValues(TagsAndValues, AssetData);
147 UE_LOG(LogAssetRegistry, Log, TEXT("GetAssetsByTagValues for Tag'%s' and Value'%s':"), *Args[0], *Args[1]);
148 for (int32 AssetIdx = 0; AssetIdx < AssetData.Num(); ++AssetIdx)
149 {
150 AssetData[AssetIdx].PrintAssetData();
151 }
152 }
153
155 {
156 if ( Args.Num() < 1 )
157 {
158 UE_LOG(LogAssetRegistry, Log, TEXT("Usage: AssetRegistry.GetDependencies PackageName"));
159 return;
160 }
161
162 const FName PackageName = FName(*Args[0]);
163 TArray<FName> Dependencies;
164
165 if ( IAssetRegistry::GetChecked().GetDependencies(PackageName, Dependencies) )
166 {
167 UE_LOG(LogAssetRegistry, Log, TEXT("Dependencies for %s:"), *PackageName.ToString());
168 for ( auto DependencyIt = Dependencies.CreateConstIterator(); DependencyIt; ++DependencyIt )
169 {
170 UE_LOG(LogAssetRegistry, Log, TEXT(" %s"), *(*DependencyIt).ToString());
171 }
172 }
173 else
174 {
175 UE_LOG(LogAssetRegistry, Log, TEXT("Could not find dependency data for %s:"), *PackageName.ToString());
176 }
177 }
178
180 {
181 if ( Args.Num() < 1 )
182 {
183 UE_LOG(LogAssetRegistry, Log, TEXT("Usage: AssetRegistry.GetReferencers ObjectPath"));
184 return;
185 }
186
187 const FName PackageName = FName(*Args[0]);
188 TArray<FName> Referencers;
189
190 if ( IAssetRegistry::GetChecked().GetReferencers(PackageName, Referencers) )
191 {
192 UE_LOG(LogAssetRegistry, Log, TEXT("Referencers for %s:"), *PackageName.ToString());
193 for ( auto ReferencerIt = Referencers.CreateConstIterator(); ReferencerIt; ++ReferencerIt )
194 {
195 UE_LOG(LogAssetRegistry, Log, TEXT(" %s"), *(*ReferencerIt).ToString());
196 }
197 }
198 else
199 {
200 UE_LOG(LogAssetRegistry, Log, TEXT("Could not find referencer data for %s:"), *PackageName.ToString());
201 }
202 }
203
205 {
206 TArray<FAssetData> AllAssets;
208
209 UE_LOG(LogAssetRegistry, Log, TEXT("Invalid UAssets:"));
210
211 for (int32 AssetIdx = 0; AssetIdx < AllAssets.Num(); ++AssetIdx)
212 {
213 const FAssetData& AssetData = AllAssets[AssetIdx];
214
215 // Note, the 'internal' version of DoesPackageExist must be used to avoid re-entering the AssetRegistry's lock resulting in deadlock
216 FPackagePath PackagePath;
217 if (FPackageName::InternalDoesPackageExistEx(AssetData.PackageName.ToString(), FPackageName::EPackageLocationFilter::Any,
218 false /*bMatchCaseOnDisk*/, &PackagePath) != FPackageName::EPackageLocationFilter::None)
219 {
220 if (PackagePath.GetHeaderExtension() == EPackageExtension::Asset && !AssetData.IsUAsset())
221 {
222 // This asset was in a package with a uasset extension but did not share the name of the package
223 UE_LOG(LogAssetRegistry, Log, TEXT("%s"), *AssetData.GetObjectPathString());
224 }
225 }
226 }
227 }
228
229 void ScanPath(const TArray<FString>& Args)
230 {
231 bool bForceRescan = false;
232 bool bIgnoreDenyList = false;
233 bool bAsFile = false;
234 bool bAsDir = false;
235
236 FString InPath;
237 for (const FString& Arg : Args)
238 {
239 if (Arg.StartsWith(TEXT("-")))
240 {
241 bForceRescan = bForceRescan || Arg.Equals(TEXT("-forcerescan"), ESearchCase::IgnoreCase);
242 bIgnoreDenyList = bIgnoreDenyList || Arg.Equals(TEXT("-ignoreDenyLists"), ESearchCase::IgnoreCase);
243 bAsDir = bAsDir || Arg.Equals(TEXT("-asdir"), ESearchCase::IgnoreCase);
244 bAsFile = bAsFile || Arg.Equals(TEXT("-asfile"), ESearchCase::IgnoreCase);
245 }
246 else
247 {
248 InPath = Arg;
249 }
250 }
251 if (InPath.IsEmpty())
252 {
253 UE_LOG(LogAssetRegistry, Log, TEXT("Usage: AssetRegistry.ScanPath [-forcerescan] [-ignoreDenyLists] [-asfile] [-asdir] FileOrDirectoryPath"));
254 return;
255 }
256
257 if (!bAsDir && !bAsFile)
258 {
259 bAsDir = true;
261 {
262 FString LocalPath;
264 {
265 // Note, the 'internal' version of DoesPackageExist must be used to avoid re-entering the AssetRegistry's lock resulting in deadlock
266 FPackagePath PackagePath = FPackagePath::FromLocalPath(LocalPath);
267 if (FPackageName::InternalDoesPackageExistEx(PackagePath, FPackageName::EPackageLocationFilter::Any,
268 false /* bMatchCaseOnDisk */, &PackagePath) != FPackageName::EPackageLocationFilter::None)
269 {
270 bAsFile = true;
271 bAsDir = false;
272 }
273 }
274 }
275 else if (IFileManager::Get().FileExists(*InPath))
276 {
277 bAsFile = true;
278 bAsDir = false;
279 }
280 }
281 if (bAsDir)
282 {
283 IAssetRegistry::GetChecked().ScanPathsSynchronous({ InPath }, bForceRescan, bIgnoreDenyList);
284 }
285 else
286 {
288 }
289 }
290
292 {
294
295 UE_LOG(LogAssetRegistry, Log, TEXT("Total %2.f mb"), double(Size) / 1024.0 / 1024.0);
296 }
297
298 void DumpState(const TArray<FString>& Args)
299 {
300 const bool bLog = Args.Contains(TEXT("log"));
301 const bool bDashLog = Args.Contains(TEXT("-log"));
302 if (Args.Num() == 0 + int32(bLog) + int32(bDashLog))
303 {
304 UE_LOG(LogAssetRegistry, Error, TEXT("No arguments for asset registry dump."));
305 return;
306 }
307
308 const bool bDoLog = bLog || bDashLog || (!ALLOW_DEBUG_FILES);
309
310#if ASSET_REGISTRY_STATE_DUMPING_ENABLED
311 FString Path = FPaths::ProfilingDir() / FString::Printf(TEXT("AssetRegistryState_%s.txt"), *FDateTime::Now().ToString());
312 TUniquePtr<FArchive> Ar{ IFileManager::Get().CreateDebugFileWriter(*Path) };
313
314 TArray<FString> Pages;
315 IAssetRegistry::GetChecked().DumpState(Args, Pages, 1000);
316 for (const FString& Page : Pages)
317 {
318 if( bDoLog )
319 {
321 }
322#if ALLOW_DEBUG_FILES
323 Ar->Logf(TEXT("%s"), *Page);
324#endif
325 }
326
327 UE_LOG(LogAssetRegistry, Display, TEXT("Dumped asset registry state to %s."), *Path);
328#else
329 UE_LOG(LogAssetRegistry, Error, TEXT("Asset registry dumping is disabled by compilation flags."));
330#endif
331 }
332
333};
334
335#undef LOCTEXT_NAMESPACE
#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
DIRECTLINK_API Display
Definition DirectLinkLog.h:8
#define LOCTEXT(InKey, InTextLiteral)
Definition Internationalization.h:295
#define UE_LOG(CategoryName, Verbosity, Format,...)
Definition LogMacros.h:270
uint32 Size
Definition VulkanMemory.cpp:4034
Definition AssetRegistryConsoleCommands.h:16
void DumpState(const TArray< FString > &Args)
Definition AssetRegistryConsoleCommands.h:298
void GetDependencies(const TArray< FString > &Args)
Definition AssetRegistryConsoleCommands.h:154
void ScanPath(const TArray< FString > &Args)
Definition AssetRegistryConsoleCommands.h:229
FAutoConsoleCommand GetByClassCommand
Definition AssetRegistryConsoleCommands.h:21
FAutoConsoleCommand GetReferencersCommand
Definition AssetRegistryConsoleCommands.h:24
void FindInvalidUAssets(const TArray< FString > &Args)
Definition AssetRegistryConsoleCommands.h:204
FAutoConsoleCommand DumpAllocatedSizeCommand
Definition AssetRegistryConsoleCommands.h:27
FAutoConsoleCommand GetDependenciesCommand
Definition AssetRegistryConsoleCommands.h:23
void GetByName(const TArray< FString > &Args)
Definition AssetRegistryConsoleCommands.h:73
FAutoConsoleCommand ScanPathCommand
Definition AssetRegistryConsoleCommands.h:26
FAutoConsoleCommand GetByTagCommand
Definition AssetRegistryConsoleCommands.h:22
FAutoConsoleCommand DumpStateCommand
Definition AssetRegistryConsoleCommands.h:28
void DumpAllocatedSize(const TArray< FString > &Args)
Definition AssetRegistryConsoleCommands.h:291
FAssetRegistryConsoleCommands()
Definition AssetRegistryConsoleCommands.h:30
void GetByPath(const TArray< FString > &Args)
Definition AssetRegistryConsoleCommands.h:91
void GetByTag(const TArray< FString > &Args)
Definition AssetRegistryConsoleCommands.h:134
FAutoConsoleCommand GetByNameCommand
Definition AssetRegistryConsoleCommands.h:19
FAutoConsoleCommand FindInvalidUAssetsCommand
Definition AssetRegistryConsoleCommands.h:25
FAutoConsoleCommand GetByPathCommand
Definition AssetRegistryConsoleCommands.h:20
void GetByClass(const TArray< FString > &Args)
Definition AssetRegistryConsoleCommands.h:109
void GetReferencers(const TArray< FString > &Args)
Definition AssetRegistryConsoleCommands.h:179
Definition IConsoleManager.h:2026
Definition NameTypes.h:617
CORE_API FString ToString() const
Definition UnrealNames.cpp:3537
static COREUOBJECT_API bool TryConvertLongPackageNameToFilename(const FString &InLongPackageName, FString &OutFilename, const FString &InExtension=TEXT(""))
Definition PackageName.cpp:933
static COREUOBJECT_API bool IsValidLongPackageName(FStringView InLongPackageName, bool bIncludeReadOnlyRoots=false, EErrorCode *OutReason=nullptr)
Definition PackageName.cpp:1284
Definition PackagePath.h:89
static COREUOBJECT_API FPackagePath FromLocalPath(FStringView InFilename)
Definition PackagePath.cpp:243
COREUOBJECT_API EPackageExtension GetHeaderExtension() const
Definition PackagePath.cpp:266
static CORE_API FString ProfilingDir()
Definition Paths.cpp:559
virtual SIZE_T GetAllocatedSize(bool bLogDetailed=false) const =0
virtual bool GetAssetsByPackageName(FName PackageName, TArray< FAssetData > &OutAssetData, bool bIncludeOnlyOnDiskAssets=false, bool bSkipARFilteredAssets=true) const =0
virtual bool GetAssetsByPath(FName PackagePath, TArray< FAssetData > &OutAssetData, bool bRecursive=false, bool bIncludeOnlyOnDiskAssets=false) const =0
virtual void ScanPathsSynchronous(const TArray< FString > &InPaths, bool bForceRescan=false, bool bIgnoreDenyListScanFilters=false)=0
virtual bool GetAssetsByTagValues(const TMultiMap< FName, FString > &AssetTagsAndValues, TArray< FAssetData > &OutAssetData) const =0
virtual bool GetAllAssets(TArray< FAssetData > &OutAssetData, bool bIncludeOnlyOnDiskAssets=false) const =0
virtual bool GetAssetsByClass(FTopLevelAssetPath ClassPathName, TArray< FAssetData > &OutAssetData, bool bSearchSubClasses=false) const =0
virtual void DumpState(const TArray< FString > &Arguments, TArray< FString > &OutPages, int32 LinesPerPage=1) const =0
virtual void ScanFilesSynchronous(const TArray< FString > &InFilePaths, bool bForceRescan=false)=0
static IAssetRegistry & GetChecked()
Definition IAssetRegistry.h:270
static CORE_API IFileManager & Get()
Definition FileManagerGeneric.cpp:1072
Definition Array.h:670
UE_REWRITE SizeType Num() const
Definition Array.h:1144
bool Contains(const ComparisonType &Item) const
Definition Array.h:1518
UE_NODEBUG TConstIterator CreateConstIterator() const
Definition Array.h:3365
Definition UniquePtr.h:107
@ IgnoreCase
Definition CString.h:26
Definition AssetData.h:162
static CORE_API FDateTime Now()
Definition DateTime.cpp:377
Definition TopLevelAssetPath.h:38