logo
EnemySpawner

shooter

EnemySpawner

1
Brood WardenBonus figureBrood Warden
Unlock

Install with the CLI:

bjs download EnemySpawner

EnemySpawner

Pulses pooled enemies out from its own position on a timer, up to a live cap.

What it does

On a timer (interval) the spawner places a new enemy at its own world position, up to a per-spawner live cap (maxAlive). It never creates entities itself — it emits pool.spawn naming its pool, and the Pool blueprint hands out a reused (pooled) enemy. The cap stays a true live count by tracking the pool's pool.spawned / pool.released events (a release covers both a normal kill and the pool recycling an enemy under pressure). Per-spawn hp/speed/color ride along on the spawn event for games that apply overrides on acquire.

Use it in a scene

A scene is just data — a list of entities, each with its components. At startup the SceneLoader turns this JSON into a live world; edit the file and reload to rebuild it.

Fastest path

bjs download scene EnemySpawner

Pulls this exact scene into your project and runs it — no copy-paste. Add --all to grab the components and assets it needs too.

Or build it from scratch with the bjs CLI:

  1. 1Scaffold a project
    npm create @babylonjsmarket/arcade@latest my-game

    World, renderer, and dev server — ready to run.

  2. 2Install dependencies
    cd my-game && npm install
  3. 3Add EnemySpawner
    bjs download EnemySpawner

    Copies its source into src/ so the scene resolves.

    First time? Run bjs login once.

  4. 4Paste the scene into src/scenes/arcade-room.ts and run
    npm run dev

    SceneLoader builds the world from the JSON; reload to rebuild.

JSON
{
  "Spawner_NW": {
    "components": {
      "MeshPrimitive": {
        "primitive": "cylinder", "diameter": 1.6, "height": 0.4, "position": [-15, 0.2, 15],
        "material": { "diffuseColor": [0.6, 0.1, 0.15] }
      },
      "EnemySpawner": { "interval": 1.2, "maxAlive": 6, "pool": "enemy" }
    }
  },
  "Enemies": {
    "tags": ["enemy"],
    "components": {
      "Pool": { "size": 8, "name": "enemy" },
      "MeshPrimitive": { "primitive": "sphere", "diameter": 1.2, "material": { "diffuseColor": [0.85, 0.25, 0.35] } },
      "Enemy": { "arenaHalfWidth": 19, "arenaHalfDepth": 19 },
      "Health": { "hp": 2, "maxHp": 2 }
    }
  }
}

Props

  • interval (number, default 1.2) — seconds between spawn pulses.
  • maxAlive (number, default 6) — live cap for this spawner.
  • pool (string, default "enemy") — name of the Pool blueprint to spawn from.
  • enemyHp (number, default 2) — hp passed along on each spawn.
  • enemySpeed (number, default 2.5) — speed passed along on each spawn.
  • enemyColor ([r,g,b], default [0.85, 0.25, 0.35]) — color passed along on each spawn.
  • enemyDiameter (number, default 1.2) — enemy diameter hint.

Events

  • emits pool.spawn (with its pool, position, spawnerId, hp/speed/color).
  • listens pool.spawned (bumps its live count) and pool.released (frees a slot).

Dependencies

MeshPrimitive — the spawner's own mesh, whose position is the spawn origin. Pool — the blueprint entity source; the spawner only requests spawns and counts them.

Notes

The live aliveIds set is non-serializable runtime state, kept in a WeakMap on the system rather than on the component. The scene must register a Pool blueprint under the same pool name (and that blueprint must carry Enemy + Health), or pool.spawn produces nothing.

More like this

MeshPrimitive
AIGoalSeek
AIKick
AIZone
AiDriver
AiPilot
Animation
ArcCamera
Asteroid
AsteroidField
BallPossession
BallPursuit
Bullet
CameraFollow
DeckDealer
DirectionalLight
Enemy
EnvironmentTexture
FreighterCar
FreighterChain
FreighterHead
GameConfig
Health
HemisphericLight
Jump
KeyboardInput
KeyboardMover
Lifetime
LineOfSight
MachineGun
Mesh
Missile
MissileLauncher
MissionDirector
MoneyField
MouseInput
Movement
Obstacle
ObstacleField
OilBlob
Parts
Physics
PlayerInput
PlayerWalkAnimator
PokerAI
PokerAIBill
PokerAICali
PokerAIRandy
PokerAIShark
PokerAISurge
PokerAITilt
RespawnTimer
RoadSpawner
RoundReset
Score
Shadow
ShipLoadout
ShooterCamera
SkeletonAnimator
SpaceShooterBullet
SpaceShooterHealth
SpaceShooterScore
TrafficConvoy
TwinStickEnemy
TwinStickShooter
WaveDirector
Waypoint
WaypointTrack

Was this page helpful?

We read every note — tell us what's working and what isn't.

↑↓ NavigateEnter SelectEsc CloseCtrl+K Open Search