Skip to content

Prefabs and spawning

Prefabs let you save a configured object and reuse it. They are how you avoid rebuilding the same enemy, pickup, projectile, door, or UI widget over and over.

In Opal, prefab-like assets are stored in the library as blueprints.

What a prefab keeps

A prefab can include:

DataExamples
Object hierarchyParent object, child sprites, markers, hitboxes
Inspector fieldsName, visibility, interaction, transform defaults
ComponentsHealth, Collider 2D, Inventory, Spawner, custom components
Object variablesPer-object state declarations
Object FlowOn Tap, collision, custom event rules
AnimationMotion clips and skeleton references

Use prefabs whenever the same object appears more than once or must be spawned during play.

Save a prefab

  1. Select an object in Arrange.
  2. Configure its children, components, variables, motion, and Object Flow.
  3. Use the prefab action in the inspector to save it.
  4. Find the result in the library, usually under Blueprints.

Name the prefab by role:

WeakBetter
thingCoinPickup
enemySlimeEnemy
doorDoorToLevel2
buttonRetryButton

Place prefab instances

Place a prefab from the asset library like any other asset. The new scene object starts with the prefab's saved configuration.

Good uses:

  • Coins and pickups
  • Enemy variants
  • Projectiles
  • Reusable UI controls
  • Door/portal objects
  • Spawn markers
  • Hazards and traps

Instance overrides

After placing an instance, you can change it for that scene.

Common overrides:

OverrideExample
TransformPut this coin at a different position
Component fieldGive one slime more HP
Variable defaultSet this door target to Level 3
VisibilityHide a bonus item until unlocked

Use manual sync when an instance should stop following prefab updates. Use revert controls when an instance should return to the prefab defaults.

Update a prefab

When you improve the source object, update the prefab so future instances and auto-synced existing instances share the change.

Safe update workflow:

  1. Duplicate a scene or export a backup first.
  2. Change one source object.
  3. Update the prefab.
  4. Check a few existing instances.
  5. Play-test.

Large prefab updates can affect many scenes, so treat them like a real content change.

Spawn from Object Flow

Use the Spawn Object action to create a prefab during play.

Common graph:

text
On Timer
  -> Spawn Object (SlimeEnemy)

or:

text
On Tap
  -> Spawn Object (Projectile)
  -> Play Audio

Pick the prefab from the node field. Set position or offset fields where available so the spawned object appears at the source, target, or marker you expect.

Spawn with the Spawner component

The Spawner component periodically creates a prefab at the object's position.

Use it for:

  • Enemy waves
  • Falling obstacles
  • Repeating pickups
  • Particle-like object bursts
  • Test scenes that need automatic content

Typical fields include the prefab to spawn, interval, spawn-on-start behavior, and maximum spawn count. Attach the component to an empty marker object when you want a clean spawn point.

Prefab design patterns

PatternStructure
PickupSprite + Pickup (or On Tap Flow) + GameState / inventory write + VFX + Destroy
EnemyParent group + sprite + Health + Collider 2D + Motion + Object Flow
DoorSprite + Collider sensor + target scene variable + Go To Scene
ProjectileSprite + Projectile + dynamic Rigid Body 2D (CCD) + Collider 2D
SpawnerEmpty object + Spawner component + optional visual marker hidden in play

Debugging prefab issues

If a prefab instance behaves strangely:

  1. Select the instance and check whether it is auto-synced or manual.
  2. Compare instance component fields against the prefab.
  3. Check child objects, not just the root.
  4. Verify the prefab asset still exists in the library.
  5. Use Graph Explorer's prefab anatomy view for complex templates.

Opal Engine — MIT licensed