UI

HudPainter

HudPainter is obsolete. It has been replaced by Painter, which does everything it did and much more.

Camera.Hud and Camera.Overlay used to give you a HudPainter with DrawRect, DrawLine, DrawText and DrawTexture methods. They still work for now, but you should switch to BeginHud() and BeginOverlay(), which give you a Painter.

The main difference is that fill, stroke and text style are state you set on the painter, rather than arguments you pass to each call. The painter must also be disposed to submit its drawing, so use using.

Before

protected override void OnUpdate()
{
	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 ), new Vector2( Screen.Width * 0.5f, 100 ) );
}

Now

protected override void OnUpdate()
{
	using var painter = Scene.Camera.BeginHud();

	painter.Fill = Color.White;
	painter.Rect( new Rect( 300, 300, 10, 10 ) );

	painter.Stroke = Stroke.Solid( Color.White, 10 );
	painter.Line( new Vector2( 100, 100 ), new Vector2( 200, 200 ) );

	painter.TextStyle = new TextStyle { FontSize = 32, Color = Color.Red, Alignment = TextFlag.CenterTop };
	painter.Text( "Hello!", new Rect( 0, 100, painter.Bounds.Width, 40 ) );
}
BeforeNow
Camera.HudCamera.BeginHud()
Camera.OverlayCamera.BeginOverlay()
DrawRect( rect, color )Fill = color; Rect( rect );
DrawLine( a, b, width, color )Stroke = Stroke.Solid( color, width ); Line( a, b );
DrawText( scope, position )TextStyle = ...; Text( text, rect );
DrawTexture( texture, rect )Texture( texture, rect );
DrawCircle( position, size, color )Fill = color; Circle( position, size );
SetMatrix( matrix )Transform = matrix; or Translate, Rotate, Scale
SetBlendMode( mode )BlendMode = mode;

See Destinations for the full guide to drawing on cameras.

Source: Facepunch/sbox-docs (CC-BY-4.0) · updated 2026-09-16. Read it rendered on the official docs.

More in UI

Community wiki — not affiliated with Facepunch Studios. For the latest and most authoritative information, see the official developer wiki.