menu_bookDocumentation

Editor Tools

calendar_today May 3, 2026 schedule ~1 min read person patrickjr verified 50

Editor Tools

Create custom tools for the s&box editor.

Creating a Tool

CSHARP
[EditorTool]           // Mark as editor tool
[Title("Rocket")]      // Display name
[Icon("rocket_launch")] // Material Icon (https://fonts.google.com/icons)
[Shortcut("editortool.rocket", "u")] // Keyboard shortcut
public class MyRocketTool : EditorTool
{
    public override void OnEnabled()
    {
        // Tool activated
    }

    public override void OnDisabled()
    {
        // Tool deactivated
    }

    public override void OnUpdate()
    {
        // Called every frame while active
    }
}

Scene Access

CSHARP
public override void OnUpdate()
{
    // Ray from mouse into scene
    var tr = Scene.Trace.Ray(Gizmo.CurrentRay, 5000)
        .UseRenderMeshes(true)
        .WithoutTags("ignore")
        .Run();

    if (tr.Hit)
    {
        using (Gizmo.Scope("cursor"))
        {
            Gizmo.Transform = new Transform(tr.HitPosition, Rotation.LookAt(tr.Normal));
            Gizmo.Draw.LineCircle(0, 100);
        }
    }
}

Gizmo Drawing

CSHARP
using (Gizmo.Scope("my_tool"))
{
    // Set transform
    Gizmo.Transform = new Transform(position, rotation);
    
    // Draw shapes
    Gizmo.Draw.LineSphere(0, radius);
    Gizmo.Draw.LineBox(BBox.FromPositionAndSize(Vector3.Zero, size));
    Gizmo.Draw.Arrow(Vector3.Zero, direction * 100);
}

Preventing Selection

CSHARP
public override void OnEnabled()
{
    AllowGameObjectSelection = false; // Disable click-to-select
}

Overlay UI

CSHARP
public override void OnEnabled()
{
    var window = new WidgetWindow(SceneOverlay);
    window.Layout = Layout.Column();
    window.Layout.Margin = 16;

    var button = new Button("Shoot Rocket");
    button.Pressed = () => FireRocket();

    window.Layout.Add(button);
    
    // Auto-cleanup on tool disable
    AddOverlay(window, TextFlag.RightTop, 10);
}

Editor Project Setup

Tools must be in an editor projectopen_in_new:

CODE
mygame/
  mygame.sbproj        // Game project
  mygame.editor/
    mygame.editor.csproj // Editor tools project
Was this helpful?