Your first screen
This page assumes you’ve already installed the
Unity package and have a <ProjectRoot>/UI/ folder with a package.json.
-
Define the bridge in C#.
Create a new C# file in your game’s
Assets/Scripts/UI/:Assets/Scripts/UI/GameBridge.cs using Loom;[Bridge]public partial class GameBridge {[BridgeState] public Observable<int> Score { get; } = new(0);[BridgeAction] public void AddPoint() { Score.Value += 1; }}The
[Bridge]attribute triggers the source generator. After the next Unity compile,Loom → Regenerate Types(run from the Editor menu) emits the matching TypeScript types toUI/src/bridge.d.ts. -
Register the bridge on Play.
In your bootstrap MonoBehaviour (typically
LoomBootstrapor a subclass), add the bridge beforeLoomRuntime.Initialize():var bridge = new GameBridge();bridge.RegisterWithLoom(); -
Use the bridge from your UI.
In your Solid app:
C#[BridgeState]public Observable<int> Score { get; } = new(0);[BridgeAction]public void AddPoint() {Score.Value += 1;}TSimport { useBridge } from '@loomgui/bridge'export default function Score() {const bridge = useBridge()return (<><span>{bridge.state.score}</span><button onClick={() => bridge.actions.addPoint()}>+1</button></>)} -
Hit Play. Click the +1 button —
bridge.actions.addPoint()reaches C#,Score.Valuebumps, and the UI re-renders with the new value.
Where to go next
- The bridge — full reference for state, actions, and events.
- Mock mode — author the UI without Unity running.
- ↗
unity/sample/UI/src/screens/Counter.tsx— the same pattern in the in-repo sample.