cocos_add_and_attach_script
Create a TypeScript script file and attach it as a component to a scene node in one operation, eliminating UUID handling errors and simplifying Cocos Creator workflow.
Instructions
Write a TS script file + attach it as a component in ONE call.
Replaces the 3-call sequence agents ran dozens of times per session::
r = cocos_add_script(project, "Bird", source) # file + meta
short = cocos_compress_uuid(r["uuid"]) # UUID form
cid = cocos_add_script(scene, node_id, short, props) # attachThe two same-named cocos_add_script tools (the project-
level writer vs. the scene-level attacher) were the main
friction — agents accidentally passed the standard UUID to
the attacher, or skipped the compress step entirely and got
a silently-broken component.
Arguments:
project_path/rel_path/source— where the .ts lives.rel_pathfollowscocos_add_script's prefix rules (bare name →assets/scripts/<name>.ts).scene_path/node_id— target scene (or .prefab) and the node's array index.props— component @property values, forwarded verbatim. Use{"__id__": N}for node/component refs,{"__uuid__": "..."}for asset refs.uuid— optional override for the .ts.meta UUID. Omit to let the underlyingadd_scriptpreserve an existing UUID on overwrite (idempotent mode) or mint a fresh one on first write.
Returns::
{
"script_path": "/abs/path/Foo.ts",
"rel_path": "assets/scripts/Foo.ts",
"uuid_standard": "5372d6f5-...", # 36-char form
"uuid_compressed":"5372db1cH...", # what scenes use
"component_id": <int>, # attached comp's id
"created": <bool>, # False if meta preserved
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_path | Yes | ||
| rel_path | Yes | ||
| source | Yes | ||
| scene_path | Yes | ||
| node_id | Yes | ||
| props | No | ||
| uuid | No |