Scenes and levels

Usage guide of game.engine scenes: scene kinds and roles, next scene and backgrounds, the sceneFlow config (title as a scene, loading, unload, failures), stacked and kept scenes, archetypes and scripts with their verbs, the hooks engine.scene.change, engine.scene.release and engine.scene.failed, events, save, engines.

Source: module-kits:kits/game_engine/usage/scenes/en.mdView Markdown source

Also read offline — CLI: grip-forge docs scenesMCP tool: gripforge_docs { "topic": "scenes" }

Scenes, levels and content (game.engine) #

With game.engine.flow.title: "off", the start scene enters play directly, even when ui.menu.titleScreen is true and titleMode is scene. No hidden title holds the scene paused; the pause menu still works.

How a game is organised into scenes (title, levels, loading, cinematics, credits), how one follows another, how files are loaded and freed, and the content files (archetypes, scenes, scripts) a game grows by. Readable offline: gripforge docs scenes, or the MCP tool gripforge_docs (topic scenes).

What it is for #

game.engine is the first kit of every game. It does not rewrite the runtime: the loop, the bus, variables, entities, zones, triggers, objectives, spawn and save already run in the player. It names that base and adds three layers a game grows by without engine code: archetypes (entity templates), scenes (places and screens) and scripts (rules compiled to triggers).

It is transparent without content: no archetype, scene, script or start scene means no entity, rule, variable, event or save section, and the game plays as it always did. It is installed first in every new game and is a normal dependency of the kits that claim its vocabulary; removing it needs with_dependents and confirm.

ContentCollectionRead by
archetype (gripforge.archetype/1)archetypesthe engine and the kits that claim its components
scene (gripforge.scene/1)scenesthe engine, the world kit of the scene, layer kits
script (gripforge.script/1)scriptsthe engine, compiled to trigger rules
quest, dialogue, NPC, itemmissions, dialogues, npcs, itemstheir own kits

Scenes #

A scene names its world ({ kit, config?, doc? }), its entries, its instances ({ id, archetype, at, yaw?, place?, set? }), zones, per-scene data, layers, audio and ui. A game without any scene uses the implicit scene main: kits read their global collections.

A scene has:

FieldValuesMeaning
kind3d (default), 2d, interface, loading, cinematicinterface has no world: a title, a main menu, credits (nothing 3D is drawn); loading is a loading scene
rolemenu, level, creditsits part in the game
nexta scene idwhat follows (Play from the menu, the end of a level, the verb next_scene); default: the next level
background{ image }, { video }, { color }the backdrop of an interface scene
transitionreplace, addhow load_scene and next_scene bring it in
loadingoverlay, none, background, a scene idhow it waits for its files
nativean engine sceneon Unity, Unreal and Godot, the engine's own scene, loaded by the engine's scene adapter
{ "id": "title", "kind": "interface", "role": "menu", "next": "level_1", "background": { "video": "media/title.webm" } }
{ "id": "level_1", "role": "level", "world": { "kit": "world.racetrack", "doc": "oval" }, "next": "level_2" }

A scene's world hands its config to the world kit (for example world.terrain), over the kit's own config. Kits that build or dress a scene implement sceneEnter and sceneExit; their data lives in the scene's data (for example minion_routes).

Tools #

gripforge game-scenes <gkp_id> <action> (MCP gripforge_game_scenes) lists, plans, creates, orders and links scenes, edits the flow and the menu, and lists and checks the assets of each scene (gripforge game-scenes help).

The scene flow (sceneFlow config) #

Set with gripforge_gamekit_configure { id: "game.engine", config: { "sceneFlow": { … } } }.

