Spawn & Wave System

v1.0.0

Core Concepts

Understand the fundamental architecture and systems of SWS.

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:

PropertyDescription
PrefabThe GameObject to instantiate
VariantsWeighted prefab alternatives
Budget CostCost for wave budget balancing
LifetimeAuto-despawn after X seconds (0 = infinite)
Pool SizeNumber of instances to pre-pool

Spawn Points

SpawnPoints are scene components that mark valid spawn locations:

PropertyDescription
TagsFilter spawn points by tags
RadiusRandom offset from center position
Max ConcurrentLimit active spawns from this point
CooldownMinimum time between spawns

Priority Queue

Spawn requests are processed through a priority queue to ensure critical spawns happen first:

Critical

Bosses, key NPCs

High

Elite enemies

Normal

Standard enemies

Low

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: AllDefeated

End Conditions

AllDefeatedWave ends when all spawned entities are defeated
AllSpawnedWave ends immediately after all entities spawn
TimerWave 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 iteration

Sequence 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:

PropertyDescription
Next AnchorsConnected waypoints (supports branching)
Wait TimePause duration at this waypoint
Speed MultiplierSpeed modifier for this segment
Reach RadiusDistance to consider waypoint reached
Path Visualization: PathAnchors display connection lines in the Scene view, making it easy to design complex paths.

Path Follower

The PathFollower component makes entities navigate along paths:

PropertyDescription
Movement SpeedBase movement speed
Rotation SpeedHow fast entity turns toward target
Smooth MovementInterpolate movement for smoother motion
Look AheadRotate 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: 10

Entity Lifecycle

The SpawnedEntityTracker component manages an entity's lifecycle:

  1. Spawn: Entity retrieved from pool or instantiated
  2. Active: Entity is alive and tracked by EntityRegistry
  3. Defeat: Entity health reaches 0 or is manually defeated
  4. Despawn: Entity returned to pool for reuse
GC2 Stats Integration: When using the GC2 Stats Module, entities are automatically marked as defeated when their Health attribute reaches zero.