UI Scripting
UI elements are scene objects (Create → 2D/UI). They render in the Game Viewport overlay.
Button Clicks
IsUIButtonPressed() is true only on the frame the click happens.
1
400">void TickUpdate(400">ScriptContext& ctx, 400">float) {
2
400">if (ctx.IsUIButtonPressed()) {
3
ctx.AddConsoleMessage("Button clicked!");
4
}
5
}
Sliders as Meters (Health/Ammo)
Set Interactable to false to make a slider read-only.
1
400">void TickUpdate(400">ScriptContext& ctx, 400">float) {
2
ctx.SetUIInteractable(400">false);
3
ctx.SetUISliderStyle(UISliderStyle::Fill);
4
ctx.SetUISliderRange(0.0f, 100.0f);
5
ctx.SetUISliderValue(health);
6
}
Style Presets
Register custom ImGui style presets in code and select them per UI element in the Inspector.
1
400">void Begin(400">ScriptContext& ctx, 400">float) {
2
ImGuiStyle style = 400">ImGui::GetStyle();
3
style.Colors[ImGuiCol_Button] = ImVec4(0.20f, 0.50f, 0.90f, 1.00f);
4
style.Colors[ImGuiCol_ButtonHovered] = ImVec4(0.25f, 0.60f, 1.00f, 1.00f);
5
ctx.RegisterUIStylePreset("Ocean", style, 400">true);
6
}
Then select UI → Style Preset on a button or slider.
Finding Other UI Objects
1
400">void TickUpdate(400">ScriptContext& ctx, 400">float) {
2
400">if (SceneObject* other = ctx.FindObjectByName("UI Button 3")) {
3
400">if (other->type == ObjectType::UIButton && other->ui.buttonPressed) {
4
ctx.AddConsoleMessage("Other button clicked!");
5
}
6
}
7
}
Text Objects
Use UI Text objects for on-screen text. Update their label and size from scripts:
1
400">void TickUpdate(400">ScriptContext& ctx, 400">float) {
2
400">if (SceneObject* text = ctx.FindObjectByName("UI Text 2")) {
3
400">if (text->type == ObjectType::UIText) {
4
text->ui.label = "Speed: 12.4";
5
text->ui.textScale = 1.4f;
6
ctx.MarkDirty();
7
}
8
}
9
}