KeyDefaultMeaning
menuoverlay (scene in every new game)scene: the title of ui.menu is a scene of its own, entered first with no world behind it (the project's role: menu scene, else one synthesised); Play leads to the start scene. overlay: the title is drawn over the start scene
menuScenethe menu scene when several interface scenes exist
loadingoverlayhow a scene waits for its files: ui.menu's loading screen, scene (the loading scene), none, background (the scene left stays until the next is ready)
loadingScenefirst loading scenescene shown between two scenes when loading is scene
loadTimeout30seconds a scene waits for its files before it is entered anyway
minLoadingMs0shortest time a loading screen stays
showAfterMs250a loading screen appears only if the files are still not in after this delay (preloaded files: no flash)
unloadreleaserelease: leaving a scene frees its instances and the memory of the files only it used (never the disk cache, never a preload asked elsewhere); keep
transitionreplacereplace or add (stacked) when neither the scene nor the call says
onFailretrya file of the next scene failed: retry, enter (without it) or wait (until engine.scenes.retry() or cancelLoading())
retries2how many times retry asks again
loadingScreenthe dressing of the loading screen: image, title, tips

A scene loads its files before it is entered (asset.preload); the asset list of each scene (scene_assets) is generated from its content, can be edited, and is one more source for asset.preload. Progress is the real progress of the preload, never a simulated bar.

Several scenes at once #

A change may keep the scene left: engine.scenes.enter(scene, entry, { unload: false }) or load_scene { scene, unload: false }. The scene left is hidden and paused by default and resumes at once when the game comes back. A scene can be stacked on others: push_scene { scene, below: "run" | "pause" | "hide" } (an inventory over a frozen level), pop_scene. Every loaded scene is visible or hidden, running or paused at any moment: set_scene { scene, visible, paused }. This is saved with the game. Nothing a loaded scene uses is freed.

The game behind the title (1.9) #

When ui.menu shows the game itself behind its title (titleMode: "scene", its default from ui.menu 1.10.0), the start scene is staged at launch: entered at its start entry and built by its kits (engine.scene.entered with staged: true), the game time held from the first tick (no kit tick, physics, zone, input or intro) and its scripts not armed. A role: menu scene comes over it, the staged scene staying drawn under it; its background.scene names another scene to stage. Play hands the staged scene over where it stands: the menu scene goes, the scripts are armed, the time runs and engine.scene.entered fires again without staged (no rebuild, no respawn), then the intro plays. A chapter, Continue or Load leaves it for the scene asked. Nothing is staged for another titleMode, a scene without a world or an online world (net.zones, save.online): the title keeps its artwork. A listener that starts gameplay on engine.scene.entered skips staged.

Scripts and verbs #

A script compiles, in pure TypeScript shared by the server and the web runtime, to ordinary trigger rules that the player runs.

{ "id": "s_cellar_door", "on": "door_cellar",
  "rules": [ { "when": { "interact": "self" }, "if": [ { "has_item": "cellar_key" } ],
               "then": [ { "set_state": { "open": true } }, { "play_clip": "open" }, { "set_solid": false }, { "take_item": "cellar_key" } ],
               "else": [ { "notify": "content.door.locked" } ], "once": true } ] }

Sugars for when: interact, enter / leave (zones), scene (entered / left), talked, quest, state, and gives on an archetype or instance. Engine verbs: set_state, play_clip, set_solid, show, hide, enable_script, disable_script, load_scene, next_scene, push_scene, pop_scene, set_scene, end_game, call, set_talk, patch_data, add_data, remove_data, set_config, set_setting, set_component. Kit verbs keep working (give_item, has_item, add_money, damage…) with the shorthand { verb: arg }.

An archetype has kind (the spawn factory; prop is the engine's), asset ({ slot } or { item }), tags, components (claimed by a kit, or owned by the engine: state, solid, model, size, model.placement, entry), gives and clips.

Hooks, events, services #

WhatNameDetail
Hookengine.scene.change{ from, to, entry, reason, loading } (reason: play, load_scene, next, enter, restart, push, pop); mutable to, entry, loading; cancellable (engine.scene.refused follows). Send the player elsewhere or keep them here
Hookengine.scene.release{ scene, next, assets }; mutable assets (the ones still freed); cancellable: everything stays in memory, for a scene the player returns to at once
Hookengine.scene.failed{ scene, failed, attempts, action }; mutable action (retry, enter, wait)
Hookengine.spawn{ kind, archetype, at, tags }; mutable archetype, tags; cancellable
Eventsengine.scene.entered, leaving, loading, progress, loaded, screen, failed, cancelled, pushed, popped, activated, state, unloaded, refusedthe scene life cycle
Eventsengine.flow.title, engine.flow.ended, engine.flow.restartedthe game flow
Servicesgame.enginethe contract
engine.contentinstances, registerComponent, the report
engine.scenescurrent, enter, push, pop, retry, cancelLoading
engine.scriptsthe verb registry, rules, enable and disable
engine.flowstart, end, restart
Moddablearchetypes, scenes, scripts, hooks, scene_assets, config sceneFlowhooks is live: a rule may add or remove a tap while the game runs
{ "id": "locked_keep", "hook": "engine.scene.change", "match": { "to": "keep" }, "if": [{ "var": "story.key", "eq": false }], "cancel": true, "reason": "locked" }

Save #

The section kits["game.engine"] keeps the current scene and entry, visited scenes, per-instance state, played once-rules, disabled scripts, quest statuses, and the visible and paused state of each loaded scene. An old save without it loads into the start scene.

Engines #

The scene flow, the scripts and the hooks run in the web runtime and the Rust kit host (hooks: web and Rust). Godot, Unity and Unreal read the compiled content and the flow; a scene with native is the engine's own scene, loaded by its scene adapter. Both ways (1.11): the scenes the game changes to or adds by itself in the engine (Godot change_scene_to_file, Unity SceneManager, Unreal levels) are told by the engine adapter (engine.scenes.nativeEntered(path, { mode }), nativeLeft(path)) and the kits see the same change as one they asked (events, the engine.scene.change hook); a path no document names is adopted as a scene of the game (info(id).adopted), its files are the engine's dependency list (assets(id)). Nothing to declare: the host makes the adapter.

When it does not do what you expect #

SymptomCause and fix
The title shows over the first levelsceneFlow.menu is overlay: set scene
A loading screen flasheslower showAfterMs is not needed: raise it, or preload the files so none shows
Memory stays high after leaving a sceneunload: keep, a tap of engine.scene.release cancels, or the files are shared with another scene
A scene change does nothinga tap of engine.scene.change cancelled it (engine.scene.refused says by whom)
A scene comes back frozenit was kept by unload: false and is paused: set_scene { scene, paused: false }

Logic tick #

Besides scenes, game.engine sets the rate of the game logic: gripforge_gamekit_configure { id: "game.engine", config: { "tick": { "hz": 30, "maxCatchUp": 4, "systems": { "npc.core.decide": 3 } } } }. Logic runs on a fixed tick, the game creator's choice from 5 to 120 Hz (default 30; strategy 10-20, action 30, twitch shooter 60; changeable live, by the authority in multiplayer), separate from the render frame and the physics step, rendering draws the last published poses interpolated between two ticks, so the game plays at the same speed at 30, 60 or 144 frames per second. systems gives a heavy system a period (N ticks, or { every, offset, hz }); never code a throttle. The three loops are set in the same tick object: source (independent | engine-physics), physicsHz and syncPhysics (the engine physics step, aligned on tick.hz when the game sets it), interpolate (render interpolation between two ticks, on by default) and maxCatchUp (optional cap on the ticks of one frame, 0 = none, the default). Rendering only interpolates, physics moves the characters at its own step, the action tick runs the game at tick.hz. tick is not moddable: every player of a match uses the same tick.

<!-- kit-services:begin -->

Services this kit uses (and that you can provide) #

CapabilityRequiredMethods
asset.metaoptionalof, section
asset.preloadoptionalreleaseScene, retryScene, sceneLoad, sceneProgress, sceneReady, wantScene
audio.coreoptionalplay, playPlaylist, setMusicState, stop
combat.healthoptionalalive, health
input.actionsoptionalaxis, justPressed, pressed
interaction.useoptionalregister
inventory.itemsoptionalgive
net.zonesoptional—
save.onlineoptional—
ui.menuoptional—

Any brick can serve them: a kit, or your engine (Godot provide_service, Unity Provide, Unreal ProvideService, Bevy provide_kit_service, C gfk_provide) — see the guide. <!-- kit-services:end -->

Startup interface policy belongs to the UI kit: engine.startupView declares visibility, scene backdrop, historical defaults and artwork roles. The shared Rust scene compiler and asset.preload read these declarations. Removing or disabling the UI kit starts play directly; chapters and the 3D title keep their existing behavior.

Spawn placement queries the active engine physics, downward from the authored height (0.4 m tolerance above it). It preserves the intended floor under bridges. place: "none" keeps the authored position; old resolved/basis coordinates are ignored. A missing surface leaves the pose unchanged and publishes structured warnings in engine.placement and engine.placement.completed. Runtime spawners can call engine.content.placeGround(entity) after installing their collider. If the scene declares a world, missing ground is retried within a budget of 120 polls to allow terrain collisions to load. The warning is emitted when that budget expires; without a world producer it remains immediate.

A native node whose pose is owned by the engine (engine.held) stays unchanged. placeGround reports engine.placement.engine_owned with applied:false; place that node through its engine controller, or bind it to an entity owned by the kits.

Loading steps of the game #

Work the kits cannot see (the game builds its terrain, generates a map) is declared as a step: holdStep(id, { label?, scene?, timeout? }), stepProgress(id, ratio), releaseStep(id), and steps(scene?) lists the pending ones. Without scene, the whole game waits: Play stays disabled on the title and a scene being entered waits behind its loading screen, even beyond loadTimeout. With a scene (or "current") only that scene is held; once entered, its loading screen stays (loading() answers settling: true, entering() stays true). A step expires after 120 s by default (timeout) and engine.step.expired tells it. Events: engine.step.held, engine.step.progress, engine.step.released, engine.step.expired; variable engine.steps (pending, game, ratio, label). In Godot, host.hold, host.progress and host.release call them:

On Bevy, KitGame::hold_step(step, label, scene, timeout), step_progress(step, ratio) and release_step(step) do the same, typed.

func _ready():
    host.hold("terrain", "Building the terrain")
    WorkerThreadPool.add_task(_build_terrain)

func _build_terrain():
    for i in CHUNKS:
        _build_chunk(i)
        if i % 8 == 0:
            host.call_deferred("progress", "terrain", float(i) / CHUNKS)
    host.call_deferred("release", "terrain")

Do the heavy work in the engine's worker threads, call progress a few times (not every frame) and release on the main thread (call_deferred).