codeAPI Reference

s&box ISpawner: Spawner interface

calendar_today May 12, 2026 schedule ~2 min read person PatrickJr verified 50

ISpawner Interface API Reference

ISpawner describes something that can be spawned into the world. Implementations handle their own preview rendering and spawn logic.

Type Signature

CSHARP
public interface ISpawner
{
    string DisplayName { get; }
    string Icon { get; }
    BBox Bounds { get; }
    bool IsReady { get; }
    Task<bool> Loading { get; }
    string Data { get; }
    GameObject Prefab => null;

    void PopulateContextMenu(MenuPanel menu, string ident, string metadata);
    void DrawPreview(Transform transform, Material overrideMaterial);
    Task<List<GameObject>> Spawn(Transform transform, Player player);
}

Properties

Methods

PopulateContextMenu(MenuPanel menu, string ident, string metadata)

Populate a right-click context menu with spawner-specific options. Override in spawner implementations to add custom menu items.

DrawPreview(Transform transform, Material overrideMaterial)

Draw a ghost preview at the given world transform.

Spawn(Transform transform, Player player)

Actually spawn the thing at the given transform. Called on the host. Returns the root GameObject(s) that were spawned so they can be added to undo.

Usage

Implement ISpawner on a class that handles spawning:

CSHARP
public class MySpawner : ISpawner
{
    public string DisplayName => "My Object";
    public string Icon => "thumb:materials/myicon.png";
    public BBox Bounds => new BBox(Vector3.One * -10, Vector3.One * 10);
    public bool IsReady => true;
    public Task<bool> Loading => Task.FromResult(true);
    public string Data => "my_data";

    public void PopulateContextMenu(MenuPanel menu, string ident, string metadata)
    {
        menu.AddOption("Rotate", () => { /* rotate logic */ });
    }

    public void DrawPreview(Transform transform, Material overrideMaterial)
    {
        // Draw ghost preview
    }

    public async Task<List<GameObject>> Spawn(Transform transform, Player player)
    {
        var go = new GameObject();
        go.WorldTransform = transform;
        return new List<GameObject> { go };
    }
}

Notes

  • Used by spawner weapons (SpawnerWeapon, DuplicatorSpawner)
  • Bounds is used for surface placement calculations
  • Loading task enables async resource loading
  • Data property enables serialization/deserialization
  • Prefab property is optional (null for non-prefab spawners)
  • Spawn is only called on the host
Was this helpful?