diff --git a/Plugins/BlueprintMCP/Source/BlueprintMCP/Private/MCPFetcher.cpp b/Plugins/BlueprintMCP/Source/BlueprintMCP/Private/MCPFetcher.cpp index 94632123..2c8ef47d 100644 --- a/Plugins/BlueprintMCP/Source/BlueprintMCP/Private/MCPFetcher.cpp +++ b/Plugins/BlueprintMCP/Source/BlueprintMCP/Private/MCPFetcher.cpp @@ -39,12 +39,26 @@ void MCPFetcher::PrintDocs() } -void MCPFetcher::SetObj(UObject* InObj) { UMCPServer::AddTouchedObject(InObj); Obj = InObj; ResultPin = nullptr; } -void MCPFetcher::SetPin(UEdGraphPin* InPin) { ResultPin = InPin; Obj = nullptr; } +void MCPFetcher::SetObj(UObject* InObj) +{ + UMCPServer::AddTouchedObject(InObj); + Obj = InObj; + ResultPin = nullptr; +} + +void MCPFetcher::SetPin(UEdGraphPin* InPin) +{ + ResultPin = InPin; + Obj = nullptr; +} MCPFetcher& MCPFetcher::SetError() { bError = true; + Obj = nullptr; + ResultPin = nullptr; + OriginalAsset = nullptr; + Editor = nullptr; return *this; } @@ -60,8 +74,6 @@ MCPFetcher& MCPFetcher::TypeMismatch(const TCHAR* Walker, const TCHAR* Expected) return *this; } - - MCPFetcher& MCPFetcher::Walk(const FString& Path) { if (bError) return *this; @@ -102,6 +114,8 @@ MCPFetcher& MCPFetcher::Walk(const FString& Path) MCPFetcher& MCPFetcher::Asset(const FString& PackagePath) { + if (bError) return *this; + SetObj(LoadObject(nullptr, *PackagePath)); if (!Obj) { @@ -118,7 +132,6 @@ MCPFetcher& MCPFetcher::Asset(const FString& PackagePath) UMCPServer::Printf(TEXT("ERROR: Could not open editor for '%s'\n"), *PackagePath); return SetError(); } - Editor = Sub->FindEditorForAsset(OriginalAsset, false); if (!Editor) { diff --git a/Plugins/BlueprintMCP/Source/BlueprintMCP/Public/MCPFetcher.h b/Plugins/BlueprintMCP/Source/BlueprintMCP/Public/MCPFetcher.h index c02d2482..79538eec 100644 --- a/Plugins/BlueprintMCP/Source/BlueprintMCP/Public/MCPFetcher.h +++ b/Plugins/BlueprintMCP/Source/BlueprintMCP/Public/MCPFetcher.h @@ -30,8 +30,8 @@ struct FWalker; // If any step fails, the MCPFetcher will print an error // message that can be seen by the MCP's caller. It will // also set an error flag. Once the error flag is set, all -// further ops become no-ops. At that point, attempting a -// Cast will return nullptr. +// further ops become no-ops. After that point, fetching +// any data will return nullptr. // class MCPFetcher @@ -62,7 +62,7 @@ public: // MCPFetcher& ToBlueprint(); MCPFetcher& ToGraph(); - + // Return true if there haven't been any errors. // Note that errors always automatically generate // output to MCPServer::Printf. @@ -92,6 +92,11 @@ public: // loaded, returns nullptr. Does not generate errors. // UObject* GetAsset() const { return OriginalAsset; } + + // Get the asset from where it all began: the first + // step in the walk path, as a specified type. Errors + // if it cannot cast to the specified type. + // template T* CastAsset() { if (!CheckAssetIsA(T::StaticClass())) return nullptr;