cocos_instantiate_prefab
Clone a prefab file into a Cocos Creator scene as a child node, allowing customization of position, scale, and name for the new instance.
Instructions
Drop a .prefab file into the scene as a child node — returns root id.
Reads the .prefab JSON, deep-copies its node tree (root + children +
components), shifts every internal id reference, gives every cloned
object a fresh _id, refreshes each cc.PrefabInfo.fileId so multiple
instances of the same prefab don't alias, and parents the new root
under parent_id.
Treats the prefab as unlinked (a one-shot copy). If you later edit the .prefab, instances already dropped into the scene will NOT update — re-instantiate to pick up the changes.
Pass any of name / pos_x / pos_y / pos_z / scale to override the root's defaults (otherwise the prefab's own values stay).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| scene_path | Yes | ||
| parent_id | Yes | ||
| prefab_path | Yes | ||
| name | No | ||
| pos_x | No | ||
| pos_y | No | ||
| pos_z | No | ||
| scale | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |