react-three-game
Use this skill when building scenes or tools with react-three-game.
Use it to keep generated code and explanations aligned with the current scene/entity API.
Working Model
Treat react-three-game as an authored scene layer on top of React Three Fiber, not as a separate engine.
- Use plain R3F / Three.js for behavior, controllers, and procedural logic.
- Use
PrefabRootfor rendering authored scene JSON. - Use
PrefabEditorfor authoring UI, transform gizmos, and play/edit mode.
Prefer the lowest layer that solves the request.
Terminology
Use scene/entity language in explanations and generated code.
PrefabEditor: editor shellPrefabRoot: pure rendererScene: imperative scene handle from the editor refEntity: a node handle inside the sceneEntityComponent: handle returned byentity.getComponent(...)
The serialized document type is Prefab, and each node is a GameObject.
Default API Choices
When generating code or suggesting changes, prefer these patterns in order:
entity.getComponent(...).set(path, value)for targeted property editscomponent.update(...)when next state depends on previous component stateentity.update(...)orscene.update(...)for whole-entity changes likedisabled,locked, or multi-component swapsscene.add(node, options?)for authored entity creationeditor.load(...)andeditor.save()for whole-scene replacement and persistence
Prefer scene handles over rebuilding and replacing the whole scene tree.
State Split
Keep editor state and scene state separate.
useEditorContext()is for editor concerns like transform mode, selection, focus, and edit/play state.editor.scene,entity, andentity.getComponent(...)are for scene content changes.
Route scene content edits through scene handles, not editor-context helpers.
Export Surface Guidance
Prefer examples that use the actual root exports.
Common root exports worth suggesting:
GameCanvasPrefabRootPrefabEditorregisterComponentuseEditorContextgroundloadFiles,loadModel,loadTexturesoundManager
Useful type exports:
PrefabEditorRef,PrefabEditorPropsPrefabRootRef,PrefabRootPropsScene,Entity,EntityComponentFieldDefinition,Component
Stay within the current root export surface.
Scene Data Rules
- transforms are local to the parent
disabledis the visibility toggle- component keys are lowercase in JSON
- component
typevalues are TitleCase - use
crypto.randomUUID()for new entity ids - asset paths are relative to
/public
Guidance
- Prefer scene/entity language consistently in both prose and code.
- Keep runtime behavior in normal R3F components when that is clearer than pushing it into scene JSON.
- Reach for
PrefabEditoronly when the request actually needs authoring UI or editor interaction. - Use the current scene-handle APIs instead of whole-scene replacement for targeted mutations.