Skip to content

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).

ts
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 ​

SectionFieldDefaultApplied by
graphicspreset: auto low medium high ultra customautoQualitySystem
resolutionScale 0.5..11
shadows: off low highhigh
postFx: off light fullfull
dynamicResolutiontrue
frameRateCap: 0, 30, 600
showFpsfalse
audiomaster, music, sfx, voice, ui 0..10.8, 0.7, 0.9, 1, 0.8the mixer
mutedfalse
muteInBackgroundtrue
controlslookSensitivity 0.1..31input
invertYfalse
vibration (pad rumble and phone vibration)true
touchStick: float fixedfloat
touchOpacity 0.2..1, touchScale 0.7..1.50.85, 1
bindings (rebinds){}
gameplaycameraShake 0..11your scripts
subtitlestrueyour scripts
anything elseyour 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:

ts
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.