Game Settings
world.settings (or this.settings in a Behaviour) is the one place for what a player chooses: graphics, audio, controls and gameplay. It's saved in the browser between visits, each value is checked when it's read back, and the engine applies its own parts by itself, so a settings screen only reads and writes here. Since spatial-ecs 0.18.0 (SPATIAL_ECS_FEATURES.gameSettings).
import { Behaviour } from "@relu-interactives/spatial-ecs";
export default class SettingsExample extends Behaviour {
protected init() {
const audio = this.settings.section("audio");
console.log(audio.music); // 0..1
this.settings.update({ audio: { music: 0.4 } }); // saved, and the mixer follows at once
this.settings.set("controls.invertY", true);
this.settings.set("gameplay.difficulty", "hard"); // your own values
const stop = this.settings.subscribe((settings, changed) => {
if (changed.includes("gameplay")) console.log(settings.gameplay.difficulty);
});
stop();
}
}What's in it
| Section | Field | Default | Applied by |
|---|---|---|---|
graphics | preset: auto low medium high ultra custom | auto | QualitySystem |
resolutionScale 0.5..1 | 1 | ||
shadows: off low high | high | ||
postFx: off light full | full | ||
dynamicResolution | true | ||
frameRateCap: 0, 30, 60 | 0 | ||
showFps | false | ||
audio | master, music, sfx, voice, ui 0..1 | 0.8, 0.7, 0.9, 1, 0.8 | the mixer |
muted | false | ||
muteInBackground | true | ||
controls | lookSensitivity 0.1..3 | 1 | input |
invertY | false | ||
vibration (pad rumble and phone vibration) | true | ||
touchStick: float fixed | float | ||
touchOpacity 0.2..1, touchScale 0.7..1.5 | 0.85, 1 | ||
bindings (rebinds) | {} | ||
gameplay | cameraShake 0..1 | 1 | your scripts |
subtitles | true | your scripts | |
| anything else | your scripts |
gameplay takes any extra string, number or boolean field. The engine doesn't read cameraShake or subtitles; they're there so every game names them the same way. Multiply your shake by this.settings.section("gameplay").cameraShake.
Audio
The player's levels sit on top of the game's own mix: a bus plays at the volume the game set (setBusVolume) times the player's level for it, all through a master volume and mute. Changing a level never touches the game's mix, and the game's ducking still works. See Mixing and Sound Banks.
Browsers start sound suspended until the player touches, clicks or presses a key; the engine resumes it on the first one. With muteInBackground, a game in a background tab goes quiet and comes back when it's shown.
Your game's defaults
Ship different defaults (quiet music, a difficulty) with setDefaults at start-up. A saved choice still wins; reset goes back to your defaults:
import { Behaviour } from "@relu-interactives/spatial-ecs";
export default class Boot extends Behaviour {
protected init() {
this.settings.setDefaults({
audio: { music: 0.5 },
gameplay: { difficulty: "normal", fieldOfView: 70 },
});
}
resetAudio() {
this.settings.reset("audio");
}
}Where it's saved
localStorage key relu-game-settings:<gameId>, where gameId is passed to new World({ gameId }) (the templates pass the project's id). A save that can't be read, or storage that's blocked (private browsing, a sandboxed frame), falls back to the defaults and the game still runs. The editor never saves a player's settings.

