logo

Babylon.js Market

By Lawrence

5 minutes

An empty road at thirty units a second looks identical to an empty road at rest. Traffic is what turns the ribbon into a place. But a spawner bolted to a pad cannot supply it: a pad picks a spawn point once and it is still a spawn point a minute later, whereas the only stretch of road worth putting a car on is the one you are about to reach — and that stretch moves at whatever speed you are doing.

A blueprint entity is a pool

Cars appear and disappear continuously, which is the exact workload that must never go through createEntity and removeEntity. At one car every 1.1 seconds, that is fifty-odd entities and their meshes built and thrown away every minute, for as long as anyone plays. The free Pool component turns the whole stream into twelve entities:

@babylonjsmarket/arcade/src/Components/Pool/Pool.core.ts
/**
 * Marks its host entity as a pool blueprint. The host's other components are the
 * template each pooled instance carries; this component itself is never copied
 * onto an instance.
 */
export class PoolComponent extends Component {
  /** Empty string means "use the blueprint entity's id as the pool name". */
  name: string
  size: number

  constructor(data: PoolInput = {}) {
    super()
    this.name = data.name ?? ''
    this.size = data.size ?? 16
  }

  serialize(): PoolInput {
    return { name: this.name || undefined, size: this.size }
  }
}

Two fields, and the interesting one is the one that isn't there. A Pool marker says nothing about what it holds. The blueprint's other components are the template — declared as ordinary top-level scene keys, so their Systems register through the normal scene-load path and a pooled car's CarDrive runs with no extra wiring.

Continue reading

Unlock the Full Course

Every lesson, the runnable examples, and the finished build — yours to keep.

$9one-time

Was this page helpful?

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

↑↓ NavigateEnter SelectEsc CloseCtrl+K Open Search