Skip to content

React HUD

In vgai, React is for the HUD/overlay only — not gameplay objects. You mount a React tree into the game’s UI container and tear it down on dispose.

The UI container is pointer-events none; interactive widgets opt back in to auto
The pointer-events model.

mountUI(container, element) (packages/editor/template/src/examples/ui/mount-ui.ts) creates a React root and renders into it, returning an unmount function:

const unmount = mountUI(ctx.uiContainer, <MyHUD />);
// in dispose():
return { dispose: unmount };

Store the returned function and call it in your example’s dispose() so the HUD is removed on scene change.

ctx.uiContainer is a full-screen overlay created with pointer-events: none (packages/engine/src/runtime/create-runtime.ts), so clicks fall through to the 3D canvas by default. Interactive widgets explicitly set pointer-events: auto to receive input (the shared Panel, for instance, sets pointerEvents: 'auto').

The template ships reusable, inline-styled HUD components in packages/editor/template/src/examples/ui/: Panel, Button, Slider, Toggle, KeyHint, and StatusDot. They use inline styles (no CSS files) and a dark, monospace aesthetic.

For authoring UI visually (layout, theming, data binding) rather than hand-coding it, see the Visual UI Editor.