Skip to main content

prefab_contents

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: prefabs  ·  Module: services.registry.capability_adapter

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

Description​

Edit prefab contents, inspect whole-prefab or selected-component changes without saving with modify_contents preview_only and preview_scope, or preview and apply a guarded transform change. Action inputs: modify_contents: requires prefab_path; excludes non-null preview_id. preview_modify_contents: requires prefab_path; excludes non-null target, name, tag, layer, parent, components_to_add, components_to_remove, create_child, delete_child, component_properties, preview_only, preview_scope, preview_id. apply_preview: requires preview_id; excludes non-null prefab_path, target, position, rotation, scale, name, tag, layer, set_active, parent, components_to_add, components_to_remove, create_child, delete_child, component_properties, preview_only, preview_scope.

Parameters​

NameTypeRequiredDescription
actionLiteral['modify_contents', 'preview_modify_contents', 'apply_preview']yesFeature action to perform.
prefab_pathstr | None—Prefab asset path (e.g., Assets/Prefabs/MyPrefab.prefab). For save/close, when supplied it must match the current Prefab Stage.
targetstr | int | None—For create_from_gameobject: instance ID (integer or numeric string), unique name, or full hierarchy path (e.g. 'Parent/Child' or '/Parent/Child') in the active scene/current prefab stage. Stage names/paths take precedence. Numeric targets are IDs; ambiguous names/paths fail. For modify_contents: saved prefab object name or child path; omit to target the root. Use returned rootObjectName/rootObjectPath, which may differ from the source instance name. IDs do not apply to isolated prefab contents.
positionlist[float] | dict[str, float] | str | None—New local position [x, y, z] or {x, y, z} for modify_contents.
rotationlist[float] | dict[str, float] | str | None—New local rotation (euler angles) [x, y, z] or {x, y, z} for modify_contents.
scalelist[float] | dict[str, float] | str | None—New local scale [x, y, z] or {x, y, z} for modify_contents.
namestr | None—Source name for create_from_gameobject when target is omitted. In modify_contents, renames a child. The root uses the prefab asset filename.
tagstr | None—New tag for the target object in modify_contents.
layerstr | None—New layer name for the target object in modify_contents.
set_activebool | None—Set active state of target object in modify_contents.
parentstr | None—New parent object name/path within prefab for modify_contents.
components_to_addlist[str] | None—Component types to add in modify_contents.
components_to_removelist[str] | None—Remove original target components by unique type or zero-based Type[index], e.g. BoxCollider[1].
create_childdict[str, Any] | list[dict[str, Any]] | None—Create child GameObject(s) in the prefab. Single object or array of objects, each with: name (required), parent (optional, defaults to target), source_prefab_path (optional: asset path to instantiate as nested prefab, e.g. 'Assets/Prefabs/Bullet.prefab'), primitive_type (optional: Cube, Sphere, Capsule, Cylinder, Plane, Quad), position, rotation, scale, components_to_add, tag, layer, set_active. source_prefab_path and primitive_type are mutually exclusive.
delete_childstr | list[str] | None—Child name(s) or path(s) to remove from the prefab. Supports single string or array for batch deletion (e.g. 'Child1' or ['Child1', 'Child1/Grandchild']).
component_propertiesdict[str, dict[str, Any]] | None—Map a unique component type or zero-based Type[index] to properties. Indices count matching components after requested additions and removals. Example: {"Rigidbody": {"mass": 5.0}, "BoxCollider[1]": {"isTrigger": true}}. Supports object references via {"guid": "..."}, {"path": "Assets/..."}, or {"instanceID": 123}. For Sprite sub-assets: {"guid": "...", "spriteName": ""}. Single-sprite textures auto-resolve.
preview_idstr | None—One-attempt token from preview_modify_contents, valid 10 minutes.
preview_onlybool | None—modify_contents only: inspect changes without saving; includes load/edit side effects, not save callbacks. No apply token; inspect complete/truncated coverage in data.preview.
preview_scopeLiteral['prefab', 'components'] | None—Requires preview_only=true. Default prefab observes the whole prefab. components observes only components named by component_properties on the selected target and accepts only component-property edits. Inspect data.preview.scope, complete and whole_prefab_complete.
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​

See the scene and prefab editing guide for guarded previews and the broader modify_contents inspection path. Choose a verified existing prefab without nested instances or custom components:

{
"action": "preview_modify_contents",
"prefab_path": "Assets/Prefabs/Crate.prefab",
"scale": [1.25, 1.25, 1.25]
}

Review the returned impact, then replace REPLACE_WITH_RETURNED_PREVIEW_ID with the returned token. Apply accepts the token without the original path or edit fields:

{
"action": "apply_preview",
"preview_id": "REPLACE_WITH_RETURNED_PREVIEW_ID"
}

The token permits one attempt within ten minutes. Source/dependency drift requires a new preview. Asset saves do not promise Undo or callback rollback. In contrast, modify_contents with preview_only: true inspects broader changes without saving and returns no apply token; review unsupported fields and truncation explicitly.