Skip to content

Load a scene built from prefabs

quick start Beginner ⏱ 6 min vgai 0.1.0

Prerequisites: Installed vgai and run the editor

What you'll learn

  • Load and run a .vscn scene
  • See prefab instances spawned by the scene loader
  • Understand the spawn → joints → init load order

What you'll build: A look at how a scene of prefab instances loads and runs.

Walkthrough — Load a scene built from prefabs · generated by site/media/lessons/scenes2-batch.lesson.ts (4 steps)

A scene (.vscn.json) is a tree of entities; many can be prefab instances of a reusable template. The RTS scene’s units are prefab instances — a good scene to watch load.

  1. Open a scene built from prefab instances. Load examples/scenes/rts.vscn.json.

    The rts scene loaded
    A scene of prefab-instance units.
  2. Enter play mode — the scene loader spawns every entity. The loader runs three passes: spawn all entities (building an id → Object3D map), create joints, then run every component’s init().

    The scene running after load
    The three-pass loader has spawned the scene.
  3. Prefab unit instances populate the scene. Each unit is a .prefab.json instance, merged with any per-instance overrides; shared default values come from one defaults table so the editor preview matches the runtime.

    Prefab units in the running scene
    Prefab instances populate the arena.
  4. Stop play mode. Press Stop (or Escape).

Recap

New functionality

  • Loaded and ran a prefab-based scene
  • Saw prefab instances spawned

New concepts & skills

  • A scene is a tree of entities; prefab instances reuse a template
  • The loader runs spawn → joints → initAll
  • Shared defaults keep editor and runtime in sync

Next lesson → Manual: Scenes & prefabs

On Your Own!

Extend what you built:

  • Open a .prefab.json and change a field — every instance updates
  • Override a single instance's transform without touching the prefab
  • Read the three-pass loader detail in the manual