Connecting Unity and UI DTO rules
Connecting Unity and UI

DTO rules

Shape C# data transfer objects so Loom can generate stable TypeScript types.

DTOs are plain C# types used as nested state, action parameters, action return values, or event payloads.

Supported shape

Use simple public properties:

C#
public sealed class InventoryItem
{
    public string Id { get; set; } = "";
    public string Name { get; set; } = "";
    public int Count { get; set; }
}

Prefer:

  • string, bool, numeric types
  • enums
  • DTO classes and structs
  • arrays and lists
  • dictionaries with supported key and value types

Avoid exposing Unity engine objects, services, delegates, file handles, or runtime-only references across the bridge. The state-only exceptions are Texture2D, Sprite, and RenderTexture; see Unity image sources. These image types are not supported in action parameters, action return values, or event payloads.

Naming

C# names are converted to camelCase in TypeScript:

C#
public int CurrentHealth { get; set; }
ts
bridge.currentHealth;

Use [BridgeName] only when you must preserve a different UI-facing name.

Enums

Enums appear in TypeScript as string values:

C#
public enum Screen
{
    MainMenu,
    Hud
}
ts
type Screen = 'MainMenu' | 'Hud';

Nulls

Prefer initialized values for state DTOs and collections. Nulls are harder for UI code to work with and can hide missing initialization during startup.

Regenerate after changes

Run:

Tools > Loom > Regenerate Types

after changing DTO fields, enum values, action signatures, or event payloads.

Loom documentation

Search docs

Esc

Type a word or phrase to search the documentation.

Type a word or phrase to search the documentation.