Move Asset_Search to use IAssetRegistry

This commit is contained in:
2026-03-17 23:02:07 -04:00
parent cad9947670
commit 26de2351db

View File

@@ -3,8 +3,9 @@
#include "CoreMinimal.h"
#include "MCPServer.h"
#include "MCPHandler.h"
#include "MCPAssets.h"
#include "MCPUtils.h"
#include "AssetRegistry/AssetRegistryModule.h"
#include "AssetRegistry/IAssetRegistry.h"
#include "Asset_Search.generated.h"
@@ -40,9 +41,12 @@ public:
return;
}
MCPAssets<UObject> Assets;
// Build the asset registry filter
FARFilter Filter;
Filter.bRecursiveClasses = true;
Filter.bRecursivePaths = true;
Filter.PackagePaths.Add(FName(TEXT("/Game")));
// If a type is specified, find the UClass and filter by it
if (!Type.IsEmpty())
{
UClass* TypeClass = MCPUtils::FindClassByName(Type);
@@ -51,29 +55,40 @@ public:
UMCPServer::Printf(TEXT("ERROR: Unknown asset type '%s'\n"), *Type);
return;
}
Assets.NoScans().Scan(TypeClass);
Filter.ClassPaths.Add(TypeClass->GetClassPathName());
}
if (!Query.IsEmpty())
// Query the asset registry
IAssetRegistry& AR = FModuleManager::LoadModuleChecked<FAssetRegistryModule>("AssetRegistry").Get();
TArray<FAssetData> Candidates;
AR.GetAssets(Filter, Candidates);
// Filter by query substring and collect results
TArray<FAssetData> Results;
for (const FAssetData& Data : Candidates)
{
Assets.Substring(Query);
if (Results.Num() >= Limit) break;
if (!Query.IsEmpty())
{
if (!Data.AssetName.ToString().Contains(Query, ESearchCase::IgnoreCase) &&
!Data.PackageName.ToString().Contains(Query, ESearchCase::IgnoreCase))
continue;
}
Results.Add(Data);
}
Assets.AllContent().Limit(Limit).Info();
const TArray<FAssetData>& AllData = Assets.AllData();
for (const FAssetData& Data : AllData)
for (const FAssetData& Data : Results)
{
UMCPServer::Printf(TEXT("%s %s\n"),
*MCPUtils::FormatName(Data.GetClass()),
*Data.PackageName.ToString());
}
if (AllData.Num() == 0)
if (Results.Num() == 0)
{
UMCPServer::Print(TEXT("No assets found.\n"));
}
else if (AllData.Num() >= Limit)
else if (Results.Num() >= Limit)
{
UMCPServer::Printf(TEXT("WARNING: You reached the limit of %d, to raise it, specify the Limit parameter.\n"), Limit);
}