Skip to main content

prefab_create

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​

Create a prefab asset from an existing GameObject.

Parameters​

NameTypeRequiredDescription
actionLiteral['create_from_gameobject']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.
allow_overwritebool | None—Allow replacing existing prefab.
search_inactivebool | None—Include inactive GameObjects in search.
unlink_if_instancebool | None—Unpack the outermost prefab instance root before creating a new prefab; child targets are rejected. A failed save may leave the scene unpacked.
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.
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 and returned-root targeting examples. Replace the target with a verified scene/stage object ID or unique hierarchy path, and choose a new asset path:

{
"action": "create_from_gameobject",
"target": "Props/Crate",
"prefab_path": "Assets/Prefabs/Crate.prefab",
"allow_overwrite": false,
"unlink_if_instance": false
}

Existing destinations require explicit allow_overwrite: true. For a prefab instance, review the unpack scope before setting unlink_if_instance: true: the target must be its outermost instance root, not a nested child. On failure, inspect the error and scene/destination state before retrying; unpacking can require Undo or manual restoration. Keep rootObjectName/rootObjectPath from the create result for subsequent asset edits; they can differ from the source instance name.