> For the complete documentation index, see [llms.txt](https://roogame.gitbook.io/roogame/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://roogame.gitbook.io/roogame/survivors-roguelike-kit/adding-a-new-stage-configuration.md).

# Adding a New Stage Configuration

## Stage System Detailed Guide

The **Stage System** drives all enemy spawning in your game. It consists of two asset types—**StageConfigSO** (defining which groups spawn) and **SpawnSet** (defining how and when each group spawns)—plus the **StageManager** component that runs it at runtime.

***

#### 1. Spawn Patterns (`SpawnPatternType`)

Spawn behavior is controlled by this enum in code:

```
public enum SpawnPatternType {
  Random,  // scattered just outside the camera view
  Circle,  // enemies form a ring around the player
  Dense    // enemies cluster tightly around a point
}
```

Use these patterns to vary your encounters.

***

#### 2. Defining a SpawnSet

A **SpawnSet** asset describes one group of enemies and its spawn logic.

**a. Create or Locate a SpawnSet**

1. In the Project window go to:

```
Assets/RGame/RoguelikeKit/ScriptableObjects/DataSO/Stage/StageSet
```

<figure><img src="/files/6xoESK1nLWZKXKKbXNw5" alt=""><figcaption></figcaption></figure>

1. To create a new one: **Right-click → Create → RGame → RoguelikeKit → Stage → Spawn Set**
2. Name the asset (e.g., `SpawnSet_GoblinRing`).

**b. Configure SpawnSet Properties**

Open your **SpawnSet** in the Inspector and set these fields:

<figure><img src="/files/4WSFti632xlfweUlHqt2" alt=""><figcaption></figcaption></figure>

* **PoolKey**: string matching your object-pool key (e.g., "Goblin").
* **Weight**: relative chance when picking randomly.
* **Pattern** (`SpawnPatternType`): choose **Random**, **Circle**, or **Dense**.
* **BaseRatePerSecond** (Random only): enemies spawned per second (before scaling).
* **Count** (Circle/Dense only): how many enemies spawn each tick.
* **CircleRadius** (Circle only): distance from player for the ring.
* **StartTime** & **EndTime**: when (in seconds) this set becomes active.
* **IntensityCurve**: AnimationCurve (0–1) that multiplies **BaseRatePerSecond** over the segment.

***

#### 3. Assembling a StageConfigSO

A **StageConfigSO** asset groups multiple **SpawnSets** into a timeline.

**a. Locate or Create**

1. Navigate to:

   ```
   Assets/RGame/RoguelikeKit/ScriptableObjects/DataSO/Stage/StageConfigSO.asset
   ```

   <figure><img src="/files/dDba9KI4hfJInY5jwIQR" alt=""><figcaption></figcaption></figure>
2. To create new: **Right-click → Create → RGame → RoguelikeKit → Stage → StageConfigSO**
3. Name it (e.g., `StageConfig_ForestLevel`).

**b. Add SpawnSets**

In the Inspector’s **SpawnSets** list:

1. Click **+**.
2. Drag each **SpawnSet** asset into its slot.
3. The **StageManager** will sort them by **StartTime** at runtime.

   <figure><img src="/files/9pjge7nqI4p9Llgt8irS" alt="" width="405"><figcaption></figcaption></figure>

***

#### 4. StageManager Component

1. Assign references:
   * **PoolRuntimeSO**: your pooling asset
   * **GlobalConfigSO** & **CommonStatRuntimeSO**: for curse scaling
   * **EnemySystem**: handles enemy registration
   * **PlayerSpawnChannelSO**, **StartStageEventChannelSO**, **VoidEventChannelSO**: hook up spawn and win events
   * **minSpawnRadius** / **maxSpawnRadius**: for Random pattern distances
2. At gameplay start, fire the **StartStageEvent** with your **StageConfigSO** during initialization.

The **StageManager** will:

* Sort **SpawnSets** by `StartTime`.
* For each set when time ≥ `StartTime`, spawn according to its `Pattern`:
  * **Random**: continuous spawning using `BaseRatePerSecond × IntensityCurve × Curse`.
  * **Circle**: one-off ring of `Count` enemies at `CircleRadius`.
  * **Dense**: one-off cluster of `Count` enemies around a random point.
* Stop after all sets finish and no enemies remain, then emit the **gameWin** event.

***

#### 5. Tips & Best Practices

* **Tuning Difficulty**: Adjust `IntensityCurve` shape to ramp up or ease difficulty.
* **Pattern Mix**: Combine `Random` for filler, `Circle` for surround challenges, `Dense` for targeted ambushes.
* **Reusability**: Duplicate `SpawnSet` assets to quickly create new stages.
* **Timing**: Overlap `StartTime`/`EndTime` to layer multiple sets in parallel.

With these steps, even beginners can set up rich, varied stages fully through the Inspector—no coding required!
