Skip to main content
Glama

cocos_save_subtree_as_prefab

Convert a configured scene subtree into a reusable prefab asset for efficient game object duplication in Cocos Creator.

Instructions

Extract a fully-configured scene subtree into a reusable .prefab.

The usual case: build your "Enemy" in a scratch scene with Sprite + RigidBody2D + Collider + Animation + script all wired, then save-as-prefab to spawn dozens. Without this, every copy requires re-running the same add_* stack against a new node.

Self-contained rule: every cc.Node referenced from inside the subtree (script field pointing at another Node, Button target, etc.) must already BE inside the subtree. External cc.Node refs raise with a message naming the offender — Cocos's prefab format has no way to express late-bound cross-scene refs, so silent clipping would produce a broken prefab. Asset UUID refs ({__uuid__: ...} for SpriteFrames, clips, meshes, other prefabs) survive unchanged; those travel through the asset DB.

Effects on scene_path: NONE (read-only). If you want the scene to now use an instance instead of the raw subtree: delete the source node, then cocos_instantiate_prefab the fresh prefab. That's a deliberately-explicit two-step so you don't lose the raw subtree on a misfired single call.

Returns {prefab_path, prefab_uuid, root_node_id (=1), object_count, source_root_name}.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
scene_pathYes
root_node_idYes
prefab_pathYes
prefab_uuidNo
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Since no annotations are provided, the description carries the full burden of behavioral disclosure. It thoroughly explains key behaviors: the self-contained rule for node references (with error handling), how asset UUID refs are handled, that the operation is read-only on the scene ('Effects on ``scene_path``: NONE (read-only)'), and the explicit two-step process for replacing the subtree. It also details the return values, compensating for the lack of output schema.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured and front-loaded with the core purpose. Each sentence adds value: it explains the use case, technical constraints, effects on the scene, workflow guidance, and return values. There is no wasted text, and the information is organized logically from general to specific.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of the operation (prefab creation with technical constraints), no annotations, 0% schema coverage, and no output schema, the description provides complete context. It covers purpose, usage, behavioral details, parameter implications, and return values, making it fully self-sufficient for an agent to understand and invoke the tool correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage for 4 parameters, the description must compensate, which it does effectively. It explains the purpose of 'scene_path' and 'root_node_id' implicitly through context, and clarifies that 'prefab_uuid' can be null (default). The description adds significant meaning beyond the bare schema, making parameter roles clear in the context of the operation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Extract a fully-configured scene subtree into a reusable .prefab.' It provides a specific verb ('extract'), resource ('scene subtree'), and output format ('.prefab'), and distinguishes itself from sibling tools by focusing on prefab creation rather than component addition or scene manipulation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly states when to use this tool ('The usual case: build your "Enemy" in a scratch scene... then save-as-prefab to spawn dozens') and when not to use it ('Without this, every copy requires re-running the same ``add_*`` stack'). It also names an alternative tool ('cocos_instantiate_prefab') for the next step after creation, providing clear guidance on workflow.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/chenShengBiao/cocos-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server