Class ManageGameObject
Handles GameObject manipulation within the current scene (CRUD, find, components).
Inherited Members
Namespace: Unity.AI.MCP.Editor.Tools
Assembly: Unity.AI.MCP.Editor.dll
Syntax
public static class ManageGameObject
Fields
Description
Description of the ManageGameObject tool functionality and parameters.
Declaration
public const string Description = "Manages GameObjects: create, modify, delete, find, and component operations.\n\nArgs:\n action: Operation (e.g., 'create', 'modify', 'find', 'add_component', 'remove_component', 'set_component_property', 'get_components', 'get_component').\n target: GameObject identifier (name or path string) for modify/delete/component actions.\n search_method: How to find objects ('by_name', 'by_id', 'by_path', etc.). Used with 'find' and some 'target' lookups.\n name: GameObject name - used for both 'create' (initial name) and 'modify' (rename).\n tag: Tag name - used for both 'create' (initial tag) and 'modify' (change tag).\n parent: Parent GameObject reference - used for both 'create' (initial parent) and 'modify' (change parent).\n layer: Layer name - used for both 'create' (initial layer) and 'modify' (change layer).\n component_properties: Dict mapping Component names to their properties to set.\n Example: {\"Rigidbody\": {\"mass\": 10.0, \"useGravity\": True}},\n To set references:\n - Use asset path string for Prefabs/Materials, e.g., {\"MeshRenderer\": {\"material\": \"Assets/Materials/MyMat.mat\"}}\n - Use a dict for scene objects/components, e.g.:\n {\"MyScript\": {\"otherObject\": {\"find\": \"Player\", \"method\": \"by_name\"}}} (assigns GameObject)\n {\"MyScript\": {\"playerHealth\": {\"find\": \"Player\", \"component\": \"HealthComponent\"}}} (assigns Component)\n Example set nested property:\n - Access shared material: {\"MeshRenderer\": {\"sharedMaterial.color\": [1, 0, 0, 1]}}\n components_to_add: List of component names to add.\n Action-specific arguments (e.g., position, rotation, scale for create/modify;\n component_name for component actions;\n search_term, find_all for 'find').\n include_non_public_serialized: If True, includes private fields marked [SerializeField] in component data.\n\n Action-specific details:\n - For 'get_components':\n Required: target, search_method\n Optional: includeNonPublicSerialized (defaults to True)\n Returns all components on the target GameObject with their serialized data.\n The search_method parameter determines how to find the target ('by_name', 'by_id', 'by_path').\n - For 'get_component', specify 'component_name' to retrieve only that component's serialized data.\n\nReturns:\n Dictionary with operation results ('success', 'message', 'data')."
Field Value
| Type | Description |
|---|---|
| string |
Methods
FindObjectByInstruction(JObject, Type)
Finds a specific UnityEngine.Object based on a find instruction JObject. Primarily used by UnityEngineObjectConverter during deserialization.
Declaration
public static Object FindObjectByInstruction(JObject instruction, Type targetType)
Parameters
| Type | Name | Description |
|---|---|---|
| JObject | instruction | The JObject containing find instructions (find term, method, component). |
| Type | targetType | The type of Unity Object to find. |
Returns
| Type | Description |
|---|---|
| Object | The found UnityEngine.Object or null if not found. |
GetInputSchema()
Returns the input schema for this tool.
Declaration
[McpSchema("Unity.ManageGameObject")]
public static object GetInputSchema()
Returns
| Type | Description |
|---|---|
| object | The JSON schema object describing the tool's input structure. |
HandleCommand(JObject)
Main handler for GameObject management actions.
Declaration
[McpTool("Unity.ManageGameObject", "Manages GameObjects: create, modify, delete, find, and component operations.\n\nArgs:\n action: Operation (e.g., 'create', 'modify', 'find', 'add_component', 'remove_component', 'set_component_property', 'get_components', 'get_component').\n target: GameObject identifier (name or path string) for modify/delete/component actions.\n search_method: How to find objects ('by_name', 'by_id', 'by_path', etc.). Used with 'find' and some 'target' lookups.\n name: GameObject name - used for both 'create' (initial name) and 'modify' (rename).\n tag: Tag name - used for both 'create' (initial tag) and 'modify' (change tag).\n parent: Parent GameObject reference - used for both 'create' (initial parent) and 'modify' (change parent).\n layer: Layer name - used for both 'create' (initial layer) and 'modify' (change layer).\n component_properties: Dict mapping Component names to their properties to set.\n Example: {\"Rigidbody\": {\"mass\": 10.0, \"useGravity\": True}},\n To set references:\n - Use asset path string for Prefabs/Materials, e.g., {\"MeshRenderer\": {\"material\": \"Assets/Materials/MyMat.mat\"}}\n - Use a dict for scene objects/components, e.g.:\n {\"MyScript\": {\"otherObject\": {\"find\": \"Player\", \"method\": \"by_name\"}}} (assigns GameObject)\n {\"MyScript\": {\"playerHealth\": {\"find\": \"Player\", \"component\": \"HealthComponent\"}}} (assigns Component)\n Example set nested property:\n - Access shared material: {\"MeshRenderer\": {\"sharedMaterial.color\": [1, 0, 0, 1]}}\n components_to_add: List of component names to add.\n Action-specific arguments (e.g., position, rotation, scale for create/modify;\n component_name for component actions;\n search_term, find_all for 'find').\n include_non_public_serialized: If True, includes private fields marked [SerializeField] in component data.\n\n Action-specific details:\n - For 'get_components':\n Required: target, search_method\n Optional: includeNonPublicSerialized (defaults to True)\n Returns all components on the target GameObject with their serialized data.\n The search_method parameter determines how to find the target ('by_name', 'by_id', 'by_path').\n - For 'get_component', specify 'component_name' to retrieve only that component's serialized data.\n\nReturns:\n Dictionary with operation results ('success', 'message', 'data').", null, null, Groups = new string[] { "core", "scene" })]
public static object HandleCommand(JObject @params)
Parameters
| Type | Name | Description |
|---|---|---|
| JObject | params | The JObject containing action and parameters for GameObject operations. |
Returns
| Type | Description |
|---|---|
| object | A response object containing success status, message, and optional data. |