Derived from the cocosair-scene-graph skill and its canonical docs/source pointers; reorganized on 2026-10-11. Source annotations below identify repository inputs, not files guaranteed to ship to npm consumers.
Contracts
Scene extends Node. A scene is the tree root; callscene.addChild(node).app.run(newScene)anddirector.loadSceneroute throughrunSceneImmediate, which destroys the previous scene; its children are destroyed with it.director.getScene()is the live scene;finddefaults to it. Tables: node-ops.md.- Component lifecycle runs in this fixed order:
__preload->onLoad->onEnable-> (first frame)start->update(dt)->lateUpdate(dt)->onDisable->onDestroy.onLoadruns before anystart;startruns before the firstupdate;dtis in seconds.active=falsestopsupdatescheduling, not just rendering. node-ops.md. node.destroy()is deferred and narrow: it marks the objectToDestroy; the real teardown runs at end of frame in_destroyImmediate->_onPreDestroyBase, whosethis._eventProcessor.destroy()call clears this node's OWN node-event listeners only. The exception is a scene switch:runSceneImmediatecalls the old scene'sdestroy()and thenCCObject._deferredDestroy()within the same call (director.ts:446, :464), so afterapp.run(newScene)the previous scene already readsisValid === false.input.on/Input.EventTypesubscriptions, DOMaddEventListener,director/gameevents and callbacks registered on OTHER nodes are out of scope and must be released explicitly (thescene-switch-reentryexample unsubscribesinput.oninonDisable). node-events.md.addChild(child)returns void; do not chain.setScale(...)and thescalegetter act on LOCAL scale;worldScalemultiplies the parent chain (setting world scale back-solves local).setParent(value, keepWorldTransform = false)keeps the child's local transform by default. node-ops.md.- Layers are a bit mask in
node.layer(defaultLayers.Enum.DEFAULT) tested againstcamera.visibility; a mismatch draws nothing, and the two passes test it differently: the 3D render queue requires containment,(visibility & node.layer) === node.layer(src/cocos/rendering/scene-culling.ts:198), while the 2D path uses the non-zero testvisibility & node.layer(src/cocos/2d/renderer/batcher-2d.ts:265), so an OR-ed multi-bitnode.layermust be wholly inside the 3D mask or the 3D pass culls it. The engine default camera mask (CAMERA_DEFAULT_MASK) already includes DEFAULT and every user bit (0-19), so a default Camera draws DEFAULT-layer and registered-custom-layer nodes without touchingvisibility; only nodes moved to an excluded bit or a replaced mask go unseen. Register custom layers throughLayers.addLayer(name, bit)and build masks withmakeMaskInclude/makeMaskExclude; do not hand-OR reserved bits. Bit numbers and the reserved range: layers.md. - Scene globals (
ambient,fog,skybox,shadows,octree,skin,lightProbeInfo) are writable config objects reached viascene.globals, with a two-phase sync. Before activation edits are staged on the config fields; scene activation (_activate->_globals.activate,scene.ts:204, skipped in TEST) binds them to the render resources ondirector.root.pipeline.pipelineSceneData(membersambient/fog/skybox/shadows/octree/skin/postSettings/lightProbes,pipeline-scene-data.ts:107-115) and pushes the staged values. After activation the member setters write the bound resource directly (each setter guardsif (this._resource)), so post-runedits apply too.scene.renderSceneexposes neither ambient nor fog nor skybox; read effective values fromscene.globalsor the boundpipelineSceneDatamembers. scene-globals.md. - Refcount:
Asset.addRef()increments_ref(asset.ts:316-319);decRef(autoRelease = true)decrements only while_ref > 0(asset.ts:331-334) and, whenautoRelease, queues a release attempt throughreleaseManager.tryRelease(asset.ts:335-336). Nothing frees synchronously: the free runs on the next tick and only while the count is zero or circular references are all that remains (release-manager.ts:224-229, :249-253). A loadedSceneAsset(a thin wrapper holding.scene) follows the same rule.Scene.autoReleaseAssetsdefaults tofalse; on switch away the release manager callsdecRef(TEST || oldScene.autoReleaseAssets)on the old scene's dependencies (release-manager.ts:179, :189), so leaving itfalsekeeps those assets resident until you release them. scene-globals.md. - Capability layers, stated separately (source export / default-bundle reachable / browser-verified): every symbol in this skill's surface resolves by symbol name in the main entry declaration
build/cocosair.module.d.ts(line-level inventory in node-ops.md, Main entry export surface; re-exported throughsrc/exports/base.ts). Node-tree behavior inexamples/node-hierarchyand scene-switch/refcount behavior inexamples/scene-switch-reentrycarry browser evidence indocs/evidence/examples-verified.json, but that file ismeasuredAt2026-10-04 recorded for candidate fingerprint2f089f6ce25eaccd, while the current tree recomputes to8f3e573cebbb315f(candidateFingerprint()intools/verify/api-trace.cjs); cite it as historical until the gate is re-run against the current candidate. A symbol resolving by name does not by itself prove the behavior is browser-verified.