Skip to content

Commit 3615612

Browse files
committed
fix(#41): unused assets detection with OFPA
- unused assets detected correctly now , even with level with World Partition system enabled - all external assets of that systems, are not displayed as corrupted now
1 parent 7043b02 commit 3615612

File tree

4 files changed

+35
-3
lines changed

4 files changed

+35
-3
lines changed

ProjectCleaner.uplugin

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"FileVersion": 3,
33
"Version": 1,
4-
"VersionName": "1.8.0",
4+
"VersionName": "1.8.1",
55
"FriendlyName": "ProjectCleaner",
66
"Description": "Unreal engine plugin for managing all unused assets and empty folders in project",
77
"Category": "ProjectManagementTools",

Source/ProjectCleaner/Private/Core/ProjectCleanerDataManager.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,13 @@ void FProjectCleanerDataManager::FindAllAssets()
445445
AllAssets.Empty();
446446
AllAssets.Reserve(AssetRegistry->Get().GetAllocatedSize());
447447
AssetRegistry->Get().GetAssetsByPath(RelativeRoot, AllAssets, true);
448+
449+
// filtering assets that are in '/Game/__ExternalActors__' and '/Game/__ExternalObjects__' folders
450+
FARFilter Filter;
451+
Filter.bRecursivePaths = true;
452+
Filter.PackagePaths.Add(FName{*ProjectCleanerUtility::GetExternalActorsFolderPath()});
453+
Filter.PackagePaths.Add(FName{*ProjectCleanerUtility::GetExternalObjectsFolderPath()});
454+
AssetRegistry->Get().UseFilterToExcludeAssets(AllAssets, Filter);
448455
}
449456

450457
void FProjectCleanerDataManager::FindInvalidFilesAndAssets()
@@ -479,6 +486,11 @@ void FProjectCleanerDataManager::FindInvalidFilesAndAssets()
479486
ObjectPath.RemoveFromEnd(FPaths::GetExtension(InternalFilePath, true));
480487
ObjectPath.Append(TEXT(".") + FPaths::GetBaseFilename(InternalFilePath));
481488

489+
if (ProjectCleanerUtility::IsUnderExternalGameFolder(ObjectPath))
490+
{
491+
return false;
492+
}
493+
482494
const FName ObjectPathName = FName{*ObjectPath};
483495
const bool IsInAssetRegistry = AllAssets.ContainsByPredicate([&] (const FAssetData& Elem)
484496
{
@@ -680,9 +692,9 @@ void FProjectCleanerDataManager::FindAssetsWithExternalReferencers()
680692
{
681693
AssetRegistry->Get().GetReferencers(Asset.PackageName, Refs);
682694

683-
const bool HasExternalRefs = Refs.ContainsByPredicate([](const FName& Ref)
695+
const bool HasExternalRefs = Refs.ContainsByPredicate([&](const FName& Ref)
684696
{
685-
return !Ref.ToString().StartsWith(TEXT("/Game"));
697+
return !Ref.ToString().StartsWith(TEXT("/Game")) || ProjectCleanerUtility::IsUnderExternalGameFolder(Ref.ToString());
686698
});
687699

688700
if (HasExternalRefs)

Source/ProjectCleaner/Private/Core/ProjectCleanerUtility.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,23 @@ bool ProjectCleanerUtility::IsUnderMegascansFolder(const FAssetData& AssetData)
131131
return AssetData.PackagePath.ToString().StartsWith(TEXT("/Game/MSPresets"));
132132
}
133133

134+
FString ProjectCleanerUtility::GetExternalActorsFolderPath()
135+
{
136+
return FString::Printf(TEXT("/Game/%s"), FPackagePath::GetExternalActorsFolderName());
137+
}
138+
139+
FString ProjectCleanerUtility::GetExternalObjectsFolderPath()
140+
{
141+
return FString::Printf(TEXT("/Game/%s"), FPackagePath::GetExternalObjectsFolderName());
142+
}
143+
144+
bool ProjectCleanerUtility::IsUnderExternalGameFolder(const FString& Path)
145+
{
146+
if (Path.IsEmpty()) return false;
147+
148+
return Path.StartsWith(GetExternalActorsFolderPath()) || Path.StartsWith(GetExternalObjectsFolderPath());
149+
}
150+
134151
bool ProjectCleanerUtility::HasIndirectlyUsedAssets(const FString& FileContent)
135152
{
136153
if (FileContent.IsEmpty()) return false;

Source/ProjectCleaner/Public/Core/ProjectCleanerUtility.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class PROJECTCLEANER_API ProjectCleanerUtility
1919
static int64 GetTotalSize(const TArray<FAssetData>& Assets);
2020
static FName GetClassName(const FAssetData& AssetData);
2121
static FText GetDeletionProgressText(const int32 DeletedAssetNum, const int32 Total, const bool bShowPercent);
22+
static FString GetExternalActorsFolderPath();
23+
static FString GetExternalObjectsFolderPath();
2224
static FString ConvertAbsolutePathToInternal(const FString& InPath);
2325
static FString ConvertInternalToAbsolutePath(const FString& InPath);
2426
static void SaveAllAssets(const bool PromptUser);
@@ -28,6 +30,7 @@ class PROJECTCLEANER_API ProjectCleanerUtility
2830
static int32 DeleteAssets(TArray<FAssetData>& Assets, const bool ForceDelete);
2931
static bool IsEngineExtension(const FString& Extension);
3032
static bool IsUnderMegascansFolder(const FAssetData& AssetData);
33+
static bool IsUnderExternalGameFolder(const FString& Path);
3134
static bool HasIndirectlyUsedAssets(const FString& FileContent);
3235
private:
3336
static FString ConvertPathInternal(const FString& From, const FString To, const FString& Path);

0 commit comments

Comments
 (0)