Skip to main content

manage_prefabs

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_prefabs

Description

Manages Unity Prefab assets. Actions: get_info, get_hierarchy, create_from_gameobject, modify_contents, open_prefab_stage, save_prefab_stage, close_prefab_stage. Two approaches to prefab editing: (1) Headless: use modify_contents for automated/scripted edits without opening the prefab in the editor. (2) Interactive: use open_prefab_stage to open a prefab, then manage_gameobject/manage_components to edit objects inside the prefab stage, then save_prefab_stage to save and close_prefab_stage to return to the main scene. Use create_child parameter with modify_contents to add child GameObjects or nested prefab instances to a prefab (single object or array for batch creation in one save). Example: create_child=[{"name": "Child1", "primitive_type": "Sphere", "position": [1,0,0]}, {"name": "Nested", "source_prefab_path": "Assets/Prefabs/Bullet.prefab", "position": [0,2,0]}]. Use delete_child parameter to remove child GameObjects from the prefab (single name/path or array of paths for batch deletion. Example: delete_child=["Child1", "Child2/Grandchild"]). Use component_properties with modify_contents to set serialized fields on existing components (e.g. component_properties={"Rigidbody": {"mass": 5.0}, "MyScript": {"health": 100}}). Supports object references via {"guid": "..."}, {"path": "Assets/..."}, or {"instanceID": 123}. Use manage_asset action=search filterType=Prefab to list prefabs.

Parameters

NameTypeRequiredDescription
actionLiteral['create_from_gameobject', 'get_info', 'get_hierarchy', 'modify_contents', 'open_prefab_stage', 'save_prefab_stage', 'close_prefab_stage']yesPrefab operation to perform.
prefab_pathstr | NonePrefab asset path (e.g., Assets/Prefabs/MyPrefab.prefab).
targetstr | NoneTarget GameObject: scene object for create_from_gameobject, or object within prefab for modify_contents (name or path like 'Parent/Child').
allow_overwritebool | NoneAllow replacing existing prefab.
search_inactivebool | NoneInclude inactive GameObjects in search.
unlink_if_instancebool | NoneUnlink from existing prefab before creating new one.
positionlist[float] | dict[str, float] | str | NoneNew local position [x, y, z] or {x, y, z} for modify_contents.
rotationlist[float] | dict[str, float] | str | NoneNew local rotation (euler angles) [x, y, z] or {x, y, z} for modify_contents.
scalelist[float] | dict[str, float] | str | NoneNew local scale [x, y, z] or {x, y, z} for modify_contents.
namestr | NoneNew name for the target object in modify_contents.
tagstr | NoneNew tag for the target object in modify_contents.
layerstr | NoneNew layer name for the target object in modify_contents.
set_activebool | NoneSet active state of target object in modify_contents.
parentstr | NoneNew parent object name/path within prefab for modify_contents.
components_to_addlist[str] | NoneComponent types to add in modify_contents.
components_to_removelist[str] | NoneComponent types to remove in modify_contents.
create_childdict[str, Any] | list[dict[str, Any]] | NoneCreate 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] | NoneChild 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]] | NoneSet properties on existing components in modify_contents. Keys are component type names, values are dicts of property name to value. Example: {"Rigidbody": {"mass": 5.0}, "MyScript": {"health": 100}}. Supports object references via {"guid": "..."}, {"path": "Assets/..."}, or {"instanceID": 123}. For Sprite sub-assets: {"guid": "...", "spriteName": ""}. Single-sprite textures auto-resolve.

Returns

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

Examples

No examples yet. Add usage examples here — they will be preserved across regenerations.