72bf94d142
Editor tool for the LA and 3D departments: which assets each level uses, which are used nowhere, and export of a chosen set. Three modules. AssetUsageAuditCore holds the whole analysis and links no UI and no editor-only asset pipeline, so it stays runnable from a commandlet; AssetUsageAuditEditor holds the Slate panel and everything that needs UnrealEd or AssetTools; AssetUsageAuditTests holds 152 specs. Load-bearing decisions, each of which produces a wrong answer if undone: - Dependency queries are always Package + NoRequirements, never Hard. The map-to-external-actor edges the OFPA gatherer emits carry Game|Build without Hard, so a Hard query drops all 16117 external actor packages in this project. There is deliberately no Hard constant in the code. - Crossing into another map is allowed only from a level or its external actor package. Without that rule WP_Main reported 18136 assets, of which 9994 belonged to L_MainLevel, reached through the GameMode. - The verdict has five states, never a bool. The registry cannot see FMOD events, DataTable rows or string-built paths; those are Unknown, and the tool never proposes a deletion. - Copying .uasset files does not preserve references - they are stored as full package paths. Only the Migrate layout produces something Unreal can open; the others write a manifest so the graph can be rebuilt. Co-Authored-By: Claude Code <noreply@anthropic.com>
132 lines
5.0 KiB
C++
132 lines
5.0 KiB
C++
// NextGenium 2026. Asset Usage Audit.
|
|
|
|
#include "IndirectReferenceScanner.h"
|
|
#include "Misc/AutomationTest.h"
|
|
|
|
#if WITH_DEV_AUTOMATION_TESTS
|
|
|
|
BEGIN_DEFINE_SPEC(IndirectReferenceScannerSpec,
|
|
"AssetUsageAudit.IndirectReferences",
|
|
EAutomationTestFlags::EditorContext | EAutomationTestFlags::EngineFilter)
|
|
|
|
TArray<FString> Extract(const TCHAR* Line)
|
|
{
|
|
TArray<FString> Result;
|
|
FIndirectReferenceScanner::ExtractGamePathsFromLine(Line, Result);
|
|
return Result;
|
|
}
|
|
|
|
END_DEFINE_SPEC(IndirectReferenceScannerSpec)
|
|
|
|
void IndirectReferenceScannerSpec::Define()
|
|
{
|
|
Describe("ExtractGamePathsFromLine", [this]()
|
|
{
|
|
// These four lines are copied from this project's Config/DefaultEngine.ini. They are the
|
|
// whole reason this scanner exists: nothing in Content references them, so without this
|
|
// pass the project's GameMode and GameInstance are reported as unused assets.
|
|
It("finds the GameMode from DefaultEngine.ini and strips the _C class suffix", [this]()
|
|
{
|
|
const TArray<FString> Found = Extract(
|
|
TEXT("GlobalDefaultGameMode=/Game/Space/Core/GameModes/BP_FirstPersonGameMode.BP_FirstPersonGameMode_C"));
|
|
|
|
TestEqual(TEXT("one hit"), Found.Num(), 1);
|
|
if (Found.Num() == 1)
|
|
{
|
|
TestEqual(TEXT("package"), Found[0], FString(TEXT("/Game/Space/Core/GameModes/BP_FirstPersonGameMode")));
|
|
}
|
|
});
|
|
|
|
It("finds the GameInstance from MenuSystemPro", [this]()
|
|
{
|
|
const TArray<FString> Found = Extract(
|
|
TEXT("GameInstanceClass=/Game/MenuSystemPro/Blueprints/GameFramework/BP_MenuSystemGameInstance.BP_MenuSystemGameInstance_C"));
|
|
|
|
TestEqual(TEXT("one hit"), Found.Num(), 1);
|
|
if (Found.Num() == 1)
|
|
{
|
|
TestEqual(TEXT("package"), Found[0],
|
|
FString(TEXT("/Game/MenuSystemPro/Blueprints/GameFramework/BP_MenuSystemGameInstance")));
|
|
}
|
|
});
|
|
|
|
It("finds a map reference with an object suffix", [this]()
|
|
{
|
|
const TArray<FString> Found = Extract(TEXT("EditorStartupMap=/Game/Space/Maps/Gyms/Gyms_Geoda.Gyms_Geoda"));
|
|
|
|
TestEqual(TEXT("one hit"), Found.Num(), 1);
|
|
if (Found.Num() == 1)
|
|
{
|
|
TestEqual(TEXT("package"), Found[0], FString(TEXT("/Game/Space/Maps/Gyms/Gyms_Geoda")));
|
|
}
|
|
});
|
|
|
|
It("finds a bare package path with no object suffix", [this]()
|
|
{
|
|
const TArray<FString> Found = Extract(TEXT("GameDefaultMap=/Game/Space/Maps/RefinedMenuMap"));
|
|
|
|
TestEqual(TEXT("one hit"), Found.Num(), 1);
|
|
if (Found.Num() == 1)
|
|
{
|
|
TestEqual(TEXT("package"), Found[0], FString(TEXT("/Game/Space/Maps/RefinedMenuMap")));
|
|
}
|
|
});
|
|
|
|
It("strips surrounding quotes and parentheses from an ini struct value", [this]()
|
|
{
|
|
const TArray<FString> Found = Extract(TEXT("+DirectoriesToAlwaysCook=(Path=\"/Game/Space/Art\")"));
|
|
|
|
TestEqual(TEXT("one hit"), Found.Num(), 1);
|
|
if (Found.Num() == 1)
|
|
{
|
|
TestEqual(TEXT("package"), Found[0], FString(TEXT("/Game/Space/Art")));
|
|
}
|
|
});
|
|
|
|
It("handles a C++ literal wrapped in TEXT()", [this]()
|
|
{
|
|
const TArray<FString> Found = Extract(
|
|
TEXT("static const FSoftObjectPath Path(TEXT(\"/Game/Space/Art/SM_Rock\"));"));
|
|
|
|
TestEqual(TEXT("one hit"), Found.Num(), 1);
|
|
if (Found.Num() == 1)
|
|
{
|
|
TestEqual(TEXT("package"), Found[0], FString(TEXT("/Game/Space/Art/SM_Rock")));
|
|
}
|
|
});
|
|
|
|
It("finds several distinct paths on one line", [this]()
|
|
{
|
|
const TArray<FString> Found = Extract(
|
|
TEXT("Redirect=(From=\"/Game/Old/SM_A\", To=\"/Game/New/SM_B\")"));
|
|
|
|
TestEqual(TEXT("two hits"), Found.Num(), 2);
|
|
if (Found.Num() == 2)
|
|
{
|
|
TestEqual(TEXT("first"), Found[0], FString(TEXT("/Game/Old/SM_A")));
|
|
TestEqual(TEXT("second"), Found[1], FString(TEXT("/Game/New/SM_B")));
|
|
}
|
|
});
|
|
|
|
It("returns nothing for a line with no /Game path", [this]()
|
|
{
|
|
TestEqual(TEXT("no hits"), Extract(TEXT("bDynamicLevelStreaming=False")).Num(), 0);
|
|
TestEqual(TEXT("no hits"), Extract(TEXT("")).Num(), 0);
|
|
});
|
|
|
|
It("ignores a bare /Game root with no asset under it", [this]()
|
|
{
|
|
// "/Game" alone is a mount point, not a reference. Recording it would mark the entire
|
|
// project as referenced-from-config and make the verdict column meaningless.
|
|
TestEqual(TEXT("no hits"), Extract(TEXT("PackagePath=/Game")).Num(), 0);
|
|
});
|
|
|
|
It("does not match a path that merely contains the word Game", [this]()
|
|
{
|
|
TestEqual(TEXT("no hits"), Extract(TEXT("Path=/MiniGames2/Foo/SM_Bar")).Num(), 0);
|
|
});
|
|
});
|
|
}
|
|
|
|
#endif // WITH_DEV_AUTOMATION_TESTS
|