Connecting Unity and UI The bridge model
Connecting Unity and UI

The bridge model

State, actions, and events are the three ways Unity and the UI communicate.

The bridge is the typed contract between your Unity game and your Solid UI. You define it in C#, and Loom generates the matching TypeScript surface.

There are three concepts:

DirectionBridge memberUse it for
C# to UIState propertiesValues the UI should render reactively
UI to C#[BridgeAction] methodsButtons, form submits, menu actions
C# to UIEvent<T> propertiesOne-shot notifications

State

State is data the UI reads:

C#
public int Health { get; set; } = 100;

When C# assigns a new value, the UI updates:

TSX
const bridge = useBridge();

<span>{bridge.health}</span>

Use state for values that have a current truth: selected screen, player health, inventory snapshots, loading progress, current scene, and settings.

Actions

Actions are public C# methods tagged [BridgeAction] that the UI can call:

C#
[BridgeAction]
public void OpenInventory()
{
    CurrentScreen = GameScreen.Inventory;
}

The UI calls the generated action proxy:

TSX
await bridge.openInventory();

Use actions for user intent: click, confirm, purchase, equip, submit, start, cancel.

Events

Events are one-shot messages from C# to UI:

C#
public Event<DamageEvent> TookDamage { get; } = new();

Use events for moments rather than durable state: damage flash, toast, reward burst, alert sound, or animation trigger.

Choosing the right primitive

  • If the UI needs to know the latest value, use state.
  • If the UI is asking the game to do something, use an action.
  • If the game is announcing that something happened, use an event.

The next pages go deeper into each piece.

Loom documentation

Search docs

Esc

Type a word or phrase to search the documentation.

Type a word or phrase to search the documentation.