menu_bookDocumentation

HudPainter: Immediate-Mode HUD Drawing in s&box

calendar_today May 20, 2026 schedule ~1 min read person PatrickJr verified 50

Each CameraComponent has a Hud property (HudPainter) for immediate-mode drawing onto the screen. More efficient than UI panels since there's no layout, stylesheets, or interactivity — you handle positioning yourself.

Basic Usage

Draw in any Update function:

CSHARP
protected override void OnUpdate()
{
    if ( Scene.Camera is null ) return;

    var hud = Scene.Camera.Hud;

    hud.DrawRect( new Rect( 300, 300, 10, 10 ), Color.White );
    hud.DrawLine( new Vector2( 100, 100 ), new Vector2( 200, 200 ), 10, Color.White );
    hud.DrawText( new TextRendering.Scope( "Hello!", Color.Red, 32 ), Screen.Width * 0.5f );
}

When to Use

Use HudPainter for simple HUDs (crosshairs, debug overlays, minimal status displays) where you don't need layout, styling, or interactivity. For complex UI with panels, styling, and interaction, use Razor Panels instead.

Was this helpful?