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.

Customize a prefab from its root ​

Expose the settings people need most, such as a vehicle's wheel motor speed or an enemy's health, in a Prefab properties panel on the root object.

  1. Select a prefab instance and choose Actions → Edit Prefab.
  2. Select the prefab origin. In Prefab properties, choose an object/component field, give it a clear label, and add it.
  3. Save and exit prefab editing.
  4. Select a placed instance's root to edit those settings without finding its children.

Each control edits the actual component field and supports undo. Reset restores that instance's prefab default. Exposed overrides survive prefab updates; untouched controls inherit the new defaults. Other component settings follow the usual prefab update behavior. Controls are read-only during Play; tune live values through their component cards.

You can expose editable, saved component settings. If a source object or component is removed, its control explains the missing source. Recreate the source or remove the entry in prefab editing.

Update a prefab ​

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

Update workflow:

  1. Choose Edit Prefab from a placed instance or the asset library.
  2. Change the prefab on its isolated stage.
  3. Save and exit to update the linked instances in the current scene.
  4. Check the instance overrides and 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.

Spawning is immediate: loading a scene preloads every prefab it names (Spawn Object nodes, Spawner components, script Asset properties, and whatever those prefabs name in turn), so the new object exists when the next node or script line runs. A prefab a scene never names (an id computed at runtime) still spawns once it loads, a frame or so late, and Problems / the console say so — reference it from the scene to preload it.

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.