Build 2D screen panels and 3D world panels using Razor components and CSS styling.
s&box UI is built on an HTML/CSS panel model. You write layout using Razor (.razor) files and style with SCSS. The engine renders panels using its own GPU-accelerated layout engine — no browser required.
Every UI element is a Panel. Panels form a tree: a parent panel clips and positions its children. Layout follows a CSS flexbox model, and styling uses a subset of CSS/SCSS.The two root containers are:
Component
Description
ScreenPanel
Renders panels as a 2D overlay on the screen.
WorldPanel
Renders panels in 3D world space, attached to a GameObject.
Add a ScreenPanel component to a GameObject to create a 2D HUD or menu layer. All PanelComponent children of that GameObject (or its descendants) are parented to this root automatically.
Property
Description
Opacity
Transparency of the entire panel [0–1].
Scale
Uniform scale multiplier.
AutoScreenScale
Automatically scale the UI based on screen resolution.
ScaleStrategy
ConsistentHeight (assumes 1080p height) or FollowDesktopScaling.
ZIndex
Render order; higher values are drawn on top.
TargetCamera
Optional camera to render against (for split-screen, etc.).
// The ScreenPanel component is configured in the Inspector.// Access it from code if needed:var sp = Components.Get<ScreenPanel>();sp.Opacity = 0.9f;sp.ZIndex = 200;
Scales the UI so it appears the same physical size regardless of resolution,
by assuming the screen height is always 1080 units.
Good for gameplay HUDs.
Matches the OS display scale factor.
Good for menus and settings screens that should respect the user’s DPI preference.
Add a WorldPanel component to render UI anchored to a point in 3D space — useful for name tags, interactive terminals, or floating labels.
Property
Type
Description
PanelSize
Vector2
Canvas size in screen-space pixels.
RenderScale
float
Overall scale of the world panel geometry.
LookAtCamera
bool
Rotate to always face the camera.
HorizontalAlign
enum
Left, Center, or Right pivot.
VerticalAlign
enum
Top, Center, or Bottom pivot.
InteractionRange
float
Maximum distance at which the player can interact.
// Configure from the Inspector, or access at runtime:var wp = Components.Get<WorldPanel>();wp.PanelSize = new Vector2( 800, 400 );wp.LookAtCamera = true;wp.InteractionRange = 250f;
WorldPanel is a Renderer component. It creates a SceneObject in the world and renders the panel tree into a texture each frame.
The engine re-renders your Razor markup whenever BuildHash() returns a different value than the previous frame. Always include every piece of data your template depends on:
protected override int BuildHash(){ // Re-render whenever any of these change return HashCode.Combine( Health, IsAlive, StatusEffect );}
You can also call StateHasChanged() to force an immediate re-render:
protected override void OnTreeFirstBuilt(){ // Called once, after the Razor tree is rendered for the first time Log.Info( "HUD is ready" );}protected override void OnTreeBuilt(){ // Called every time the tree is re-rendered}