cocos-scene-json-component-binding
Use when binding code-driven TypeScript components in Cocos Creator scenes.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Use when binding code-driven TypeScript components in Cocos Creator scenes.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
Use when installing Cocos Creator 3.x and setting up a headless test bootstrap.
Use when setting up a GUI-free CLI build pipeline for Cocos Creator 3.x.
Use when building code-driven scrollable UI panels in Cocos Creator 3.x.
Use when code-driven UI nodes in Cocos Creator 3.x fail to render text or colors.
Use when Cocos Creator 3.x CLI build fails with scene or library errors.
Use when installing Cocos Creator 3.x and debugging scene import errors.
| name | cocos-scene-json-component-binding |
| description | Use when binding code-driven TypeScript components in Cocos Creator scenes. |
正確將 code-driven TypeScript Component 綁定到 Scene JSON 的方法,唔開 Editor 都做到。
Cocos Creator 3.x 嘅 Scene JSON 係一個 array of objects,用 __id__ 做 cross-reference:
[
{ "__id__": 0 }, // SceneAsset (entry point)
{ "__id__": 1 }, // Scene root node
{ "__id__": 2 }, // Child node (e.g. Canvas / Bootstrapper)
{ "__id__": 3 }, // Component on node 2
...
]
"scene": { "__id__": 1 } → points to Scene node"_children": [{ "__id__": 2 }] → lists child nodes"_parent": { "__id__": 1 }, "_components": [{ "__id__": M }]"node": { "__id__": N } → points back to its nodeCheck the .meta file of your TypeScript file:
cat assets/scripts/control/GameBootstrapper.ts.meta
# => { "uuid": "df04b42a-58f5-41c9-9980-bc4605129b94", ... }
In the node's _components array, add:
"_components": [
{ "__id__": 5 }, // existing component (e.g. Canvas)
{ "__id__": 15 } // new component reference — pick unused __id__
]
At the end of the Scene JSON array:
{
"__type__": "df04b42a-58f5-41c9-9980-bc4605129b94.GameBootstrapper",
"_name": "GameBootstrapper",
"_objFlags": 0,
"node": { "__id__": 2 },
"_enabled": true,
"__prefab": null,
"_id": "gameBootstrapper"
}
npm run build
# Then open in DevTools / simulator
Cause: WeChat Mini Game's Cocos engine automatically creates a Canvas during initialization. Adding a Canvas component manually in Scene JSON or via addComponent(Canvas) triggers this error.
Fix:
Canvas node in Scene JSONthis.node.addComponent(Canvas) in codeNode (not Canvas)If the Scene JSON has no component that runs code, the scene loads but nothing executes. Console shows LoadScene ...: 20ms but no app logs.
Fix: Always ensure at least one node in Scene JSON has a Component that runs onLoad()/start().
If you use an __id__ already used by another object, Cocos will either crash or silently fail.
Best practice: Use high numbers (e.g., 15, 20) for manually-added components to avoid collision with auto-generated IDs (usually 0-14 for simple scenes).
If your code dynamically creates a Camera (child of the Bootstrapper node), set z position to 1000:
camNode.setPosition(v3(0, 0, 1000));
Otherwise the camera might be behind or inside the scene geometry.
After binding a component to Scene JSON:
npm run build succeedsonLoad logLoadScene message appears with scene pathcocos-gray-screen-camera-canvas-fix — gray/blue screen debugging flowcocos-creator-scene-less-test-bootstrap — fully code-driven test bootstrapcocos-code-driven-ui-common-pitfalls — UITransform, font, layer issues