codeAPI Reference
s&box EntitySpawnerEntity: Entity spawner
EntitySpawnerEntity Component API Reference
EntitySpawnerEntity is a world-placed SENT that spawns another SENT at its location. Can be triggered manually via player input or automatically on a timer. Implements IPlayerControllable.
Type Signature
CSHARP
[Alias("entity_spawner")]
public class EntitySpawnerEntity : Component, IPlayerControllable
{
[Property, ClientEditable]
public ScriptedEntity Entity { get; set; }
[Property, Sync, ClientEditable, Group("Input")]
public ClientInput SpawnInput { get; set; }
[Property, ClientEditable, Group("Auto Spawn")]
public bool AutoSpawn { get; set; } = false;
[Property, ClientEditable, Range(1f, 300f), Step(1), Group("Auto Spawn")]
public float SpawnInterval { get; set; } = 5f;
[Property, ClientEditable, Range(1, 50), Step(1), Group("Auto Spawn")]
public float MaxEntities { get; set; } = 5;
}Properties
- ScriptedEntity Entity { get; set; } - The SENT to spawn
- ClientInput SpawnInput { get; set; } - Input binding for manual spawn
- bool AutoSpawn { get; set; } = false - Enable automatic spawning on timer
- float SpawnInterval { get; set; } = 5f - Seconds between automatic spawns (1-300)
- float MaxEntities { get; set; } = 5 - Max entities allowed to exist at once (1-50)
IPlayerControllable Implementation
- OnControl() - Spawns entity when SpawnInput is pressed
- OnStartControl() - Empty
- OnEndControl() - Empty
Usage
CSHARP
// Create an auto-spawning entity spawner
var spawner = GameObject.Components.Create<EntitySpawnerEntity>();
spawner.Entity = myEntityResource;
spawner.AutoSpawn = true;
spawner.SpawnInterval = 10f;
spawner.MaxEntities = 10;Notes
- Alias is "entity_spawner" for spawning via console
- Auto-spawn only runs on host (IsProxy check)
- Tracks spawned entities with WeakReference to enforce MaxEntities limit
- Prunes destroyed entities from tracking list each spawn
- Spawned entities are tagged "removable"
- Ownership is set to caller or GameObject owner
- Undo entry is created for the spawning player
- Spawned entities are networked and enabled after spawn
Was this helpful?