CoplayDev/unity-mcp · error · Exception
Target GameObject not found.
Error message
Target GameObject not found.
What it means
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.
Source
Thrown at MCPForUnity/Editor/Tools/ProBuilder/ManageProBuilder.cs:280
// =====================================================================
// Helpers
// =====================================================================
internal static GameObject FindTarget(JObject @params)
{
return ObjectResolver.ResolveGameObject(@params["target"], @params["searchMethod"]?.ToString());
}
private static Component GetProBuilderMesh(GameObject go)
{
return go.GetComponent(_proBuilderMeshType);
}
internal static Component RequireProBuilderMesh(JObject @params)
{
var go = FindTarget(@params);
if (go == null)
throw new Exception("Target GameObject not found.");
var pbMesh = GetProBuilderMesh(go);
if (pbMesh == null)
throw new Exception($"GameObject '{go.name}' does not have a ProBuilderMesh component.");
return pbMesh;
}
internal static void RefreshMesh(Component pbMesh)
{
// ToMesh and Refresh have optional parameters (MeshTopology, RefreshMask) —
// Type.EmptyTypes won't find them. Use name-only lookup with default args.
var toMeshMethod = _proBuilderMeshType.GetMethod("ToMesh", Type.EmptyTypes)
?? _proBuilderMeshType.GetMethod("ToMesh", BindingFlags.Instance | BindingFlags.Public);
toMeshMethod?.Invoke(pbMesh, toMeshMethod.GetParameters().Length > 0
? new object[toMeshMethod.GetParameters().Length]
: null);
var refreshMethod = _proBuilderMeshType.GetMethod("Refresh", Type.EmptyTypes)
?? _proBuilderMeshType.GetMethod("Refresh", BindingFlags.Instance | BindingFlags.Public);View on GitHub (pinned to c21bf496bc)
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.
Example fix
// before
params = {"target": "MyCube", "searchMethod": "byId"}
// after
params = {"target": "MyCube", "searchMethod": "byName"} Defensive patterns
Strategy: validation
Validate before calling
# Before calling a ProBuilder tool, verify the target exists
# Use read_hierarchy or list_game_objects and check the name/id is present
def target_exists(hierarchy, target_name):
for entry in hierarchy:
if entry['name'] == target_name:
return True
return False Try / catch
try
{
var mesh = RequireProBuilderMesh(@params);
}
catch (Exception ex) when (ex.Message == "Target GameObject not found.")
{
// Re-resolve target or return a descriptive error to the AI
return new ErrorResponse($"GameObject not found. Verify it exists in the current scene.");
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- GameObject '{go.name}' does not have a ProBuilderMesh compon
- Could not read faces from ProBuilderMesh.
- Unity instance '{identifier}' not found. Available instances
- Failed to resolve Scene view host view.
- {hostView.GetType().FullName}.GrabPixels(RenderTexture, Rect
AI-assisted analysis of CoplayDev/unity-mcp@c21bf496bc (2026-08-13).
Data as JSON: /api/errors/03f07947cc1620a2.
Report an issue: GitHub.