Skip to content

LoomBootstrap

LoomBootstrap is the entry point — a MonoBehaviour you attach to a GameObject in your boot scene that:

  1. Instantiates your [Bridge] class.
  2. Registers it with the Loom runtime.
  3. Initializes the Loom runtime.
  4. Spawns the Vite dev server (in Editor) or loads the static UI (in player builds).
  5. Navigates the WebView once the UI is ready.

Minimal usage

using Loom;
using UnityEngine;
[DefaultExecutionOrder(-1000)]
public class GameLoomBootstrap : MonoBehaviour {
public static GameLoomBootstrap Instance { get; private set; }
public GameBridge Bridge { get; private set; }
private void Awake() {
if (Instance != null && Instance != this) {
Destroy(this); return;
}
Instance = this;
DontDestroyOnLoad(gameObject);
Bridge = new GameBridge();
Bridge.RegisterWithLoom();
LoomRuntime.Initialize();
}
private void OnDestroy() {
if (Instance == this) Instance = null;
LoomRuntime.Shutdown();
}
}

The [DefaultExecutionOrder(-1000)] ensures this bootstrap runs before any other scripts that depend on Loom being initialized.

Per-scene drivers

For multi-scene games, LoomBootstrap lives in your boot scene and persists via DontDestroyOnLoad. Each gameplay scene can have a small per-scene driver that pushes scene-specific state into the bridge.

See Multi-scene patterns below.

Editor vs player

In the Editor, Loom auto-spawns Vite and navigates the UI for you. No extra setup needed.

In player builds, the UI is loaded from Application.streamingAssetsPath/Loom/index.html, which your last production UI build emitted.

Multi-scene patterns

A common pattern is one bootstrap + one bridge per game, with per-scene “drivers” that:

  • Read scene state (e.g. current score, current screen) and push to the bridge.
  • Subscribe to bridge events relevant to the scene.
public class GameplayLoomDriver : MonoBehaviour {
private void Start() {
var bridge = GameLoomBootstrap.Instance.Bridge;
bridge.CurrentScreen.Value = SampleScreen.Hud;
}
}

Drivers attach to scene-specific GameObjects and clean up automatically on scene unload.

Shutdown

LoomRuntime.Shutdown() disposes the bridge. To stop Vite as well, use Loom → Stop Dev Server from the menu.