codeAPI Reference

s&box Global.ISpawnEvents: Spawn event callbacks

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

Global.ISpawnEvents Interface API Reference

Global.ISpawnEvents is an interface for Components that want to listen to spawn events across the scene. Implement to receive callbacks before and after objects are spawned.

Type Signature

CSHARP
public static partial class Global
{
    public interface ISpawnEvents : ISceneEvent<ISpawnEvents>
    {
        public class SpawnData
        {
            public ISpawner Spawner { get; init; }
            public Transform Transform { get; init; }
            public PlayerData Player { get; init; }
            public bool Cancelled { get; set; }
        }

        public class PostSpawnData : SpawnData
        {
            public List<GameObject> Objects { get; init; }
        }

        void OnSpawn(SpawnData e);
        void OnPostSpawn(PostSpawnData e);
    }
}

Event Data

SpawnData

PostSpawnData (inherits SpawnData)

Methods

OnSpawn(SpawnData e)

Called before an object is spawned into the world. Set SpawnData.Cancelled to true to reject the spawn.

OnPostSpawn(PostSpawnData e)

Called after an object has been successfully spawned into the world.

Usage

CSHARP
public class SpawnLogger : Component, Global.ISpawnEvents
{
    public void OnSpawn(Global.ISpawnEvents.SpawnData e)
    {
        Log.Info($"Spawning object at {e.Transform.Position} by {e.Player?.Name ?? "unknown"}");

        // Reject spawns in restricted areas
        if (IsInRestrictedArea(e.Transform.Position))
        {
            e.Cancelled = true;
        }
    }

    public void OnPostSpawn(Global.ISpawnEvents.PostSpawnData e)
    {
        Log.Info($"Spawned {e.Objects.Count} objects");
    }
}

Notes

  • Implements ISceneEvent for scene-wide event broadcasting
  • OnSpawn allows pre-spawn validation and cancellation
  • OnPostSpawn allows post-spawn processing
  • Spawner is the ISpawner implementation (e.g., SpawnerWeapon)
  • Transform is the spawn position and rotation
  • Player is the player who requested the spawn (can be null)
  • Cancelled prevents the spawn from occurring
Was this helpful?