Overview
SWS is built around four core systems that work together to provide flexible and performant entity spawning:
Spawning System
Manages what, where, and how entities spawn
Wave System
Orchestrates when and how many entities spawn
Path System
Guides entities along waypoint-based paths
Object Pooling
Recycles entities for optimal performance
Spawning System
The spawning system consists of three key elements: SpawnProfiles define what to spawn, SpawnPoints define where to spawn, and theSpawnManager orchestrates the process.
Spawn Profiles
A SpawnProfile is a ScriptableObject that defines everything about a spawnable entity:
| Property | Description |
|---|---|
| Prefab | The GameObject to instantiate |
| Variants | Weighted prefab alternatives |
| Budget Cost | Cost for wave budget balancing |
| Lifetime | Auto-despawn after X seconds (0 = infinite) |
| Pool Size | Number of instances to pre-pool |
Spawn Points
SpawnPoints are scene components that mark valid spawn locations:
| Property | Description |
|---|---|
| Tags | Filter spawn points by tags |
| Radius | Random offset from center position |
| Max Concurrent | Limit active spawns from this point |
| Cooldown | Minimum time between spawns |
Priority Queue
Spawn requests are processed through a priority queue to ensure critical spawns happen first:
Bosses, key NPCs
Elite enemies
Standard enemies
Ambient, decoration
Wave System
The wave system controls when entities spawn using a hierarchy of WaveDefinitions grouped into WaveSequences.
Wave Definitions
A WaveDefinition describes a single wave:
WaveDefinition Structure
WaveDefinition:
├── Allocations:
│ ├── Profile: Enemy_Basic, Count: 10
│ └── Profile: Enemy_Fast, Count: 5
├── Spawn Interval: 0.5 seconds
├── Spawn Point Selection: Random
├── Spawn Point Tags: ["Enemy", "Ground"]
└── End Condition: AllDefeatedEnd Conditions
| AllDefeated | Wave ends when all spawned entities are defeated |
| AllSpawned | Wave ends immediately after all entities spawn |
| Timer | Wave ends after a specified duration |
Wave Sequences
A WaveSequence groups multiple wave definitions together:
WaveSequence Structure
WaveSequence:
├── Waves: [Wave_01, Wave_02, Wave_03]
├── Mode: Single | Loop | Endless
├── Auto Advance: true
├── Wave Delay: 3 seconds
└── Scale On Loop: Multiplier per loop iterationSequence Modes
Single Mode
Plays all waves once in order. When the last wave completes, the sequence ends. Perfect for story missions or level-based games.
Loop Mode
After the last wave, returns to the first wave indefinitely. Useful for endless arcade modes.
Endless Mode
Like Loop, but with optional difficulty scaling each iteration. Configure spawn count and stat multipliers that increase over time.
Path System
The path system enables Tower Defense-style gameplay where entities follow predefined routes through your level.
Path Anchors
PathAnchors are waypoints that entities navigate between:
| Property | Description |
|---|---|
| Next Anchors | Connected waypoints (supports branching) |
| Wait Time | Pause duration at this waypoint |
| Speed Multiplier | Speed modifier for this segment |
| Reach Radius | Distance to consider waypoint reached |
Path Follower
The PathFollower component makes entities navigate along paths:
| Property | Description |
|---|---|
| Movement Speed | Base movement speed |
| Rotation Speed | How fast entity turns toward target |
| Smooth Movement | Interpolate movement for smoother motion |
| Look Ahead | Rotate toward next waypoint early |
Object Pooling
SWS includes a high-performance pooling system that recycles entities instead of constantly creating and destroying them.
Pool Configuration
SpawnProfile Pool Settings
SpawnProfile:
├── Use Pooling: ✓
├── Pool Size: 50
└── Allow Growth: ✓ (create more if pool empty)SpawnManager Global Settings
SpawnManagerSettings:
├── Default Pool Size: 20
├── Max Pool Size Per Profile: 100
├── Enable Debug Logging: ✓
└── Max Spawns Per Frame: 10Entity Lifecycle
The SpawnedEntityTracker component manages an entity's lifecycle:
- Spawn: Entity retrieved from pool or instantiated
- Active: Entity is alive and tracked by EntityRegistry
- Defeat: Entity health reaches 0 or is manually defeated
- Despawn: Entity returned to pool for reuse