Skip to content

prefab-only-construction-cocos

Prefab-Only Construction (Cocos): No Code-Built Nodes / UI / Scene-Wiring

Section titled “Prefab-Only Construction (Cocos): No Code-Built Nodes / UI / Scene-Wiring”

Scope: Cocos runtime & gameplay TypeScript, not editor extensions, reusable factories, or tests (see Carve-outs). Full rationale, tool-mapping table, MCP gotchas: docs/prefab-only-construction-cocos.md.

MUST NOT construct node hierarchies, UI, or wire scene references in code. Everything visual/structural is authored as a prefab (or scene) in the editor; cross-node references are @property-assigned there.

Banned: new Node()+addChild · addComponent(...) chains assembling a hierarchy · procedural UITransform/Widget/Layout/label/sprite trees · code scene-wiring (find/getChildByName/getComponentInChildren locating what should be an editor-assigned @property) · auto-creating a root/container node in code.

The ONE permitted form: instantiate(prefab) (pooled via ObjectPoolManager when spawned/recycled repeatedly, per code-quality-cocos.md), then configure()/bind() sets data on already-serialized @property refs; MUST NOT create children.

MUST author every prefab/scene change via the Cocos Creator MCP tools (manage_node, manage_prefab, manage_component, manage_scene, manage_asset); a one-off script is not authoring. Load t1k-cocos-playable-editor-tools + t1k-cocos-playable-tooling-gotchas first.

Carve-outs: editor extension tooling · a reusable, tested factory used from ≥3 sites · pure-logic non-visual TS · unit tests · one documented one-off bootstrap node at boot.

code-quality-cocos.md (pooling) · t1k-cocos-base-asset-import skills/t1k-cocos-base-asset-import/references/asset-slot-handoff.md (UUID identity) — no Unity-engine sibling rule is published today; this rule stands alone for the Unity kit.