Big refactor in MCPAssetFinder

This commit is contained in:
2026-03-06 23:51:16 -05:00
parent 7f6438e423
commit 3a2cb775e0
21 changed files with 289 additions and 381 deletions

View File

@@ -41,304 +41,193 @@ void UMCPAssetFinder::Deinitialize()
} }
// ============================================================ // ============================================================
// GetUpdatedAssets — the gateway for all static API // Get / Refresh
// ============================================================ // ============================================================
UMCPAssetFinder* UMCPAssetFinder::GetUpdatedAssets() UMCPAssetFinder* UMCPAssetFinder::Get()
{
UMCPAssetFinder* Self = GEngine ? GEngine->GetEngineSubsystem<UMCPAssetFinder>() : nullptr;
checkf(Self, TEXT("MCPAssetFinder::Get() called before engine initialization"));
return Self;
}
void UMCPAssetFinder::CacheAssets(IAssetRegistry &Registry, UClass *Class, bool IncludeSubclasses)
{
FName Key = Class->GetFName();
TArray<FAssetData>& List = AssetCache.Add(Key);
Registry.GetAssetsByClass(Class->GetClassPathName(), List, IncludeSubclasses);
}
void UMCPAssetFinder::Refresh()
{ {
checkf(IsInGameThread(), TEXT("MCPAssetFinder must only be accessed from the game thread")); checkf(IsInGameThread(), TEXT("MCPAssetFinder must only be accessed from the game thread"));
if (!GEngine) return nullptr; UMCPAssetFinder* Self = Get();
UMCPAssetFinder* Self = GEngine->GetEngineSubsystem<UMCPAssetFinder>();
if (!Self) return nullptr;
IAssetRegistry& AR = FModuleManager::LoadModuleChecked<FAssetRegistryModule>("AssetRegistry").Get(); IAssetRegistry& AR = FModuleManager::LoadModuleChecked<FAssetRegistryModule>("AssetRegistry").Get();
while (AR.IsLoadingAssets()) FPlatformProcess::Sleep(0.1f); while (AR.IsLoadingAssets()) FPlatformProcess::Sleep(0.1f);
if (!Self->bDirty) return Self; if (!Self->bDirty) return;
Self->AllBlueprintAssets.Empty(); Self->AssetCache.Empty();
Self->AllMapAssets.Empty();
Self->AllBlueprintAndMapAssets.Empty();
Self->AllMaterialAssets.Empty();
Self->AllMaterialInstanceAssets.Empty();
Self->AllMaterialFunctionAssets.Empty();
Self->AllStructAssets.Empty();
Self->AllEnumAssets.Empty();
AR.GetAssetsByClass(UBlueprint::StaticClass()->GetClassPathName(), Self->AllBlueprintAssets, true); // Cache all asset classes.
AR.GetAssetsByClass(UWorld::StaticClass()->GetClassPathName(), Self->AllMapAssets, false); Self->CacheAssets(AR, UBlueprint::StaticClass(), true);
AR.GetAssetsByClass(UMaterial::StaticClass()->GetClassPathName(), Self->AllMaterialAssets, false); Self->CacheAssets(AR, UWorld::StaticClass(), false);
AR.GetAssetsByClass(UMaterialInstanceConstant::StaticClass()->GetClassPathName(), Self->AllMaterialInstanceAssets, false); Self->CacheAssets(AR, UMaterial::StaticClass(), false);
AR.GetAssetsByClass(UMaterialFunction::StaticClass()->GetClassPathName(), Self->AllMaterialFunctionAssets, false); Self->CacheAssets(AR, UMaterialInstanceConstant::StaticClass(), false);
AR.GetAssetsByClass(UUserDefinedStruct::StaticClass()->GetClassPathName(), Self->AllStructAssets, false); Self->CacheAssets(AR, UMaterialFunction::StaticClass(), false);
AR.GetAssetsByClass(UUserDefinedEnum::StaticClass()->GetClassPathName(), Self->AllEnumAssets, false); Self->CacheAssets(AR, UUserDefinedStruct::StaticClass(), false);
Self->CacheAssets(AR, UUserDefinedEnum::StaticClass(), false);
Self->AllBlueprintAndMapAssets = Self->AllBlueprintAssets; // Combined list: blueprints + maps
Self->AllBlueprintAndMapAssets.Append(Self->AllMapAssets); TArray<FAssetData>& Combined = Self->AssetCache.Add(BlueprintsAndMaps);
Combined = Self->AssetCache[UBlueprint::StaticClass()->GetFName()];
Combined.Append(Self->AssetCache[UWorld::StaticClass()->GetFName()]);
Self->bDirty = false; Self->bDirty = false;
UE_LOG(LogTemp, Display, TEXT("MCPAssetFinder: Refreshed — BP %d, Map %d, Mat %d, MI %d, MF %d, Struct %d, Enum %d"), UE_LOG(LogTemp, Display, TEXT("MCPAssetFinder: Refreshed — %d asset types cached"),
Self->AllBlueprintAssets.Num(), Self->AllMapAssets.Num(), Self->AllMaterialAssets.Num(), Self->AssetCache.Num());
Self->AllMaterialInstanceAssets.Num(), Self->AllMaterialFunctionAssets.Num(),
Self->AllStructAssets.Num(), Self->AllEnumAssets.Num());
return Self;
} }
// ============================================================ // ============================================================
// Static asset list accessors // Static asset list accessors
// ============================================================ // ============================================================
const TArray<FAssetData>& UMCPAssetFinder::GetBlueprintAssets() const TArray<FAssetData>& UMCPAssetFinder::GetAssets(FName Key)
{ {
UMCPAssetFinder* Self = GetUpdatedAssets(); TArray<FAssetData>* Found = Get()->AssetCache.Find(Key);
return Self ? Self->AllBlueprintAssets : EmptyAssetArray; return Found ? *Found : EmptyAssetArray;
} }
const TArray<FAssetData>& UMCPAssetFinder::GetBlueprintAndMapAssets() const TArray<FAssetData>& UMCPAssetFinder::GetAssets(UClass* Class)
{ {
UMCPAssetFinder* Self = GetUpdatedAssets(); return GetAssets(Class->GetFName());
return Self ? Self->AllBlueprintAndMapAssets : EmptyAssetArray;
} }
const TArray<FAssetData>& UMCPAssetFinder::GetMapAssets() FName UMCPAssetFinder::BlueprintsAndMaps = FName(TEXT("BlueprintsAndMaps"));
{
UMCPAssetFinder* Self = GetUpdatedAssets();
return Self ? Self->AllMapAssets : EmptyAssetArray;
}
const TArray<FAssetData>& UMCPAssetFinder::GetMaterialAssets()
{
UMCPAssetFinder* Self = GetUpdatedAssets();
return Self ? Self->AllMaterialAssets : EmptyAssetArray;
}
const TArray<FAssetData>& UMCPAssetFinder::GetMaterialInstanceAssets()
{
UMCPAssetFinder* Self = GetUpdatedAssets();
return Self ? Self->AllMaterialInstanceAssets : EmptyAssetArray;
}
const TArray<FAssetData>& UMCPAssetFinder::GetMaterialFunctionAssets()
{
UMCPAssetFinder* Self = GetUpdatedAssets();
return Self ? Self->AllMaterialFunctionAssets : EmptyAssetArray;
}
const TArray<FAssetData>& UMCPAssetFinder::GetStructAssets()
{
UMCPAssetFinder* Self = GetUpdatedAssets();
return Self ? Self->AllStructAssets : EmptyAssetArray;
}
const TArray<FAssetData>& UMCPAssetFinder::GetEnumAssets()
{
UMCPAssetFinder* Self = GetUpdatedAssets();
return Self ? Self->AllEnumAssets : EmptyAssetArray;
}
// ============================================================ // ============================================================
// Find helpers (search cached lists by name or path) // Find / Search helpers
// ============================================================ // ============================================================
namespace FAssetData* UMCPAssetFinder::FindAsset(FName Class, const FString& NameOrPath, FString* OutError)
{ {
FAssetData* FindInList(const TArray<FAssetData>& List, const FString& NameOrPath, FString* OutError) const TArray<FAssetData>& List = GetAssets(Class);
bool IsPath = NameOrPath.Contains(TEXT("/"));
FAssetData* Found = nullptr;
for (const FAssetData& Asset : List)
{ {
bool IsPath = NameOrPath.Contains(TEXT("/")); FName Name = IsPath ? Asset.PackageName : Asset.AssetName;
if (!Name.ToString().Equals(NameOrPath, ESearchCase::IgnoreCase)) continue;
// Short name match — check for duplicates if (!Found)
FAssetData* Found = nullptr;
for (const FAssetData& Asset : List)
{ {
FName Name = IsPath ? Asset.PackageName : Asset.AssetName; Found = const_cast<FAssetData*>(&Asset);
if (!Name.ToString().Equals(NameOrPath, ESearchCase::IgnoreCase)) continue; continue;
if (!Found)
{
Found = const_cast<FAssetData*>(&Asset);
continue;
}
if (OutError)
{
*OutError = FString::Printf(
TEXT("Ambiguous asset name '%s' — matches both '%s' and '%s'. Use the full package path to disambiguate."),
*NameOrPath, *Found->PackageName.ToString(), *Asset.PackageName.ToString());
}
return nullptr;
} }
return Found; if (OutError)
{
*OutError = FString::Printf(
TEXT("Ambiguous asset name '%s' — matches both '%s' and '%s'. Use the full package path to disambiguate."),
*NameOrPath, *Found->PackageName.ToString(), *Asset.PackageName.ToString());
}
return nullptr;
} }
return Found;
}
TArray<FAssetData*> SearchInList(const TArray<FAssetData>& List, const FString& Filter) FAssetData* UMCPAssetFinder::FindAsset(UClass* Class, const FString& NameOrPath, FString* OutError)
{
return FindAsset(Class->GetFName(), NameOrPath, OutError);
}
TArray<FAssetData*> UMCPAssetFinder::SearchAssets(FName Class, const FString& Filter, FString* OutError)
{
const TArray<FAssetData>& List = GetAssets(Class);
TArray<FAssetData*> Results;
for (const FAssetData& Asset : List)
{ {
TArray<FAssetData*> Results; FString AssetName = Asset.AssetName.ToString();
for (const FAssetData& Asset : List) FString PackagePath = Asset.PackageName.ToString();
if (AssetName.Contains(Filter, ESearchCase::IgnoreCase) ||
PackagePath.Contains(Filter, ESearchCase::IgnoreCase))
{ {
FString AssetName = Asset.AssetName.ToString(); Results.Add(const_cast<FAssetData*>(&Asset));
FString PackagePath = Asset.PackageName.ToString();
if (AssetName.Contains(Filter, ESearchCase::IgnoreCase) ||
PackagePath.Contains(Filter, ESearchCase::IgnoreCase))
{
Results.Add(const_cast<FAssetData*>(&Asset));
}
} }
return Results;
} }
return Results;
} }
FAssetData* UMCPAssetFinder::FindBlueprintAsset(const FString& NameOrPath, FString* OutError, bool bIncludeLevelBlueprints) TArray<FAssetData*> UMCPAssetFinder::SearchAssets(UClass* Class, const FString& Filter, FString* OutError)
{ {
const TArray<FAssetData>& List = bIncludeLevelBlueprints ? GetBlueprintAndMapAssets() : GetBlueprintAssets(); return SearchAssets(Class->GetFName(), Filter, OutError);
return FindInList(List, NameOrPath, OutError);
}
TArray<FAssetData*> UMCPAssetFinder::SearchBlueprintAssets(const FString& Filter, bool bIncludeLevelBlueprints)
{
const TArray<FAssetData>& List = bIncludeLevelBlueprints ? GetBlueprintAndMapAssets() : GetBlueprintAssets();
return SearchInList(List, Filter);
}
FAssetData* UMCPAssetFinder::FindMapAsset(const FString& NameOrPath, FString* OutError)
{
return FindInList(GetMapAssets(), NameOrPath, OutError);
}
FAssetData* UMCPAssetFinder::FindMaterialAsset(const FString& NameOrPath, FString* OutError)
{
return FindInList(GetMaterialAssets(), NameOrPath, OutError);
}
FAssetData* UMCPAssetFinder::FindMaterialInstanceAsset(const FString& NameOrPath, FString* OutError)
{
return FindInList(GetMaterialInstanceAssets(), NameOrPath, OutError);
}
FAssetData* UMCPAssetFinder::FindMaterialFunctionAsset(const FString& NameOrPath, FString* OutError)
{
return FindInList(GetMaterialFunctionAssets(), NameOrPath, OutError);
}
FAssetData* UMCPAssetFinder::FindStructAsset(const FString& NameOrPath, FString* OutError)
{
return FindInList(GetStructAssets(), NameOrPath, OutError);
}
FAssetData* UMCPAssetFinder::FindEnumAsset(const FString& NameOrPath, FString* OutError)
{
return FindInList(GetEnumAssets(), NameOrPath, OutError);
} }
FAssetData* UMCPAssetFinder::FindAnyAsset(const FString& NameOrPath, FString* OutError) FAssetData* UMCPAssetFinder::FindAnyAsset(const FString& NameOrPath, FString* OutError)
{ {
FAssetData* Asset = FindBlueprintAsset(NameOrPath, OutError); FAssetData* Found = nullptr;
if (!Asset && (!OutError || OutError->IsEmpty())) Asset = FindMaterialAsset(NameOrPath, OutError);
if (!Asset && (!OutError || OutError->IsEmpty())) Asset = FindMaterialInstanceAsset(NameOrPath, OutError); for (auto& Pair : Get()->AssetCache)
if (!Asset && (!OutError || OutError->IsEmpty())) Asset = FindMaterialFunctionAsset(NameOrPath, OutError); {
return Asset; if (Pair.Key == BlueprintsAndMaps) continue;
FString LocalError;
FAssetData* Asset = FindAsset(Pair.Key, NameOrPath, &LocalError);
if (!LocalError.IsEmpty())
{
if (OutError) *OutError = LocalError;
return nullptr;
}
if (!Asset) continue;
if (Found)
{
if (OutError)
{
*OutError = FString::Printf(
TEXT("Ambiguous asset name '%s' — matches '%s' and '%s'. Use the full package path to disambiguate."),
*NameOrPath, *Found->PackageName.ToString(), *Asset->PackageName.ToString());
}
return nullptr;
}
Found = Asset;
}
return Found;
} }
// ============================================================ // ============================================================
// Load helpers // Load helpers
// ============================================================ // ============================================================
UBlueprint* UMCPAssetFinder::LoadBlueprintByName(const FString& NameOrPath, FString& OutError, bool bIncludeLevelBlueprints) UBlueprint* UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(FAssetData& Asset, FString& OutError)
{ {
FAssetData* Asset = FindBlueprintAsset(NameOrPath, &OutError, bIncludeLevelBlueprints);
if (!Asset)
{
if (OutError.IsEmpty())
{
OutError = FString::Printf(TEXT("Blueprint '%s' not found. Use list_blueprints to see available assets."), *NameOrPath);
}
return nullptr;
}
// Regular blueprint asset // Regular blueprint asset
UBlueprint* BP = Cast<UBlueprint>(Asset->GetAsset()); UBlueprint* BP = Cast<UBlueprint>(Asset.GetAsset());
if (BP) if (BP) return BP;
{
return BP;
}
// Map asset — extract the level blueprint // Map asset — extract the level blueprint
UWorld* World = Cast<UWorld>(Asset->GetAsset()); UWorld* World = Cast<UWorld>(Asset.GetAsset());
if (World && World->PersistentLevel) if (World && World->PersistentLevel)
{ {
ULevelScriptBlueprint* LevelBP = World->PersistentLevel->GetLevelScriptBlueprint(true); ULevelScriptBlueprint* LevelBP = World->PersistentLevel->GetLevelScriptBlueprint(true);
if (LevelBP) if (LevelBP) return LevelBP;
{
return LevelBP;
}
} }
OutError = FString::Printf(TEXT("Asset '%s' loaded but its level blueprint could not be retrieved."), *NameOrPath); OutError = FString::Printf(TEXT("Asset '%s' loaded but its level blueprint could not be retrieved."),
*Asset.AssetName.ToString());
return nullptr; return nullptr;
} }
UMaterial* UMCPAssetFinder::LoadMaterialByName(const FString& NameOrPath, FString& OutError) UBlueprint* UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(const FString& NameOrPath, FString& OutError)
{ {
FAssetData* Asset = FindMaterialAsset(NameOrPath, &OutError); FAssetData* Asset = FindAsset(BlueprintsAndMaps, NameOrPath, &OutError);
if (Asset) if (!Asset)
{ {
UMaterial* Mat = Cast<UMaterial>(Asset->GetAsset()); if (OutError.IsEmpty())
if (Mat) return Mat; OutError = FString::Printf(TEXT("Blueprint '%s' not found."), *NameOrPath);
return nullptr;
} }
if (OutError.IsEmpty()) return LoadBlueprintOrLevelBlueprint(*Asset, OutError);
OutError = FString::Printf(TEXT("Material '%s' not found. Use list_materials to see available assets."), *NameOrPath);
return nullptr;
} }
UMaterialInstanceConstant* UMCPAssetFinder::LoadMaterialInstanceByName(const FString& NameOrPath, FString& OutError)
{
FAssetData* Asset = FindMaterialInstanceAsset(NameOrPath, &OutError);
if (Asset)
{
UMaterialInstanceConstant* MI = Cast<UMaterialInstanceConstant>(Asset->GetAsset());
if (MI) return MI;
}
if (OutError.IsEmpty())
OutError = FString::Printf(TEXT("Material Instance '%s' not found. Use list_materials to see available assets."), *NameOrPath);
return nullptr;
}
UMaterialFunction* UMCPAssetFinder::LoadMaterialFunctionByName(const FString& NameOrPath, FString& OutError)
{
FAssetData* Asset = FindMaterialFunctionAsset(NameOrPath, &OutError);
if (Asset)
{
UMaterialFunction* MF = Cast<UMaterialFunction>(Asset->GetAsset());
if (MF) return MF;
}
if (OutError.IsEmpty())
OutError = FString::Printf(TEXT("Material Function '%s' not found. Use list_material_functions to see available assets."), *NameOrPath);
return nullptr;
}
UUserDefinedStruct* UMCPAssetFinder::LoadStructByName(const FString& NameOrPath, FString& OutError)
{
FAssetData* Asset = FindStructAsset(NameOrPath, &OutError);
if (Asset)
{
UUserDefinedStruct* Struct = Cast<UUserDefinedStruct>(Asset->GetAsset());
if (Struct) return Struct;
}
if (OutError.IsEmpty())
OutError = FString::Printf(TEXT("UserDefinedStruct '%s' not found."), *NameOrPath);
return nullptr;
}
UUserDefinedEnum* UMCPAssetFinder::LoadEnumByName(const FString& NameOrPath, FString& OutError)
{
FAssetData* Asset = FindEnumAsset(NameOrPath, &OutError);
if (Asset)
{
UUserDefinedEnum* Enum = Cast<UUserDefinedEnum>(Asset->GetAsset());
if (Enum) return Enum;
}
if (OutError.IsEmpty())
OutError = FString::Printf(TEXT("UserDefinedEnum '%s' not found."), *NameOrPath);
return nullptr;
}

