More work on MCP handlers. Changed the Validation handler.
This commit is contained in:
@@ -59,6 +59,7 @@ UMCPAssetFinder* UMCPAssetFinder::GetUpdatedAssets()
|
||||
|
||||
Self->AllBlueprintAssets.Empty();
|
||||
Self->AllMapAssets.Empty();
|
||||
Self->AllBlueprintAndMapAssets.Empty();
|
||||
Self->AllMaterialAssets.Empty();
|
||||
Self->AllMaterialInstanceAssets.Empty();
|
||||
Self->AllMaterialFunctionAssets.Empty();
|
||||
@@ -69,6 +70,9 @@ UMCPAssetFinder* UMCPAssetFinder::GetUpdatedAssets()
|
||||
AR.GetAssetsByClass(UMaterialInstanceConstant::StaticClass()->GetClassPathName(), Self->AllMaterialInstanceAssets, false);
|
||||
AR.GetAssetsByClass(UMaterialFunction::StaticClass()->GetClassPathName(), Self->AllMaterialFunctionAssets, false);
|
||||
|
||||
Self->AllBlueprintAndMapAssets = Self->AllBlueprintAssets;
|
||||
Self->AllBlueprintAndMapAssets.Append(Self->AllMapAssets);
|
||||
|
||||
Self->bDirty = false;
|
||||
|
||||
UE_LOG(LogTemp, Display, TEXT("MCPAssetFinder: Refreshed — BP %d, Map %d, Mat %d, MI %d, MF %d"),
|
||||
@@ -88,6 +92,12 @@ const TArray<FAssetData>& UMCPAssetFinder::GetBlueprintAssets()
|
||||
return Self ? Self->AllBlueprintAssets : EmptyAssetArray;
|
||||
}
|
||||
|
||||
const TArray<FAssetData>& UMCPAssetFinder::GetBlueprintAndMapAssets()
|
||||
{
|
||||
UMCPAssetFinder* Self = GetUpdatedAssets();
|
||||
return Self ? Self->AllBlueprintAndMapAssets : EmptyAssetArray;
|
||||
}
|
||||
|
||||
const TArray<FAssetData>& UMCPAssetFinder::GetMapAssets()
|
||||
{
|
||||
UMCPAssetFinder* Self = GetUpdatedAssets();
|
||||
@@ -144,11 +154,34 @@ namespace
|
||||
}
|
||||
return Found;
|
||||
}
|
||||
|
||||
TArray<FAssetData*> SearchInList(const TArray<FAssetData>& List, const FString& Filter)
|
||||
{
|
||||
TArray<FAssetData*> Results;
|
||||
for (const FAssetData& Asset : List)
|
||||
{
|
||||
FString AssetName = Asset.AssetName.ToString();
|
||||
FString PackagePath = Asset.PackageName.ToString();
|
||||
if (AssetName.Contains(Filter, ESearchCase::IgnoreCase) ||
|
||||
PackagePath.Contains(Filter, ESearchCase::IgnoreCase))
|
||||
{
|
||||
Results.Add(const_cast<FAssetData*>(&Asset));
|
||||
}
|
||||
}
|
||||
return Results;
|
||||
}
|
||||
}
|
||||
|
||||
FAssetData* UMCPAssetFinder::FindBlueprintAsset(const FString& NameOrPath, FString* OutError)
|
||||
FAssetData* UMCPAssetFinder::FindBlueprintAsset(const FString& NameOrPath, FString* OutError, bool bIncludeLevelBlueprints)
|
||||
{
|
||||
return FindInList(GetBlueprintAssets(), NameOrPath, OutError);
|
||||
const TArray<FAssetData>& List = bIncludeLevelBlueprints ? GetBlueprintAndMapAssets() : GetBlueprintAssets();
|
||||
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)
|
||||
@@ -184,38 +217,37 @@ FAssetData* UMCPAssetFinder::FindAnyAsset(const FString& NameOrPath, FString* Ou
|
||||
// Load helpers
|
||||
// ============================================================
|
||||
|
||||
UBlueprint* UMCPAssetFinder::LoadBlueprintByName(const FString& NameOrPath, FString& OutError)
|
||||
UBlueprint* UMCPAssetFinder::LoadBlueprintByName(const FString& NameOrPath, FString& OutError, bool bIncludeLevelBlueprints)
|
||||
{
|
||||
// Strategy 1: Try as a regular Blueprint asset
|
||||
FAssetData* Asset = FindBlueprintAsset(NameOrPath, &OutError);
|
||||
if (Asset)
|
||||
FAssetData* Asset = FindBlueprintAsset(NameOrPath, &OutError, bIncludeLevelBlueprints);
|
||||
if (!Asset)
|
||||
{
|
||||
UBlueprint* BP = Cast<UBlueprint>(Asset->GetAsset());
|
||||
if (BP) return BP;
|
||||
}
|
||||
if (!OutError.IsEmpty()) return nullptr;
|
||||
|
||||
// Strategy 2: Try as a level blueprint (from a .umap)
|
||||
FAssetData* MapAsset = FindMapAsset(NameOrPath, &OutError);
|
||||
if (MapAsset)
|
||||
{
|
||||
UWorld* World = Cast<UWorld>(MapAsset->GetAsset());
|
||||
if (World && World->PersistentLevel)
|
||||
if (OutError.IsEmpty())
|
||||
{
|
||||
ULevelScriptBlueprint* LevelBP = World->PersistentLevel->GetLevelScriptBlueprint(true);
|
||||
if (LevelBP)
|
||||
{
|
||||
UE_LOG(LogTemp, Display, TEXT("MCPAssetFinder: Loaded level blueprint from map '%s'"),
|
||||
*NameOrPath);
|
||||
return LevelBP;
|
||||
}
|
||||
OutError = FString::Printf(TEXT("Blueprint '%s' not found. Use list_blueprints to see available assets."), *NameOrPath);
|
||||
}
|
||||
OutError = FString::Printf(TEXT("Map '%s' loaded but its level blueprint could not be retrieved. The map may not contain a level blueprint."), *NameOrPath);
|
||||
return nullptr;
|
||||
}
|
||||
if (!OutError.IsEmpty()) return nullptr;
|
||||
|
||||
OutError = FString::Printf(TEXT("Blueprint or map '%s' not found. Use list_blueprints to see available assets. Level blueprints are referenced by their map name (e.g. 'MAP_Ward')."), *NameOrPath);
|
||||
// Regular blueprint asset
|
||||
UBlueprint* BP = Cast<UBlueprint>(Asset->GetAsset());
|
||||
if (BP)
|
||||
{
|
||||
return BP;
|
||||
}
|
||||
|
||||
// Map asset — extract the level blueprint
|
||||
UWorld* World = Cast<UWorld>(Asset->GetAsset());
|
||||
if (World && World->PersistentLevel)
|
||||
{
|
||||
ULevelScriptBlueprint* LevelBP = World->PersistentLevel->GetLevelScriptBlueprint(true);
|
||||
if (LevelBP)
|
||||
{
|
||||
return LevelBP;
|
||||
}
|
||||
}
|
||||
|
||||
OutError = FString::Printf(TEXT("Asset '%s' loaded but its level blueprint could not be retrieved."), *NameOrPath);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user