Skip to main content
You can create custom editor tools to assist in building your game. An editor tool is a mode you can activate in the scene viewport to perform custom interactions — selecting objects, drawing, painting, placing props, and so on. Editor tools must live in an editor project — a folder named editor inside your game project.

Creating a tool

Add the [EditorTool] attribute to a class that extends EditorTool. Use [Title], [Icon], and [Shortcut] to configure how it appears and how it is activated.
[EditorTool]
[Title( "Rocket" )]
[Icon( "rocket_launch" )]
[Shortcut( "editortool.rocket", "U" )]
public class MyRocketTool : EditorTool
{
    public override void OnEnabled()
    {
        // Called when the tool is activated
    }

    public override void OnDisabled()
    {
        // Called when the tool is deactivated
    }

    public override void OnUpdate()
    {
        // Called every frame while the tool is active
    }
}
The [Icon] attribute accepts icon names from Google Material Icons. Your tool will appear in the tool selector in the editor toolbar once compiled.

Accessing the scene

Inside OnUpdate, use the Scene property to interact with the scene. The following example traces a ray from the mouse cursor and draws a gizmo at the hit point:
public override void OnUpdate()
{
    var tr = Scene.Trace.Ray( Gizmo.CurrentRay, 5000 )
                    .UseRenderMeshes( true )
                    .UsePhysicsWorld( false )
                    .WithoutTags( "sprinkled" )
                    .Run();

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

Preventing object selection

By default, clicking in the scene selects GameObjects. If your tool handles clicks itself, disable this behavior in OnEnabled:
public override void OnEnabled()
{
    AllowGameObjectSelection = false;
}

Adding overlay UI

You can display UI elements in the scene viewport while your tool is active. Create a WidgetWindow and add widgets to its layout, then call AddOverlay to attach it to the scene overlay:
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 = () => Log.Info( "Rocket Has Been Shot!" );

    window.Layout.Add( button );

    // Automatically cleans up the UI when the tool is deactivated
    AddOverlay( window, TextFlag.RightTop, 10 );
}
The UI is created when your tool activates and destroyed when it deactivates.
If you add overlay UI without calling AddOverlay, the UI will not be cleaned up automatically when the tool is deactivated. Always use AddOverlay for overlay widgets.
  • Shortcuts — Define keyboard shortcuts for your tools