View File

@@ -59,7 +59,7 @@ void FBlueprintMCPServer::HandleCreateAnimBlueprint(const FJsonObject* Json, FJs
// Check if asset already exists // Check if asset already exists
FString FullAssetPath = PackagePath / Name; FString FullAssetPath = PackagePath / Name;
if (UMCPAssetFinder::FindBlueprintAsset(Name) || UMCPAssetFinder::FindBlueprintAsset(FullAssetPath)) if (UMCPAssetFinder::FindAsset(UBlueprint::StaticClass(), Name) || UMCPAssetFinder::FindAsset(UBlueprint::StaticClass(), FullAssetPath))
{ {
return MCPUtils::MakeErrorJson(Result, FString::Printf( return MCPUtils::MakeErrorJson(Result, FString::Printf(
TEXT("Blueprint '%s' already exists. Use a different name or delete the existing asset first."), TEXT("Blueprint '%s' already exists. Use a different name or delete the existing asset first."),
@@ -214,7 +214,7 @@ void FBlueprintMCPServer::HandleAddAnimState(const FJsonObject* Json, FJsonObjec
} }
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(BlueprintName, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(BlueprintName, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -316,7 +316,7 @@ void FBlueprintMCPServer::HandleRemoveAnimState(const FJsonObject* Json, FJsonOb
} }
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(BlueprintName, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(BlueprintName, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -387,7 +387,7 @@ void FBlueprintMCPServer::HandleAddAnimTransition(const FJsonObject* Json, FJson
} }
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(BlueprintName, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(BlueprintName, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -474,7 +474,7 @@ void FBlueprintMCPServer::HandleSetTransitionRule(const FJsonObject* Json, FJson
} }
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(BlueprintName, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(BlueprintName, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -566,7 +566,7 @@ void FBlueprintMCPServer::HandleAddAnimNode(const FJsonObject* Json, FJsonObject
} }
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(BlueprintName, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(BlueprintName, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -762,7 +762,7 @@ void FBlueprintMCPServer::HandleSetStateAnimation(const FJsonObject* Json, FJson
} }
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(BlueprintName, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(BlueprintName, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -855,7 +855,7 @@ void FBlueprintMCPServer::HandleListAnimSlots(const FJsonObject* Json, FJsonObje
} }
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(BlueprintName, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(BlueprintName, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -914,7 +914,7 @@ void FBlueprintMCPServer::HandleListSyncGroups(const FJsonObject* Json, FJsonObj
} }
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(BlueprintName, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(BlueprintName, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -1261,7 +1261,7 @@ void FBlueprintMCPServer::HandleSetStateBlendSpace(const FJsonObject* Json, FJso
} }
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(BlueprintName, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(BlueprintName, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);

View File

@@ -24,7 +24,7 @@ void FBlueprintMCPServer::HandleListComponents(const FJsonObject* Json, FJsonObj
} }
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(BlueprintName, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(BlueprintName, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -118,7 +118,7 @@ void FBlueprintMCPServer::HandleAddComponent(const FJsonObject* Json, FJsonObjec
} }
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(BlueprintName, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(BlueprintName, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -271,7 +271,7 @@ void FBlueprintMCPServer::HandleRemoveComponent(const FJsonObject* Json, FJsonOb
} }
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(BlueprintName, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(BlueprintName, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);

View File

@@ -42,10 +42,10 @@ public:
// Load both blueprints // Load both blueprints
FString LoadErrorA, LoadErrorB; FString LoadErrorA, LoadErrorB;
UBlueprint* BPA = UMCPAssetFinder::LoadBlueprintByName(BlueprintA, LoadErrorA); UBlueprint* BPA = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(BlueprintA, LoadErrorA);
if (!BPA) { MCPUtils::MakeErrorJson(Result, FString::Printf(TEXT("blueprintA: %s"), *LoadErrorA)); return; } if (!BPA) { MCPUtils::MakeErrorJson(Result, FString::Printf(TEXT("blueprintA: %s"), *LoadErrorA)); return; }
UBlueprint* BPB = UMCPAssetFinder::LoadBlueprintByName(BlueprintB, LoadErrorB); UBlueprint* BPB = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(BlueprintB, LoadErrorB);
if (!BPB) { MCPUtils::MakeErrorJson(Result, FString::Printf(TEXT("blueprintB: %s"), *LoadErrorB)); return; } if (!BPB) { MCPUtils::MakeErrorJson(Result, FString::Printf(TEXT("blueprintB: %s"), *LoadErrorB)); return; }
// Helper to gather graphs from a Blueprint // Helper to gather graphs from a Blueprint

View File

@@ -29,7 +29,7 @@ void FBlueprintMCPServer::HandleGetPinInfo(const FJsonObject* Json, FJsonObject*
} }
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(BlueprintName, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(BlueprintName, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -134,7 +134,7 @@ void FBlueprintMCPServer::HandleCheckPinCompatibility(const FJsonObject* Json, F
} }
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(BlueprintName, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(BlueprintName, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);

View File

@@ -28,7 +28,7 @@ void FBlueprintMCPServer::HandleAddEventDispatcher(const FJsonObject* Json, FJso
// Load Blueprint // Load Blueprint
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(BlueprintName, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(BlueprintName, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -173,7 +173,7 @@ void FBlueprintMCPServer::HandleListEventDispatchers(const FJsonObject* Json, FJ
} }
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(BlueprintName, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(BlueprintName, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);

View File

@@ -33,7 +33,7 @@ void FBlueprintMCPServer::HandleReparentBlueprint(const FJsonObject* Json, FJson
// Load Blueprint // Load Blueprint
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(BlueprintName, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(BlueprintName, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -59,7 +59,7 @@ void FBlueprintMCPServer::HandleReparentBlueprint(const FJsonObject* Json, FJson
if (!NewParentClass) if (!NewParentClass)
{ {
FString ParentLoadError; FString ParentLoadError;
UBlueprint* ParentBP = UMCPAssetFinder::LoadBlueprintByName(NewParentName, ParentLoadError); UBlueprint* ParentBP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(NewParentName, ParentLoadError);
if (ParentBP && ParentBP->GeneratedClass) if (ParentBP && ParentBP->GeneratedClass)
{ {
NewParentClass = ParentBP->GeneratedClass; NewParentClass = ParentBP->GeneratedClass;
@@ -134,7 +134,7 @@ void FBlueprintMCPServer::HandleCreateBlueprint(const FJsonObject* Json, FJsonOb
// Check if asset already exists // Check if asset already exists
FString FullAssetPath = PackagePath / BlueprintName; FString FullAssetPath = PackagePath / BlueprintName;
if (UMCPAssetFinder::FindBlueprintAsset(BlueprintName) || UMCPAssetFinder::FindBlueprintAsset(FullAssetPath)) if (UMCPAssetFinder::FindAsset(UBlueprint::StaticClass(), BlueprintName) || UMCPAssetFinder::FindAsset(UBlueprint::StaticClass(), FullAssetPath))
{ {
return MCPUtils::MakeErrorJson(Result, FString::Printf( return MCPUtils::MakeErrorJson(Result, FString::Printf(
TEXT("Blueprint '%s' already exists. Use a different name or delete the existing asset first."), TEXT("Blueprint '%s' already exists. Use a different name or delete the existing asset first."),
@@ -156,7 +156,7 @@ void FBlueprintMCPServer::HandleCreateBlueprint(const FJsonObject* Json, FJsonOb
if (!ParentClass) if (!ParentClass)
{ {
FString ParentLoadError; FString ParentLoadError;
UBlueprint* ParentBP = UMCPAssetFinder::LoadBlueprintByName(ParentClassName, ParentLoadError); UBlueprint* ParentBP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(ParentClassName, ParentLoadError);
if (ParentBP && ParentBP->GeneratedClass) if (ParentBP && ParentBP->GeneratedClass)
{ {
ParentClass = ParentBP->GeneratedClass; ParentClass = ParentBP->GeneratedClass;
@@ -285,7 +285,7 @@ void FBlueprintMCPServer::HandleCreateGraph(const FJsonObject* Json, FJsonObject
// Load Blueprint // Load Blueprint
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(BlueprintName, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(BlueprintName, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -404,7 +404,7 @@ void FBlueprintMCPServer::HandleDeleteGraph(const FJsonObject* Json, FJsonObject
} }
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(BlueprintName, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(BlueprintName, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -490,7 +490,7 @@ void FBlueprintMCPServer::HandleRenameGraph(const FJsonObject* Json, FJsonObject
} }
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(BlueprintName, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(BlueprintName, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);

View File

@@ -34,7 +34,7 @@ public:
{ {
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(Blueprint, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(Blueprint, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -97,7 +97,7 @@ public:
{ {
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(Blueprint, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(Blueprint, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -138,7 +138,7 @@ public:
if (!InterfaceClass) if (!InterfaceClass)
{ {
FString IfaceLoadError; FString IfaceLoadError;
UBlueprint* IfaceBP = UMCPAssetFinder::LoadBlueprintByName(InterfaceName, IfaceLoadError); UBlueprint* IfaceBP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(InterfaceName, IfaceLoadError);
if (IfaceBP && IfaceBP->GeneratedClass && IfaceBP->GeneratedClass->IsChildOf(UInterface::StaticClass())) if (IfaceBP && IfaceBP->GeneratedClass && IfaceBP->GeneratedClass->IsChildOf(UInterface::StaticClass()))
{ {
InterfaceClass = IfaceBP->GeneratedClass; InterfaceClass = IfaceBP->GeneratedClass;
@@ -242,7 +242,7 @@ public:
{ {
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(Blueprint, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(Blueprint, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);

View File

@@ -41,7 +41,7 @@ void FBlueprintMCPServer::HandleCreateMaterialInstance(const FJsonObject* Json,
// Check if asset already exists // Check if asset already exists
FString FullAssetPath = PackagePath / Name; FString FullAssetPath = PackagePath / Name;
if (UMCPAssetFinder::FindMaterialInstanceAsset(Name) || UMCPAssetFinder::FindMaterialInstanceAsset(FullAssetPath)) if (UMCPAssetFinder::FindAsset(UMaterialInstanceConstant::StaticClass(), Name) || UMCPAssetFinder::FindAsset(UMaterialInstanceConstant::StaticClass(), FullAssetPath))
{ {
return MCPUtils::MakeErrorJson(Result, FString::Printf( return MCPUtils::MakeErrorJson(Result, FString::Printf(
TEXT("Material Instance '%s' already exists. Use a different name or delete the existing asset first."), TEXT("Material Instance '%s' already exists. Use a different name or delete the existing asset first."),
@@ -52,7 +52,7 @@ void FBlueprintMCPServer::HandleCreateMaterialInstance(const FJsonObject* Json,
UMaterialInterface* ParentMaterial = nullptr; UMaterialInterface* ParentMaterial = nullptr;
{ {
FString LoadError; FString LoadError;
UMaterial* ParentMat = UMCPAssetFinder::LoadMaterialByName(ParentMaterialName, LoadError); UMaterial* ParentMat = UMCPAssetFinder::LoadAsset<UMaterial>(ParentMaterialName, LoadError);
if (ParentMat) if (ParentMat)
{ {
ParentMaterial = ParentMat; ParentMaterial = ParentMat;
@@ -60,7 +60,7 @@ void FBlueprintMCPServer::HandleCreateMaterialInstance(const FJsonObject* Json,
else else
{ {
FString MILoadError; FString MILoadError;
UMaterialInstanceConstant* ParentMI = UMCPAssetFinder::LoadMaterialInstanceByName(ParentMaterialName, MILoadError); UMaterialInstanceConstant* ParentMI = UMCPAssetFinder::LoadAsset<UMaterialInstanceConstant>(ParentMaterialName, MILoadError);
if (ParentMI) if (ParentMI)
{ {
ParentMaterial = ParentMI; ParentMaterial = ParentMI;
@@ -146,7 +146,7 @@ void FBlueprintMCPServer::HandleSetMaterialInstanceParameter(const FJsonObject*
// Load the Material Instance // Load the Material Instance
FString LoadError; FString LoadError;
UMaterialInstanceConstant* MI = UMCPAssetFinder::LoadMaterialInstanceByName(MIName, LoadError); UMaterialInstanceConstant* MI = UMCPAssetFinder::LoadAsset<UMaterialInstanceConstant>(MIName, LoadError);
if (!MI) if (!MI)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -367,7 +367,7 @@ void FBlueprintMCPServer::HandleGetMaterialInstanceParameters(const FJsonObject*
} }
FString LoadError; FString LoadError;
UMaterialInstanceConstant* MI = UMCPAssetFinder::LoadMaterialInstanceByName(NameParam, LoadError); UMaterialInstanceConstant* MI = UMCPAssetFinder::LoadAsset<UMaterialInstanceConstant>(NameParam, LoadError);
if (!MI) if (!MI)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -615,7 +615,7 @@ void FBlueprintMCPServer::HandleReparentMaterialInstance(const FJsonObject* Json
// Load the Material Instance // Load the Material Instance
FString LoadError; FString LoadError;
UMaterialInstanceConstant* MI = UMCPAssetFinder::LoadMaterialInstanceByName(MIName, LoadError); UMaterialInstanceConstant* MI = UMCPAssetFinder::LoadAsset<UMaterialInstanceConstant>(MIName, LoadError);
if (!MI) if (!MI)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -628,7 +628,7 @@ void FBlueprintMCPServer::HandleReparentMaterialInstance(const FJsonObject* Json
UMaterialInterface* NewParent = nullptr; UMaterialInterface* NewParent = nullptr;
{ {
FString MatLoadError; FString MatLoadError;
UMaterial* NewParentMat = UMCPAssetFinder::LoadMaterialByName(NewParentName, MatLoadError); UMaterial* NewParentMat = UMCPAssetFinder::LoadAsset<UMaterial>(NewParentName, MatLoadError);
if (NewParentMat) if (NewParentMat)
{ {
NewParent = NewParentMat; NewParent = NewParentMat;
@@ -636,7 +636,7 @@ void FBlueprintMCPServer::HandleReparentMaterialInstance(const FJsonObject* Json
else else
{ {
FString MILoadError; FString MILoadError;
UMaterialInstanceConstant* NewParentMI = UMCPAssetFinder::LoadMaterialInstanceByName(NewParentName, MILoadError); UMaterialInstanceConstant* NewParentMI = UMCPAssetFinder::LoadAsset<UMaterialInstanceConstant>(NewParentName, MILoadError);
if (NewParentMI) if (NewParentMI)
{ {
NewParent = NewParentMI; NewParent = NewParentMI;

View File

@@ -75,7 +75,7 @@ void FBlueprintMCPServer::HandleCreateMaterial(const FJsonObject* Json, FJsonObj
// Check if asset already exists // Check if asset already exists
FString FullAssetPath = PackagePath / Name; FString FullAssetPath = PackagePath / Name;
if (UMCPAssetFinder::FindMaterialAsset(Name) || UMCPAssetFinder::FindMaterialAsset(FullAssetPath)) if (UMCPAssetFinder::FindAsset(UMaterial::StaticClass(), Name) || UMCPAssetFinder::FindAsset(UMaterial::StaticClass(), FullAssetPath))
{ {
return MCPUtils::MakeErrorJson(Result, FString::Printf( return MCPUtils::MakeErrorJson(Result, FString::Printf(
TEXT("Material '%s' already exists. Use a different name or delete the existing asset first."), TEXT("Material '%s' already exists. Use a different name or delete the existing asset first."),
@@ -219,7 +219,7 @@ void FBlueprintMCPServer::HandleSetMaterialProperty(const FJsonObject* Json, FJs
// Load material // Load material
FString LoadError; FString LoadError;
UMaterial* Material = UMCPAssetFinder::LoadMaterialByName(MaterialName, LoadError); UMaterial* Material = UMCPAssetFinder::LoadAsset<UMaterial>(MaterialName, LoadError);
if (!Material) if (!Material)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -563,7 +563,7 @@ void FBlueprintMCPServer::HandleAddMaterialExpression(const FJsonObject* Json, F
return MCPUtils::MakeErrorJson(Result, TEXT("Specify either 'material' or 'materialFunction', not both")); return MCPUtils::MakeErrorJson(Result, TEXT("Specify either 'material' or 'materialFunction', not both"));
} }
FString LoadError; FString LoadError;
MatFunc = UMCPAssetFinder::LoadMaterialFunctionByName(MaterialFunctionName, LoadError); MatFunc = UMCPAssetFinder::LoadAsset<UMaterialFunction>(MaterialFunctionName, LoadError);
if (!MatFunc) { MCPUtils::MakeErrorJson(Result, LoadError); return; } if (!MatFunc) { MCPUtils::MakeErrorJson(Result, LoadError); return; }
Owner = MatFunc; Owner = MatFunc;
AssetDisplayName = MatFunc->GetName(); AssetDisplayName = MatFunc->GetName();
@@ -571,7 +571,7 @@ void FBlueprintMCPServer::HandleAddMaterialExpression(const FJsonObject* Json, F
else else
{ {
FString LoadError; FString LoadError;
Material = UMCPAssetFinder::LoadMaterialByName(MaterialName, LoadError); Material = UMCPAssetFinder::LoadAsset<UMaterial>(MaterialName, LoadError);
if (!Material) { MCPUtils::MakeErrorJson(Result, LoadError); return; } if (!Material) { MCPUtils::MakeErrorJson(Result, LoadError); return; }
Owner = Material; Owner = Material;
AssetDisplayName = Material->GetName(); AssetDisplayName = Material->GetName();
@@ -701,14 +701,14 @@ void FBlueprintMCPServer::HandleDeleteMaterialExpression(const FJsonObject* Json
if (!MaterialFunctionName.IsEmpty()) if (!MaterialFunctionName.IsEmpty())
{ {
FString LoadError; FString LoadError;
MatFunc = UMCPAssetFinder::LoadMaterialFunctionByName(MaterialFunctionName, LoadError); MatFunc = UMCPAssetFinder::LoadAsset<UMaterialFunction>(MaterialFunctionName, LoadError);
if (!MatFunc) { MCPUtils::MakeErrorJson(Result, LoadError); return; } if (!MatFunc) { MCPUtils::MakeErrorJson(Result, LoadError); return; }
AssetDisplayName = MatFunc->GetName(); AssetDisplayName = MatFunc->GetName();
} }
else else
{ {
FString LoadError; FString LoadError;
Material = UMCPAssetFinder::LoadMaterialByName(MaterialName, LoadError); Material = UMCPAssetFinder::LoadAsset<UMaterial>(MaterialName, LoadError);
if (!Material) { MCPUtils::MakeErrorJson(Result, LoadError); return; } if (!Material) { MCPUtils::MakeErrorJson(Result, LoadError); return; }
AssetDisplayName = Material->GetName(); AssetDisplayName = Material->GetName();
} }
@@ -828,14 +828,14 @@ void FBlueprintMCPServer::HandleConnectMaterialPins(const FJsonObject* Json, FJs
if (!MaterialFunctionName.IsEmpty()) if (!MaterialFunctionName.IsEmpty())
{ {
FString LoadError; FString LoadError;
MatFunc = UMCPAssetFinder::LoadMaterialFunctionByName(MaterialFunctionName, LoadError); MatFunc = UMCPAssetFinder::LoadAsset<UMaterialFunction>(MaterialFunctionName, LoadError);
if (!MatFunc) { MCPUtils::MakeErrorJson(Result, LoadError); return; } if (!MatFunc) { MCPUtils::MakeErrorJson(Result, LoadError); return; }
AssetDisplayName = MatFunc->GetName(); AssetDisplayName = MatFunc->GetName();
} }
else else
{ {
FString LoadError; FString LoadError;
Material = UMCPAssetFinder::LoadMaterialByName(MaterialName, LoadError); Material = UMCPAssetFinder::LoadAsset<UMaterial>(MaterialName, LoadError);
if (!Material) { MCPUtils::MakeErrorJson(Result, LoadError); return; } if (!Material) { MCPUtils::MakeErrorJson(Result, LoadError); return; }
AssetDisplayName = Material->GetName(); AssetDisplayName = Material->GetName();
} }
@@ -979,14 +979,14 @@ void FBlueprintMCPServer::HandleDisconnectMaterialPin(const FJsonObject* Json, F
if (!MaterialFunctionName.IsEmpty()) if (!MaterialFunctionName.IsEmpty())
{ {
FString LoadError; FString LoadError;
MatFunc = UMCPAssetFinder::LoadMaterialFunctionByName(MaterialFunctionName, LoadError); MatFunc = UMCPAssetFinder::LoadAsset<UMaterialFunction>(MaterialFunctionName, LoadError);
if (!MatFunc) { MCPUtils::MakeErrorJson(Result, LoadError); return; } if (!MatFunc) { MCPUtils::MakeErrorJson(Result, LoadError); return; }
AssetDisplayName = MatFunc->GetName(); AssetDisplayName = MatFunc->GetName();
} }
else else
{ {
FString LoadError; FString LoadError;
Material = UMCPAssetFinder::LoadMaterialByName(MaterialName, LoadError); Material = UMCPAssetFinder::LoadAsset<UMaterial>(MaterialName, LoadError);
if (!Material) { MCPUtils::MakeErrorJson(Result, LoadError); return; } if (!Material) { MCPUtils::MakeErrorJson(Result, LoadError); return; }
AssetDisplayName = Material->GetName(); AssetDisplayName = Material->GetName();
} }
@@ -1101,14 +1101,14 @@ void FBlueprintMCPServer::HandleSetExpressionValue(const FJsonObject* Json, FJso
if (!MaterialFunctionName.IsEmpty()) if (!MaterialFunctionName.IsEmpty())
{ {
FString LoadError; FString LoadError;
MatFunc = UMCPAssetFinder::LoadMaterialFunctionByName(MaterialFunctionName, LoadError); MatFunc = UMCPAssetFinder::LoadAsset<UMaterialFunction>(MaterialFunctionName, LoadError);
if (!MatFunc) { MCPUtils::MakeErrorJson(Result, LoadError); return; } if (!MatFunc) { MCPUtils::MakeErrorJson(Result, LoadError); return; }
AssetDisplayName = MatFunc->GetName(); AssetDisplayName = MatFunc->GetName();
} }
else else
{ {
FString LoadError; FString LoadError;
Material = UMCPAssetFinder::LoadMaterialByName(MaterialName, LoadError); Material = UMCPAssetFinder::LoadAsset<UMaterial>(MaterialName, LoadError);
if (!Material) { MCPUtils::MakeErrorJson(Result, LoadError); return; } if (!Material) { MCPUtils::MakeErrorJson(Result, LoadError); return; }
AssetDisplayName = Material->GetName(); AssetDisplayName = Material->GetName();
} }
@@ -1378,14 +1378,14 @@ void FBlueprintMCPServer::HandleMoveMaterialExpression(const FJsonObject* Json,
if (!MaterialFunctionName.IsEmpty()) if (!MaterialFunctionName.IsEmpty())
{ {
FString LoadError; FString LoadError;
MatFunc = UMCPAssetFinder::LoadMaterialFunctionByName(MaterialFunctionName, LoadError); MatFunc = UMCPAssetFinder::LoadAsset<UMaterialFunction>(MaterialFunctionName, LoadError);
if (!MatFunc) { MCPUtils::MakeErrorJson(Result, LoadError); return; } if (!MatFunc) { MCPUtils::MakeErrorJson(Result, LoadError); return; }
AssetDisplayName = MatFunc->GetName(); AssetDisplayName = MatFunc->GetName();
} }
else else
{ {
FString LoadError; FString LoadError;
Material = UMCPAssetFinder::LoadMaterialByName(MaterialName, LoadError); Material = UMCPAssetFinder::LoadAsset<UMaterial>(MaterialName, LoadError);
if (!Material) { MCPUtils::MakeErrorJson(Result, LoadError); return; } if (!Material) { MCPUtils::MakeErrorJson(Result, LoadError); return; }
AssetDisplayName = Material->GetName(); AssetDisplayName = Material->GetName();
} }
@@ -1482,7 +1482,7 @@ void FBlueprintMCPServer::HandleCreateMaterialFunction(const FJsonObject* Json,
// Check if asset already exists // Check if asset already exists
FString FullAssetPath = PackagePath / Name; FString FullAssetPath = PackagePath / Name;
if (UMCPAssetFinder::FindMaterialFunctionAsset(Name) || UMCPAssetFinder::FindMaterialFunctionAsset(FullAssetPath)) if (UMCPAssetFinder::FindAsset(UMaterialFunction::StaticClass(), Name) || UMCPAssetFinder::FindAsset(UMaterialFunction::StaticClass(), FullAssetPath))
{ {
return MCPUtils::MakeErrorJson(Result, FString::Printf( return MCPUtils::MakeErrorJson(Result, FString::Printf(
TEXT("Material Function '%s' already exists. Use a different name or delete the existing asset first."), TEXT("Material Function '%s' already exists. Use a different name or delete the existing asset first."),
@@ -1551,7 +1551,7 @@ void FBlueprintMCPServer::HandleSnapshotMaterialGraph(const FJsonObject* Json, F
// Load material // Load material
FString LoadError; FString LoadError;
UMaterial* Material = UMCPAssetFinder::LoadMaterialByName(MaterialName, LoadError); UMaterial* Material = UMCPAssetFinder::LoadAsset<UMaterial>(MaterialName, LoadError);
if (!Material) if (!Material)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -1650,7 +1650,7 @@ void FBlueprintMCPServer::HandleDiffMaterialGraph(const FJsonObject* Json, FJson
// Load material // Load material
FString LoadError; FString LoadError;
UMaterial* Material = UMCPAssetFinder::LoadMaterialByName(MaterialName, LoadError); UMaterial* Material = UMCPAssetFinder::LoadAsset<UMaterial>(MaterialName, LoadError);
if (!Material) if (!Material)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -1816,7 +1816,7 @@ void FBlueprintMCPServer::HandleRestoreMaterialGraph(const FJsonObject* Json, FJ
// Load material // Load material
FString LoadError; FString LoadError;
UMaterial* Material = UMCPAssetFinder::LoadMaterialByName(MaterialName, LoadError); UMaterial* Material = UMCPAssetFinder::LoadAsset<UMaterial>(MaterialName, LoadError);
if (!Material) if (!Material)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);

View File

@@ -48,7 +48,7 @@ void FBlueprintMCPServer::HandleListMaterials(const FJsonObject* Json, FJsonObje
if (bIncludeMaterials) if (bIncludeMaterials)
{ {
for (const FAssetData& Asset : UMCPAssetFinder::GetMaterialAssets()) for (const FAssetData& Asset : UMCPAssetFinder::GetAssets(UMaterial::StaticClass()))
{ {
FString Name = Asset.AssetName.ToString(); FString Name = Asset.AssetName.ToString();
FString Path = Asset.PackageName.ToString(); FString Path = Asset.PackageName.ToString();
@@ -72,7 +72,7 @@ void FBlueprintMCPServer::HandleListMaterials(const FJsonObject* Json, FJsonObje
if (bIncludeInstances) if (bIncludeInstances)
{ {
for (const FAssetData& Asset : UMCPAssetFinder::GetMaterialInstanceAssets()) for (const FAssetData& Asset : UMCPAssetFinder::GetAssets(UMaterialInstanceConstant::StaticClass()))
{ {
FString Name = Asset.AssetName.ToString(); FString Name = Asset.AssetName.ToString();
FString Path = Asset.PackageName.ToString(); FString Path = Asset.PackageName.ToString();
@@ -94,7 +94,7 @@ void FBlueprintMCPServer::HandleListMaterials(const FJsonObject* Json, FJsonObje
} }
} }
int32 Total = UMCPAssetFinder::GetMaterialAssets().Num() + UMCPAssetFinder::GetMaterialInstanceAssets().Num(); int32 Total = UMCPAssetFinder::GetAssets(UMaterial::StaticClass()).Num() + UMCPAssetFinder::GetAssets(UMaterialInstanceConstant::StaticClass()).Num();
Result->SetNumberField(TEXT("count"), Entries.Num()); Result->SetNumberField(TEXT("count"), Entries.Num());
Result->SetNumberField(TEXT("total"), Total); Result->SetNumberField(TEXT("total"), Total);
@@ -117,7 +117,7 @@ void FBlueprintMCPServer::HandleGetMaterial(const FJsonObject* Json, FJsonObject
// Try loading as UMaterial first // Try loading as UMaterial first
FString LoadError; FString LoadError;
UMaterial* Material = UMCPAssetFinder::LoadMaterialByName(DecodedName, LoadError); UMaterial* Material = UMCPAssetFinder::LoadAsset<UMaterial>(DecodedName, LoadError);
if (Material) if (Material)
{ {
UE_LOG(LogTemp, Display, TEXT("BlueprintMCP: GetMaterial — loaded material '%s'"), *Material->GetName()); UE_LOG(LogTemp, Display, TEXT("BlueprintMCP: GetMaterial — loaded material '%s'"), *Material->GetName());
@@ -272,7 +272,7 @@ void FBlueprintMCPServer::HandleGetMaterial(const FJsonObject* Json, FJsonObject
// Try loading as MaterialInstance // Try loading as MaterialInstance
FString MILoadError; FString MILoadError;
UMaterialInstanceConstant* MI = UMCPAssetFinder::LoadMaterialInstanceByName(DecodedName, MILoadError); UMaterialInstanceConstant* MI = UMCPAssetFinder::LoadAsset<UMaterialInstanceConstant>(DecodedName, MILoadError);
if (MI) if (MI)
{ {
UE_LOG(LogTemp, Display, TEXT("BlueprintMCP: GetMaterial — loaded material instance '%s'"), *MI->GetName()); UE_LOG(LogTemp, Display, TEXT("BlueprintMCP: GetMaterial — loaded material instance '%s'"), *MI->GetName());
@@ -362,7 +362,7 @@ void FBlueprintMCPServer::HandleGetMaterialGraph(const FJsonObject* Json, FJsonO
FString DecodedName = MCPUtils::UrlDecode(Name); FString DecodedName = MCPUtils::UrlDecode(Name);
FString LoadError; FString LoadError;
UMaterial* Material = UMCPAssetFinder::LoadMaterialByName(DecodedName, LoadError); UMaterial* Material = UMCPAssetFinder::LoadAsset<UMaterial>(DecodedName, LoadError);
if (!Material) if (!Material)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -412,7 +412,7 @@ void FBlueprintMCPServer::HandleDescribeMaterial(const FJsonObject* Json, FJsonO
} }
FString LoadError; FString LoadError;
UMaterial* Material = UMCPAssetFinder::LoadMaterialByName(MaterialName, LoadError); UMaterial* Material = UMCPAssetFinder::LoadAsset<UMaterial>(MaterialName, LoadError);
if (!Material) if (!Material)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -624,7 +624,7 @@ void FBlueprintMCPServer::HandleSearchMaterials(const FJsonObject* Json, FJsonOb
TArray<TSharedPtr<FJsonValue>> Results; TArray<TSharedPtr<FJsonValue>> Results;
for (const FAssetData& Asset : UMCPAssetFinder::GetMaterialAssets()) for (const FAssetData& Asset : UMCPAssetFinder::GetAssets(UMaterial::StaticClass()))
{ {
if (Results.Num() >= MaxResults) break; if (Results.Num() >= MaxResults) break;
@@ -706,7 +706,7 @@ void FBlueprintMCPServer::HandleFindMaterialReferences(const FJsonObject* Json,
// Try to find the material's package path // Try to find the material's package path
FString PackagePath; FString PackagePath;
FAssetData* MatAsset = UMCPAssetFinder::FindMaterialAsset(MaterialName); FAssetData* MatAsset = UMCPAssetFinder::FindAsset(UMaterial::StaticClass(), MaterialName);
if (MatAsset) if (MatAsset)
{ {
PackagePath = MatAsset->PackageName.ToString(); PackagePath = MatAsset->PackageName.ToString();
@@ -714,7 +714,7 @@ void FBlueprintMCPServer::HandleFindMaterialReferences(const FJsonObject* Json,
else else
{ {
// Try material instance // Try material instance
FAssetData* MIAsset = UMCPAssetFinder::FindMaterialInstanceAsset(MaterialName); FAssetData* MIAsset = UMCPAssetFinder::FindAsset(UMaterialInstanceConstant::StaticClass(), MaterialName);
if (MIAsset) if (MIAsset)
{ {
PackagePath = MIAsset->PackageName.ToString(); PackagePath = MIAsset->PackageName.ToString();
@@ -759,7 +759,7 @@ void FBlueprintMCPServer::HandleListMaterialFunctions(const FJsonObject* Json, F
TArray<TSharedPtr<FJsonValue>> Entries; TArray<TSharedPtr<FJsonValue>> Entries;
for (const FAssetData& Asset : UMCPAssetFinder::GetMaterialFunctionAssets()) for (const FAssetData& Asset : UMCPAssetFinder::GetAssets(UMaterialFunction::StaticClass()))
{ {
FString Name = Asset.AssetName.ToString(); FString Name = Asset.AssetName.ToString();
FString Path = Asset.PackageName.ToString(); FString Path = Asset.PackageName.ToString();
@@ -780,7 +780,7 @@ void FBlueprintMCPServer::HandleListMaterialFunctions(const FJsonObject* Json, F
} }
Result->SetNumberField(TEXT("count"), Entries.Num()); Result->SetNumberField(TEXT("count"), Entries.Num());
Result->SetNumberField(TEXT("total"), UMCPAssetFinder::GetMaterialFunctionAssets().Num()); Result->SetNumberField(TEXT("total"), UMCPAssetFinder::GetAssets(UMaterialFunction::StaticClass()).Num());
Result->SetArrayField(TEXT("functions"), Entries); Result->SetArrayField(TEXT("functions"), Entries);
} }
@@ -799,7 +799,7 @@ void FBlueprintMCPServer::HandleGetMaterialFunction(const FJsonObject* Json, FJs
FString DecodedName = MCPUtils::UrlDecode(Name); FString DecodedName = MCPUtils::UrlDecode(Name);
FString LoadError; FString LoadError;
UMaterialFunction* MF = UMCPAssetFinder::LoadMaterialFunctionByName(DecodedName, LoadError); UMaterialFunction* MF = UMCPAssetFinder::LoadAsset<UMaterialFunction>(DecodedName, LoadError);
if (!MF) if (!MF)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -883,7 +883,7 @@ void FBlueprintMCPServer::HandleValidateMaterial(const FJsonObject* Json, FJsonO
// Load material // Load material
FString LoadError; FString LoadError;
UMaterial* Material = UMCPAssetFinder::LoadMaterialByName(MaterialName, LoadError); UMaterial* Material = UMCPAssetFinder::LoadAsset<UMaterial>(MaterialName, LoadError);
if (!Material) if (!Material)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);

View File

@@ -91,7 +91,7 @@ public:
{ {
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(Blueprint, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(Blueprint, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -183,7 +183,7 @@ public:
{ {
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(Blueprint, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(Blueprint, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -359,7 +359,7 @@ public:
// Load Blueprint // Load Blueprint
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(Blueprint, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(Blueprint, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -505,7 +505,7 @@ public:
{ {
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(Blueprint, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(Blueprint, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -553,7 +553,7 @@ public:
{ {
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(Blueprint, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(Blueprint, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -614,7 +614,7 @@ public:
{ {
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(Blueprint, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(Blueprint, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -713,7 +713,7 @@ public:
// Load Blueprint // Load Blueprint
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(Blueprint, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(Blueprint, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -965,7 +965,7 @@ public:
// Load Blueprint // Load Blueprint
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(Blueprint, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(Blueprint, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -1093,7 +1093,7 @@ public:
// Load Blueprint // Load Blueprint
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(Blueprint, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(Blueprint, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -1326,7 +1326,7 @@ public:
// Load Blueprint // Load Blueprint
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(Blueprint, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(Blueprint, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -1378,7 +1378,7 @@ public:
if (!ResolvedClass) if (!ResolvedClass)
{ {
FString BPLoadError; FString BPLoadError;
UBlueprint* ValueBP = UMCPAssetFinder::LoadBlueprintByName(Value, BPLoadError); UBlueprint* ValueBP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(Value, BPLoadError);
if (ValueBP && ValueBP->GeneratedClass) if (ValueBP && ValueBP->GeneratedClass)
{ {
ResolvedClass = ValueBP->GeneratedClass; ResolvedClass = ValueBP->GeneratedClass;
@@ -1418,7 +1418,7 @@ public:
// Try loading as a Blueprint asset // Try loading as a Blueprint asset
FString ObjLoadError; FString ObjLoadError;
UBlueprint* ValueBP = UMCPAssetFinder::LoadBlueprintByName(Value, ObjLoadError); UBlueprint* ValueBP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(Value, ObjLoadError);
if (ValueBP && ValueBP->GeneratedClass) if (ValueBP && ValueBP->GeneratedClass)
{ {
ResolvedObj = ValueBP->GeneratedClass->GetDefaultObject(); ResolvedObj = ValueBP->GeneratedClass->GetDefaultObject();

View File

@@ -29,7 +29,7 @@ void FBlueprintMCPServer::HandleChangeFunctionParamType(const FJsonObject* Json,
// Load Blueprint // Load Blueprint
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(BlueprintName, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(BlueprintName, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -247,7 +247,7 @@ void FBlueprintMCPServer::HandleRemoveFunctionParameter(const FJsonObject* Json,
// Load Blueprint // Load Blueprint
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(BlueprintName, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(BlueprintName, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -408,7 +408,7 @@ void FBlueprintMCPServer::HandleAddFunctionParameter(const FJsonObject* Json, FJ
// Load Blueprint // Load Blueprint
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(BlueprintName, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(BlueprintName, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);

View File

@@ -74,7 +74,7 @@ public:
EntryResult->SetStringField(TEXT("pinName"), Entry.PinName); EntryResult->SetStringField(TEXT("pinName"), Entry.PinName);
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(Entry.Blueprint, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(Entry.Blueprint, LoadError);
if (!BP) if (!BP)
{ {
EntryResult->SetStringField(TEXT("error"), LoadError); EntryResult->SetStringField(TEXT("error"), LoadError);
@@ -189,7 +189,7 @@ public:
{ {
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(Blueprint, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(Blueprint, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -327,7 +327,7 @@ public:
{ {
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(Blueprint, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(Blueprint, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);

View File

@@ -37,7 +37,7 @@ void FBlueprintMCPServer::HandleList(const FJsonObject* Json, FJsonObject* Resul
TArray<TSharedPtr<FJsonValue>> Entries; TArray<TSharedPtr<FJsonValue>> Entries;
if (bIncludeRegular) if (bIncludeRegular)
for (const FAssetData& Asset : UMCPAssetFinder::GetBlueprintAssets()) for (const FAssetData& Asset : UMCPAssetFinder::GetAssets(UBlueprint::StaticClass()))
{ {
FString Name = Asset.AssetName.ToString(); FString Name = Asset.AssetName.ToString();
FString Path = Asset.PackageName.ToString(); FString Path = Asset.PackageName.ToString();
@@ -77,7 +77,7 @@ void FBlueprintMCPServer::HandleList(const FJsonObject* Json, FJsonObject* Resul
// Also include level blueprints from maps // Also include level blueprints from maps
if (bIncludeLevel) if (bIncludeLevel)
for (const FAssetData& Asset : UMCPAssetFinder::GetMapAssets()) for (const FAssetData& Asset : UMCPAssetFinder::GetAssets(UWorld::StaticClass()))
{ {
FString Name = Asset.AssetName.ToString(); FString Name = Asset.AssetName.ToString();
FString Path = Asset.PackageName.ToString(); FString Path = Asset.PackageName.ToString();
@@ -109,7 +109,7 @@ void FBlueprintMCPServer::HandleList(const FJsonObject* Json, FJsonObject* Resul
} }
Result->SetNumberField(TEXT("count"), Entries.Num()); Result->SetNumberField(TEXT("count"), Entries.Num());
Result->SetNumberField(TEXT("total"), UMCPAssetFinder::GetBlueprintAssets().Num() + UMCPAssetFinder::GetMapAssets().Num()); Result->SetNumberField(TEXT("total"), UMCPAssetFinder::GetAssets(UBlueprint::StaticClass()).Num() + UMCPAssetFinder::GetAssets(UWorld::StaticClass()).Num());
Result->SetArrayField(TEXT("blueprints"), Entries); Result->SetArrayField(TEXT("blueprints"), Entries);
} }
@@ -122,7 +122,7 @@ void FBlueprintMCPServer::HandleGetBlueprint(const FJsonObject* Json, FJsonObjec
} }
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(Name, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(Name, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -145,7 +145,7 @@ void FBlueprintMCPServer::HandleGetGraph(const FJsonObject* Json, FJsonObject* R
FString DecodedGraphName = MCPUtils::UrlDecode(GraphName); FString DecodedGraphName = MCPUtils::UrlDecode(GraphName);
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(Name, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(Name, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -257,7 +257,7 @@ void FBlueprintMCPServer::HandleSearch(const FJsonObject* Json, FJsonObject* Res
}; };
TArray<TSharedPtr<FJsonValue>> Results; TArray<TSharedPtr<FJsonValue>> Results;
for (const FAssetData& Asset : UMCPAssetFinder::GetBlueprintAssets()) for (const FAssetData& Asset : UMCPAssetFinder::GetAssets(UBlueprint::StaticClass()))
{ {
if (Results.Num() >= MaxResults) break; if (Results.Num() >= MaxResults) break;
@@ -274,7 +274,7 @@ void FBlueprintMCPServer::HandleSearch(const FJsonObject* Json, FJsonObject* Res
} }
// Also search level blueprints // Also search level blueprints
for (const FAssetData& MapAsset : UMCPAssetFinder::GetMapAssets()) for (const FAssetData& MapAsset : UMCPAssetFinder::GetAssets(UWorld::StaticClass()))
{ {
if (Results.Num() >= MaxResults) break; if (Results.Num() >= MaxResults) break;
@@ -318,7 +318,7 @@ void FBlueprintMCPServer::HandleTestSave(const FJsonObject* Json, FJsonObject* R
UE_LOG(LogTemp, Display, TEXT("BlueprintMCP: test-save requested for '%s'"), *Name); UE_LOG(LogTemp, Display, TEXT("BlueprintMCP: test-save requested for '%s'"), *Name);
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(Name, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(Name, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -356,7 +356,7 @@ void FBlueprintMCPServer::HandleFindReferences(const FJsonObject* Json, FJsonObj
// Build set of known Blueprint package names for filtering // Build set of known Blueprint package names for filtering
TSet<FString> BlueprintPackages; TSet<FString> BlueprintPackages;
for (const FAssetData& Asset : UMCPAssetFinder::GetBlueprintAssets()) for (const FAssetData& Asset : UMCPAssetFinder::GetAssets(UBlueprint::StaticClass()))
{ {
BlueprintPackages.Add(Asset.PackageName.ToString()); BlueprintPackages.Add(Asset.PackageName.ToString());
} }
@@ -587,7 +587,7 @@ void FBlueprintMCPServer::HandleSearchByType(const FJsonObject* Json, FJsonObjec
}; };
// Search regular blueprints // Search regular blueprints
for (const FAssetData& Asset : UMCPAssetFinder::GetBlueprintAssets()) for (const FAssetData& Asset : UMCPAssetFinder::GetAssets(UBlueprint::StaticClass()))
{ {
if (Results.Num() >= MaxResults) break; if (Results.Num() >= MaxResults) break;
@@ -607,7 +607,7 @@ void FBlueprintMCPServer::HandleSearchByType(const FJsonObject* Json, FJsonObjec
} }
// Search level blueprints from maps // Search level blueprints from maps
for (const FAssetData& MapAsset : UMCPAssetFinder::GetMapAssets()) for (const FAssetData& MapAsset : UMCPAssetFinder::GetAssets(UWorld::StaticClass()))
{ {
if (Results.Num() >= MaxResults) break; if (Results.Num() >= MaxResults) break;

View File

@@ -269,7 +269,7 @@ void FBlueprintMCPServer::HandleSnapshotGraph(const FJsonObject* Json, FJsonObje
// Load Blueprint // Load Blueprint
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(BlueprintName, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(BlueprintName, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -369,7 +369,7 @@ void FBlueprintMCPServer::HandleDiffGraph(const FJsonObject* Json, FJsonObject*
// Load the current blueprint // Load the current blueprint
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(BlueprintName, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(BlueprintName, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -588,7 +588,7 @@ void FBlueprintMCPServer::HandleRestoreGraph(const FJsonObject* Json, FJsonObjec
// Load the current blueprint // Load the current blueprint
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(BlueprintName, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(BlueprintName, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -821,7 +821,7 @@ void FBlueprintMCPServer::HandleFindDisconnectedPins(const FJsonObject* Json, FJ
} }
else if (!PathFilter.IsEmpty()) else if (!PathFilter.IsEmpty())
{ {
for (const FAssetData& Asset : UMCPAssetFinder::GetBlueprintAssets()) for (const FAssetData& Asset : UMCPAssetFinder::GetAssets(UBlueprint::StaticClass()))
{ {
if (Asset.PackageName.ToString().Contains(PathFilter) || Asset.AssetName.ToString().Contains(PathFilter)) if (Asset.PackageName.ToString().Contains(PathFilter) || Asset.AssetName.ToString().Contains(PathFilter))
{ {
@@ -845,7 +845,7 @@ void FBlueprintMCPServer::HandleFindDisconnectedPins(const FJsonObject* Json, FJ
for (const FString& BPName : BlueprintsToScan) for (const FString& BPName : BlueprintsToScan)
{ {
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(BPName, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(BPName, LoadError);
if (!BP) continue; if (!BP) continue;
BlueprintsScanned++; BlueprintsScanned++;
@@ -1206,10 +1206,10 @@ void FBlueprintMCPServer::HandleAnalyzeRebuildImpact(const FJsonObject* Json, FJ
int32 TotalBreakMakeNodes = 0; int32 TotalBreakMakeNodes = 0;
int32 TotalConnectionsAtRisk = 0; int32 TotalConnectionsAtRisk = 0;
for (const FAssetData& Asset : UMCPAssetFinder::GetBlueprintAssets()) for (const FAssetData& Asset : UMCPAssetFinder::GetAssets(UBlueprint::StaticClass()))
{ {
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(Asset.AssetName.ToString(), LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(Asset.AssetName.ToString(), LoadError);
if (!BP) continue; if (!BP) continue;
FBlueprintImpact Impact; FBlueprintImpact Impact;

View File

@@ -239,7 +239,7 @@ public:
{ {
// Find the struct // Find the struct
FString StructError; FString StructError;
UUserDefinedStruct* Struct = UMCPAssetFinder::LoadStructByName(AssetPath, StructError); UUserDefinedStruct* Struct = UMCPAssetFinder::LoadAsset<UUserDefinedStruct>(AssetPath, StructError);
if (!Struct) if (!Struct)
{ {
return MCPUtils::MakeErrorJson(Result, StructError); return MCPUtils::MakeErrorJson(Result, StructError);
@@ -312,7 +312,7 @@ public:
{ {
// Find the struct // Find the struct
FString StructError; FString StructError;
UUserDefinedStruct* Struct = UMCPAssetFinder::LoadStructByName(AssetPath, StructError); UUserDefinedStruct* Struct = UMCPAssetFinder::LoadAsset<UUserDefinedStruct>(AssetPath, StructError);
if (!Struct) if (!Struct)
{ {
return MCPUtils::MakeErrorJson(Result, StructError); return MCPUtils::MakeErrorJson(Result, StructError);

View File

@@ -139,7 +139,7 @@ public:
TArray<FAssetData*> MatchingAssets; TArray<FAssetData*> MatchingAssets;
if (!Blueprint.IsEmpty()) if (!Blueprint.IsEmpty())
{ {
FAssetData* Asset = UMCPAssetFinder::FindBlueprintAsset(Blueprint, nullptr, /*bIncludeLevelBlueprints=*/true); FAssetData* Asset = UMCPAssetFinder::FindAsset(UMCPAssetFinder::BlueprintsAndMaps, Blueprint);
if (!Asset) if (!Asset)
{ {
return MCPUtils::MakeErrorJson(Result, FString::Printf(TEXT("Blueprint '%s' not found."), *Blueprint)); return MCPUtils::MakeErrorJson(Result, FString::Printf(TEXT("Blueprint '%s' not found."), *Blueprint));
@@ -148,7 +148,7 @@ public:
} }
else else
{ {
MatchingAssets = UMCPAssetFinder::SearchBlueprintAssets(Query, /*bIncludeLevelBlueprints=*/true); MatchingAssets = UMCPAssetFinder::SearchAssets(UMCPAssetFinder::BlueprintsAndMaps, Query);
} }
int32 TotalMatching = MatchingAssets.Num(); int32 TotalMatching = MatchingAssets.Num();
@@ -185,7 +185,7 @@ public:
// Load the Blueprint (handles both regular and level blueprints) // Load the Blueprint (handles both regular and level blueprints)
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(PackagePath, LoadError, /*bIncludeLevelBlueprints=*/true); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(PackagePath, LoadError);
if (!BP) if (!BP)
{ {
continue; continue;

View File

@@ -35,7 +35,7 @@ void FBlueprintMCPServer::HandleChangeVariableType(const FJsonObject* Json, FJso
// Load Blueprint // Load Blueprint
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(BlueprintName, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(BlueprintName, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -251,7 +251,7 @@ void FBlueprintMCPServer::HandleAddVariable(const FJsonObject* Json, FJsonObject
// Load Blueprint // Load Blueprint
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(BlueprintName, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(BlueprintName, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -333,7 +333,7 @@ void FBlueprintMCPServer::HandleRemoveVariable(const FJsonObject* Json, FJsonObj
// Load Blueprint // Load Blueprint
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(BlueprintName, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(BlueprintName, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);
@@ -401,7 +401,7 @@ void FBlueprintMCPServer::HandleSetVariableMetadata(const FJsonObject* Json, FJs
// Load Blueprint // Load Blueprint
FString LoadError; FString LoadError;
UBlueprint* BP = UMCPAssetFinder::LoadBlueprintByName(BlueprintName, LoadError); UBlueprint* BP = UMCPAssetFinder::LoadBlueprintOrLevelBlueprint(BlueprintName, LoadError);
if (!BP) if (!BP)
{ {
return MCPUtils::MakeErrorJson(Result, LoadError); return MCPUtils::MakeErrorJson(Result, LoadError);

View File

@@ -491,6 +491,7 @@ FString FMCPServer::HandleToolsCall(int32 Id, const FJsonObject* Params)
void FMCPServer::DispatchToolCall(const FString& ToolName, const FJsonObject* Params, FJsonObject* Result) void FMCPServer::DispatchToolCall(const FString& ToolName, const FJsonObject* Params, FJsonObject* Result)
{ {
UMCPAssetFinder::Refresh();
if (UClass** HandlerClass = MCPHandlerRegistry.Find(ToolName)) if (UClass** HandlerClass = MCPHandlerRegistry.Find(ToolName))
{ {
const bool bIsMutation = MutationEndpoints.Contains(ToolName); const bool bIsMutation = MutationEndpoints.Contains(ToolName);

View File

@@ -11,6 +11,7 @@ class UBlueprint;
class UMaterial; class UMaterial;
class UMaterialInstanceConstant; class UMaterialInstanceConstant;
class UMaterialFunction; class UMaterialFunction;
class IAssetRegistry;
/** /**
* Engine subsystem that caches asset registry data for the BlueprintMCP server. * Engine subsystem that caches asset registry data for the BlueprintMCP server.
@@ -25,49 +26,66 @@ class UMCPAssetFinder : public UEngineSubsystem
public: public:
virtual void Initialize(FSubsystemCollectionBase& Collection) override; virtual void Initialize(FSubsystemCollectionBase& Collection) override;
virtual void Deinitialize() override; virtual void Deinitialize() override;
static FName BlueprintsAndMaps;
// Call once before processing a request. Rebuilds caches if the asset registry has changed.
// After this call, all query methods read from a stable snapshot until the next Refresh().
static void Refresh();
// --- Static API: asset lists --- // --- Static API: asset lists ---
static const TArray<FAssetData>& GetBlueprintAssets(); static const TArray<FAssetData>& GetAssets(FName Class);
static const TArray<FAssetData>& GetBlueprintAndMapAssets(); static const TArray<FAssetData>& GetAssets(UClass *Class);
static const TArray<FAssetData>& GetMapAssets();
static const TArray<FAssetData>& GetMaterialAssets();
static const TArray<FAssetData>& GetMaterialInstanceAssets();
static const TArray<FAssetData>& GetMaterialFunctionAssets();
static const TArray<FAssetData>& GetStructAssets();
static const TArray<FAssetData>& GetEnumAssets();
// --- Static API: find/load helpers --- // --- Static API: find/load helpers ---
// Find functions return nullptr if not found or if the short name is ambiguous. static FAssetData* FindAsset(FName Class, const FString& NameOrPath, FString* OutError = nullptr);
// Pass OutError to get a descriptive message on failure. static FAssetData* FindAsset(UClass *Class, const FString& NameOrPath, FString* OutError = nullptr);
static FAssetData* FindAnyAsset(const FString& NameOrPath, FString* OutError = nullptr);
static FAssetData* FindBlueprintAsset(const FString& NameOrPath, FString* OutError = nullptr, bool bIncludeLevelBlueprints = false);
static TArray<FAssetData*> SearchBlueprintAssets(const FString& Filter, bool bIncludeLevelBlueprints = false);
static FAssetData* FindMapAsset(const FString& NameOrPath, FString* OutError = nullptr);
static UBlueprint* LoadBlueprintByName(const FString& NameOrPath, FString& OutError, bool bIncludeLevelBlueprints = true);
static FAssetData* FindMaterialAsset(const FString& NameOrPath, FString* OutError = nullptr); // --- Static API: find/load helpers ---
static UMaterial* LoadMaterialByName(const FString& NameOrPath, FString& OutError); static TArray<FAssetData*> SearchAssets(FName Class, const FString& NameOrPath, FString* OutError = nullptr);
static FAssetData* FindMaterialInstanceAsset(const FString& NameOrPath, FString* OutError = nullptr); static TArray<FAssetData*> SearchAssets(UClass *Class, const FString& NameOrPath, FString* OutError = nullptr);
static UMaterialInstanceConstant* LoadMaterialInstanceByName(const FString& NameOrPath, FString& OutError);
static FAssetData* FindMaterialFunctionAsset(const FString& NameOrPath, FString* OutError = nullptr); // Load an asset from an FAssetData. Returns nullptr and sets OutError on failure.
static UMaterialFunction* LoadMaterialFunctionByName(const FString& NameOrPath, FString& OutError); template<typename T>
static FAssetData* FindStructAsset(const FString& NameOrPath, FString* OutError = nullptr); static T* LoadAsset(FAssetData& Asset, FString& OutError)
static UUserDefinedStruct* LoadStructByName(const FString& NameOrPath, FString& OutError); {
static FAssetData* FindEnumAsset(const FString& NameOrPath, FString* OutError = nullptr); T* Result = Cast<T>(Asset.GetAsset());
static UUserDefinedEnum* LoadEnumByName(const FString& NameOrPath, FString& OutError); if (!Result)
OutError = FString::Printf(TEXT("Asset '%s' found but could not be loaded as %s."),
*Asset.AssetName.ToString(), *T::StaticClass()->GetName());
return Result;
}
// Load an asset by name or path. Returns nullptr and sets OutError on failure.
template<typename T>
static T* LoadAsset(const FString& NameOrPath, FString& OutError)
{
FAssetData* Asset = FindAsset(T::StaticClass(), NameOrPath, &OutError);
if (!Asset)
{
if (OutError.IsEmpty())
OutError = FString::Printf(TEXT("'%s' not found."), *NameOrPath);
return nullptr;
}
return LoadAsset<T>(*Asset, OutError);
}
static FAssetData* FindAnyAsset(const FString& NameOrPath, FString* OutError = nullptr);
// Load a blueprint or level blueprint from an asset (handles UWorld → level blueprint extraction).
static UBlueprint* LoadBlueprintOrLevelBlueprint(FAssetData& Asset, FString& OutError);
static UBlueprint* LoadBlueprintOrLevelBlueprint(const FString& NameOrPath, FString& OutError);
private: private:
/** Get the subsystem, refreshing asset caches if stale. Returns nullptr if engine is not initialized. */ // Fetch assets from the Unreal asset registry and store them locally.
static UMCPAssetFinder* GetUpdatedAssets(); void CacheAssets(IAssetRegistry &Registry, UClass *Class, bool IncludeSubclasses);
// Cached asset lists // Returns the subsystem instance, or nullptr if the engine is not initialized.
TArray<FAssetData> AllBlueprintAssets; static UMCPAssetFinder* Get();
TArray<FAssetData> AllMapAssets;
TArray<FAssetData> AllBlueprintAndMapAssets; // All cached asset lists, keyed by UClass::GetName() (e.g. "Blueprint", "World", "Material").
TArray<FAssetData> AllMaterialAssets; // The special key "BlueprintsAndMaps" combines Blueprint and World assets.
TArray<FAssetData> AllMaterialInstanceAssets; TMap<FName, TArray<FAssetData>> AssetCache;
TArray<FAssetData> AllMaterialFunctionAssets;
TArray<FAssetData> AllStructAssets;
TArray<FAssetData> AllEnumAssets;
// Change detection — set true by asset registry delegates // Change detection — set true by asset registry delegates
bool bDirty = true; bool bDirty = true;