In-game UI
In-game UI is any 2D element drawn on top of the 3D scene: crosshair, prompts, pause menu, inventory, settings. In Kolpa you build it from real GameObjects with UI components, using the UI helpers in the Kolpa.Engine namespace.
The UI system uses the same component model as the rest of the engine. A panel is a GameObject with a UiRect and a layout component. Text, images, and buttons are child GameObjects.
The UI helpers
Section titled “The UI helpers”UI builds a small tree of UI objects for you and returns a UiBuilder you can keep and extend.
| Method | Builds |
|---|---|
UI.Row(name, build) |
Children packed left to right |
UI.Column(name, build) |
Children packed top to bottom |
UI.Stack(name, direction, build) |
Same, with an explicit direction |
UI.Grid(name, columns, minCellWidth, build) |
Uniform-cell grid |
UI.Scroll(name, build, horizontal) |
Scrollable viewport |
UI.Themed(root, theme) |
Applies a UiTheme to a subtree |
A simple HUD row:
using Kolpa.Engine;
public class Hud : MonoBehaviour{ private UiBuilder _root;
public override void OnCreate() { _root = UI.Row("hud", row => { row.Label("Score").Text("0"); }); }}Widgets
Section titled “Widgets”A UiBuilder exposes typed sub-builders for common widgets: Button, Label, Image, TextInput, TextArea, Scroll, Row, Column, Grid. Each returns a builder whose component you can tweak.
UiBuilder panel = UI.Column("pause_menu", col =>{ col.Label("Paused").FontSize(32); col.Button("Quit", () => SceneManager.LoadScene("scenes/menu.scene"));});col.Button("Quit", onClick) wires the click callback. See UiBuilder for the full method list.
Layout with UiRect
Section titled “Layout with UiRect”Every UI object carries a UiRect: normalized anchors (0 top-left, 1 bottom-right), pivot, anchored position, size, and stretch. Layout components (UiStackLayout, UiGridLayout, UiResponsiveLayout) position children from these.
UiRect is the equivalent of a RectTransform. For a centered crosshair, anchor it at center and size it in layout units.
Themes
Section titled “Themes”UiTheme holds colors, sizes, and text roles. Apply one to a subtree with UI.Themed(root, theme), or pass a theme to UI.Row / UI.Column / UI.Stack. This keeps buttons and text consistent across a menu.
Presets exist (for example UiTheme.Dark()). See UiTheme.
Images and textures
Section titled “Images and textures”UiImage draws a filled rectangle or texture inside its UiRect. Set the texture path and tint through the component.
Reading UI input vs gameplay input
Section titled “Reading UI input vs gameplay input”When a menu is open, stop moving the character while the player clicks buttons. Check whether the UI wants input before you run gameplay input:
- The UI system reports pointer capture while a widget is hovered, held, or focused.
- Gate your movement and look code on that state so a click does not also fire the player controller.
Keep the pattern in one place so a pause menu disables movement the same way everywhere.
Continue reading
Section titled “Continue reading”Previous: Communication: call other scripts and read components.
Next: Assemblies and the engine API: what the engine owns and what you edit.
