Skip to content

PixelWizards/com.pixelwizards.scenariospawner

Repository files navigation

Scenario Spawner Add-On

The Scenario Spawner is an extension for RuntimeSpawner that restricts spawning to a curated set of authored Scenario Points instead of arbitrary locations in the world.

It allows designers to maintain population targets for gameplay groups (such as enemies, pickups, or objectives) while ensuring entities appear only at specific spawn locations.

The system works by directing RuntimeSpawner to spawn entities at valid Scenario Points and tracking the resulting population so it can maintain configured targets.


Why This Exists

The default RuntimeSpawner is designed for systemic spawning. It can place entities anywhere within a valid region using placement hints, navmesh checks, and spawn rules.

However, many gameplay scenarios require controlled, designer-authored spawn locations.

Examples include:

  • guards spawning at specific patrol starts
  • loot containers appearing inside buildings
  • survivors spawning at rescue locations
  • enemies appearing at encounter entry points
  • mission objectives spawning at designated spots

The Scenario Spawner Add-On bridges this gap by maintaining spawn populations while limiting where spawns may occur.


Key Features

Spawn Point Restriction

Entities only spawn at registered Scenario Points placed in the scene.

Population Targets

Groups can define a TargetCount, and the system will spawn entities until that target is reached.

Point Categories

Scenario points are grouped by Category, allowing different spawn groups to use different sets of points.

Per-Point Cooldowns

Each point can enforce a respawn cooldown, preventing rapid repeated spawns at the same location.

RuntimeSpawner Integration

The system uses the existing RuntimeSpawner pipeline, meaning it inherits:

  • spawn entries
  • spawn rules
  • object pooling
  • spawn tags
  • placement logic

The add-on simply overrides the spawn location selection.


Core Concepts

Scenario Points

A Scenario Point represents an authored spawn location in the scene.

Each point defines:

  • PointId – unique identifier
  • Category – logical grouping of points
  • SpawnHint – transform used as the spawn position

Points automatically register themselves in the ScenarioPointRegistry so they can be discovered by the system at runtime.

Example:

WarehouseGuard_01
WarehouseGuard_02
RoofSniper_01
ParkingLot_01

Scenario Groups

A Scenario Group defines a population rule.

Example configuration:

GroupId: Guards
TargetCount: 6
PointCategory: Bots
RespawnCooldown: 15

Meaning:

  • Maintain 6 guards
  • Spawn only at Bots category scenario points
  • Enforce 15 seconds cooldown per point

Scenario Spawner

The ScenarioSpawnerAddon is the runtime driver.

It periodically:

  1. checks current population for each group
  2. determines how many entities need to spawn
  3. selects an available scenario point
  4. requests a spawn from RuntimeSpawner
  5. tracks the spawned entity

When an entity despawns or dies, the population count is reduced, allowing the system to refill the group later.


How It Works

The system runs a simple update loop.

Every tick:

for each group
    if alive < target
        select spawn entry
        select valid scenario point
        spawn entity

Spawn location selection is overridden by injecting a forced spawn hint into the RuntimeSpawner spawn context.

This allows RuntimeSpawner to handle the spawn while guaranteeing the location comes from the scenario system.


Typical Workflow

  1. Place ScenarioPoint components in the scene
  2. Assign each point a Category
  3. Configure ScenarioGroupConfig entries
  4. Add ScenarioSpawnerAddon to the scene
  5. Link it to a RuntimeSpawner

At runtime the system will automatically maintain the configured populations.


Example Setup

Scenario Points

GuardPoint_A
GuardPoint_B
GuardPoint_C
GuardPoint_D

Category:

Bots

Group Configuration

GroupId: Guards
TargetCount: 3
PointCategory: Bots
RespawnCooldown: 20

Runtime Behaviour

  1. System spawns 3 guards
  2. Player eliminates one
  3. After cooldown expires
  4. A new guard spawns at a valid guard point

When To Use Scenario Spawner

Use the Scenario Spawner when:

  • spawn locations must be controlled
  • encounters require designer-placed spawn points
  • gameplay readability is important
  • prototypes need predictable spawn locations

When Not To Use It

Do not use ScenarioSpawner when you want:

  • large systemic spawn regions
  • procedural world population
  • distance-based spawning around the player

In those cases the default RuntimeSpawner is more appropriate.


Relationship to RuntimeSpawner

RuntimeSpawner handles:

  • spawning logic
  • spawn entries
  • pooling
  • spawn validation

ScenarioSpawner handles:

  • where spawns are allowed to occur

This separation allows both systems to remain simple and reusable.


Future Extensions

The system is intentionally lightweight and can be extended with additional features such as:

  • weighted spawn point selection
  • distance checks against the player
  • spawn point occupancy tracking
  • round-robin point distribution
  • dynamic enabling/disabling of spawn points

License

Part of the MegaCrush RuntimeSpawner ecosystem.

About

No description, website, or topics provided.

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages