Skip to main content

manage_components

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_components

Maturity: stable (support status; independent of enabled state, readiness and permissions).

Description​

Add, remove, or set properties on components attached to GameObjects. Actions: add, remove, set_property. Requires target (instance ID or name) and component_type. For READING component data, use the mcpforunity://scene/gameobject/{id}/components resource or mcpforunity://scene/gameobject/{id}/component/{name} for a single component. Set strict_selection=true to require a unique target and component, or select a component_instance_id. Name/path uniqueness includes inactive objects in the active scene/current prefab stage; IDs can address other loaded scenes. These opt-in requests require a compatible Editor package and never fall back to first match. Property writes use ordered best_effort results (applied/failed); earlier successes are retained and later properties are attempted. Results preserve request index and property name. For opt-in preview/expected_old/Undo compensation on supported native properties use manage_scene_edits. Arbitrary component callbacks cannot be made atomic. For creating/deleting GameObjects themselves, use gameobject_create/gameobject_edit instead.

Parameters​

NameTypeRequiredDescription
actionLiteral['add', 'remove', 'set_property']yesAction to perform: add (add component), remove (remove component), set_property (set component property)
targetstr | intyesTarget GameObject - instance ID (preferred) or name/path
component_typestryesComponent type name (e.g., 'Rigidbody', 'BoxCollider', 'MyScript')
search_methodLiteral['by_id', 'by_name', 'by_path'] | None—How to find the target GameObject
propertystr | None—Property name to set (for set_property action)
valuestr | int | float | bool | dict[Any] | list[Any] | None—Value to set (required with property for set_property). Null clears an object reference. For object references: instance ID (int), asset path (string), or {"guid": "..."} / {"path": "..."}. Arrays and lists also accept integer IDs or {"instanceID": 123} elements, with null to clear an element. For Sprite sub-assets: {"guid": "...", "spriteName": ""} or {"guid": "...", "fileID": }. Single-sprite textures auto-resolve.
propertiesdict[str, Any] | str | None—Dictionary of property names to values. Example: {"mass": 5.0, "useGravity": false}
component_indexint | None—Zero-based index within GetComponents(requested type), including derived types; not the mixed components-resource list index. Legacy omission selects the first instance. strict_selection=true instead requires uniqueness.
strict_selectionbool—Require one GameObject and, for remove/set_property, one component unless an index or component ID selects it. Default preserves legacy first match.
component_instance_idint | None—Nonzero live component instanceID from the components resource. Requires the selected target and type to match; cannot be combined with component_index or add.
unity_instancestr | int | None—Target Unity instance for this call: Name@hash or hash prefix; an integer selects only that exact port over stdio and is rejected over HTTP. Read mcpforunity://instances for available targets. Omit to use the legacy active selection or the sole available instance.

Returns​

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

Examples​

Add a BoxCollider to a uniquely named marker in a test scene. Use a marker without a collider and enable strict selection so an ambiguous target is rejected.

MCP arguments
{
"action": "add",
"target": "Prototype Marker",
"component_type": "BoxCollider",
"search_method": "by_name",
"strict_selection": true
}