logo

Babylon.js Market

Flash

vfx

Flash

Free

Install with the CLI:

bjs download Flash

Flash

A short-lived entity that pops for a moment, then removes itself.

What it does

Flash is data-only: it holds a single lifetime countdown in seconds. Each frame FlashSystem subtracts dt from lifetime, and the instant it hits zero the system removes the whole host entity from the world. There is no fade, no animation, and no event — the effect is "brief, bright, gone." The system requires both Flash and MeshPrimitive on the entity, so a flash always has geometry to render, and bare Flash: {} marker entities (used elsewhere just to make SceneLoader instantiate the system) are never matched and destroyed. You spawn a flash from another system — muzzle fire, an impact burst, a pickup pop — by creating an entity with an emissive MeshPrimitive plus a Flash set to a small lifetime, and let the timer clean it up.

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.

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 Flash
    bjs download Flash

    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
{
  "MuzzleFlash": {
    "components": {
      "MeshPrimitive": {
        "primitive": "sphere",
        "diameter": 0.7,
        "segments": 8,
        "position": [0, 1, 0],
        "material": { "diffuseColor": [1, 1, 0.6], "emissiveColor": [1, 1, 0.6] }
      },
      "Flash": { "lifetime": 0.08 }
    }
  }
}

Props

  • lifetime (number, default 0.08) — seconds before the host entity is removed. The system decrements it by dt each frame and removes the entity when it reaches 0.

Events

None. Flash is event-silent — it neither emits nor listens; it only ticks its own timer and removes the entity.

Dependencies

None declared in dependencies, but FlashSystem requires a MeshPrimitive component on the same entity (it queries [FlashComponent, MeshPrimitiveComponent]). Without a MeshPrimitive sibling the entity is never matched, so it neither renders nor gets cleaned up.

Notes

  • The countdown is frame-rate independent — it subtracts real elapsed dt, so lifetime: 0.08 is roughly 80 ms regardless of frame rate.
  • Removal is all-or-nothing: when the timer expires the entire entity is removed, including its MeshPrimitive, so the visual disappears with it. Flash is not a "hide" — don't attach it to something you want to keep.
  • Because a flash is usually spawned in code (e.g. world.createEntity() then add a MeshPrimitive and a FlashComponent), the scene-JSON form above is mainly for demoing the effect; in a real game you emit them dynamically at impact points.
  • serialize() round-trips just { lifetime }, so a flash in flight survives a save/load with its remaining time intact.

Was this page helpful?

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

↑↓ NavigateEnter SelectEsc CloseCtrl+K Open Search