codeAPI Reference
s&box ISpawner: Spawner interface
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
- string DisplayName { get; } - Display name shown in the HUD while holding this payload.
- string Icon { get; } - Icon path for this payload, used for inventory display via thumb:path.
- BBox Bounds { get; } - The local-space bounds of the thing being spawned, used to offset placement so it sits on surfaces.
- bool IsReady { get; } - Whether all required resources (packages, models, etc.) are loaded and ready to place.
- Task<bool> Loading { get; } - A task that completes with true when loading succeeds, or false if it fails.
- string Data { get; } - The raw data needed to reconstruct this spawner (e.g., a cloud ident, or JSON).
- GameObject Prefab => null - The unspawned prefab GameObject, if available. Returns null for spawners that don't use prefabs.
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?