Skip to main content

manage_gameobject

Auto-generated from the Python tool registry. Do not hand-edit outside <!-- examples:start --><!-- examples:end --> blocks — the generator (tools/generate_docs_reference.py) will overwrite them.

Group: core  ·  Module: services.tools.manage_gameobject

Description

Performs CRUD operations on GameObjects. Actions: create, modify, delete, duplicate, move_relative, look_at. NOT for searching — use the find_gameobjects tool to search by name/tag/layer/component/path. NOT for component management — use the manage_components tool (add/remove/set_property) or mcpforunity://scene/gameobject/{id}/components resource (read).

Parameters

NameTypeRequiredDescription
actionLiteral['create', 'modify', 'delete', 'duplicate', 'move_relative', 'look_at'] | NoneAction to perform on GameObject.
targetstr | NoneGameObject identifier by name, path, or instance ID for modify/delete/duplicate actions
search_methodLiteral['by_id', 'by_name', 'by_path', 'by_tag', 'by_layer', 'by_component'] | NoneHow to resolve 'target'. If omitted, Unity infers: instance ID -> by_id, path (contains '/') -> by_path, otherwise by_name.
namestr | NoneGameObject name for 'create' (initial name) and 'modify' (rename) actions.
tagstr | NoneTag name - used for both 'create' (initial tag) and 'modify' (change tag)
parentstr | NoneParent GameObject reference - used for both 'create' (initial parent) and 'modify' (change parent)
positionlist[float] | dict[str, float] | str | NonePosition as [x, y, z] array, {x, y, z} object, or JSON string
rotationlist[float] | dict[str, float] | str | NoneRotation as [x, y, z] euler angles array, {x, y, z} object, or JSON string
scalelist[float] | dict[str, float] | str | NoneScale as [x, y, z] array, {x, y, z} object, or JSON string
components_to_addlist[str] | str | NoneList of component names to add during 'create' or 'modify'
primitive_typestr | NonePrimitive type for 'create' action
save_as_prefabbool | str | NoneIf True, saves the created GameObject as a prefab (accepts true/false or 'true'/'false')
prefab_pathstr | NonePath for prefab creation
prefab_folderstr | NoneFolder for prefab creation
set_activebool | str | NoneIf True, sets the GameObject active (accepts true/false or 'true'/'false')
layerstr | NoneLayer name
is_staticbool | str | NoneSet the GameObject's static flag. true = all StaticEditorFlags, false = none (accepts true/false or 'true'/'false')
components_to_removelist[str] | str | NoneList of component names to remove
component_propertiesdict[str, dict[str, Any]] | str | NoneDictionary of component names to their properties to set. For example: {"MyScript": {"otherObject": {"find": "Player", "method": "by_name"}}} assigns GameObject {"MyScript": {"playerHealth": {"find": "Player", "component": "HealthComponent"}}} assigns Component Example set nested property: - Access shared material: {"MeshRenderer": {"sharedMaterial.color": [1, 0, 0, 1]}}
new_namestr | NoneNew name for the duplicated object (default: SourceName_Copy)
offsetlist[float] | str | NoneOffset from original/reference position as [x, y, z] array (list or JSON string)
reference_objectstr | NoneReference object for relative movement (required for move_relative)
directionLiteral['left', 'right', 'up', 'down', 'forward', 'back', 'front', 'backward', 'behind'] | NoneDirection for relative movement (e.g., 'right', 'up', 'forward')
distancefloat | NoneDistance to move in the specified direction (default: 1.0)
world_spacebool | str | NoneIf True (default), use world space directions; if False, use reference object's local directions
look_at_targetlist[float] | str | NoneWorld position [x,y,z] or GameObject name/path/ID to look at (for look_at action).
look_at_uplist[float] | str | NoneOptional up vector [x,y,z] for look_at. Defaults to [0,1,0].

Returns

A dict containing the Unity response. The exact shape depends on the action.

Examples

Create a red cube at the world origin

Create a cube called RedCube at (0, 0, 0).

{
"action": "create",
"name": "RedCube",
"primitive_type": "Cube",
"position": [0, 0, 0]
}

Pair with manage_material to make it actually red.

Find a GameObject by name and move it

Move the Player 5 units up.

{
"action": "modify",
"target": "Player",
"search_method": "by_name",
"position": [0, 5, 0]
}

search_method: by_name matches the first GameObject whose name equals Player. Use by_path for Parent/Child/Leaf lookups or by_id for instance IDs.

Parent one GameObject under another

Make Sword a child of Player/RightHand.

{
"action": "modify",
"target": "Sword",
"search_method": "by_name",
"parent": "Player/RightHand"
}

Delete every GameObject tagged Cleanup

Delete all objects tagged Cleanup in the current scene.

{
"action": "delete",
"target": "Cleanup",
"search_method": "by_tag"
}

Multi-instance routing

In the Editor2 instance, duplicate MainCamera.

{
"action": "duplicate",
"target": "MainCamera",
"search_method": "by_name",
"unity_instance": "Editor2"
}

See Multi-Instance Routing for the full routing model.