{"record":{"id":"03f07947cc1620a2","repo":"CoplayDev/unity-mcp","slug":"target-gameobject-not-found","errorCode":null,"errorMessage":"Target GameObject not found.","messagePattern":"Target GameObject not found\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"MCPForUnity/Editor/Tools/ProBuilder/ManageProBuilder.cs","lineNumber":280,"sourceCode":"        // =====================================================================\n        // Helpers\n        // =====================================================================\n\n        internal static GameObject FindTarget(JObject @params)\n        {\n            return ObjectResolver.ResolveGameObject(@params[\"target\"], @params[\"searchMethod\"]?.ToString());\n        }\n\n        private static Component GetProBuilderMesh(GameObject go)\n        {\n            return go.GetComponent(_proBuilderMeshType);\n        }\n\n        internal static Component RequireProBuilderMesh(JObject @params)\n        {\n            var go = FindTarget(@params);\n            if (go == null)\n                throw new Exception(\"Target GameObject not found.\");\n            var pbMesh = GetProBuilderMesh(go);\n            if (pbMesh == null)\n                throw new Exception($\"GameObject '{go.name}' does not have a ProBuilderMesh component.\");\n            return pbMesh;\n        }\n\n        internal static void RefreshMesh(Component pbMesh)\n        {\n            // ToMesh and Refresh have optional parameters (MeshTopology, RefreshMask) —\n            // Type.EmptyTypes won't find them. Use name-only lookup with default args.\n            var toMeshMethod = _proBuilderMeshType.GetMethod(\"ToMesh\", Type.EmptyTypes)\n                ?? _proBuilderMeshType.GetMethod(\"ToMesh\", BindingFlags.Instance | BindingFlags.Public);\n            toMeshMethod?.Invoke(pbMesh, toMeshMethod.GetParameters().Length > 0\n                ? new object[toMeshMethod.GetParameters().Length]\n                : null);\n\n            var refreshMethod = _proBuilderMeshType.GetMethod(\"Refresh\", Type.EmptyTypes)\n                ?? _proBuilderMeshType.GetMethod(\"Refresh\", BindingFlags.Instance | BindingFlags.Public);","sourceCodeStart":262,"sourceCodeEnd":298,"githubUrl":"https://github.com/CoplayDev/unity-mcp/blob/c21bf496bca87d54e75bad048563c3adb1782081/MCPForUnity/Editor/Tools/ProBuilder/ManageProBuilder.cs#L262-L298","documentation":"Thrown by RequireProBuilderMesh when FindTarget cannot resolve the target parameter. FindTarget uses ObjectResolver.ResolveGameObject with the 'target' and 'searchMethod' parameters — if the GameObject is not found by the given method (by name, path, or instance ID), it returns null, and this generic Exception is raised.","triggerScenarios":"Calling any ProBuilder tool with a 'target' that doesn't match an existing GameObject. Common causes: the object was deleted between calls, the name has a typo, the searchMethod ('byName', 'byPath', 'byId') doesn't match how the target is specified, or the object is in a different scene.","commonSituations":"Referencing a GameObject from a previous scene that was unloaded; instance ID from a prior Editor session no longer valid; path-based search when the hierarchy changed; object is inactive and the resolver doesn't find inactive objects by name.","solutions":["Verify the GameObject exists in the current scene hierarchy (list_game_objects or read_hierarchy).","Match the searchMethod to the target format: 'byId' for instance IDs, 'byName' for names, 'byPath' for hierarchy paths.","If the object was created in a prior session, re-fetch its current name/ID before calling the ProBuilder tool.","Ensure the object is active in the hierarchy if searching by name."],"exampleFix":"// before\nparams = {\"target\": \"MyCube\", \"searchMethod\": \"byId\"}\n// after\nparams = {\"target\": \"MyCube\", \"searchMethod\": \"byName\"}","handlingStrategy":"validation","validationCode":"# Before calling a ProBuilder tool, verify the target exists\n# Use read_hierarchy or list_game_objects and check the name/id is present\ndef target_exists(hierarchy, target_name):\n    for entry in hierarchy:\n        if entry['name'] == target_name:\n            return True\n    return False","typeGuard":null,"tryCatchPattern":"try\n{\n    var mesh = RequireProBuilderMesh(@params);\n}\ncatch (Exception ex) when (ex.Message == \"Target GameObject not found.\")\n{\n    // Re-resolve target or return a descriptive error to the AI\n    return new ErrorResponse($\"GameObject not found. Verify it exists in the current scene.\");\n}","preventionTips":["Always fetch the current hierarchy before referencing GameObjects by name.","Use the most specific searchMethod (byPath or byId) to avoid ambiguity.","Cache instance IDs from creation calls and reuse them rather than names.","Check object existence after scene loads or unloads."],"tags":["probuilder","gameobject","not-found","resolution","reflection"],"backgroundTag":null,"analyzedSha":"c21bf496bca87d54e75bad048563c3adb1782081","analyzedAt":"2026-08-13T17:36:56.095Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}