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
| Name | Type | Required | Description |
|---|---|---|---|
action | Literal['add', 'remove', 'set_property'] | yes | Action to perform: add (add component), remove (remove component), set_property (set component property) |
target | str | int | yes | Target GameObject - instance ID (preferred) or name/path |
component_type | str | yes | Component type name (e.g., 'Rigidbody', 'BoxCollider', 'MyScript') |
search_method | Literal['by_id', 'by_name', 'by_path'] | None | — | How to find the target GameObject |
property | str | None | — | Property name to set (for set_property action) |
value | str | 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": " |
properties | dict[str, Any] | str | None | — | Dictionary of property names to values. Example: {"mass": 5.0, "useGravity": false} |
component_index | int | 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_selection | bool | — | 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_id | int | 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_instance | str | 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.
{
"action": "add",
"target": "Prototype Marker",
"component_type": "BoxCollider",
"search_method": "by_name",
"strict_selection": true
}