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:
| Data | Examples |
|---|---|
| Object hierarchy | Parent object, child sprites, markers, hitboxes |
| Inspector fields | Name, visibility, interaction, transform defaults |
| Components | Health, Collider 2D, Inventory, Spawner, custom components |
| Object variables | Per-object state declarations |
| Object Flow | On Tap, collision, custom event rules |
| Animation | Motion clips and skeleton references |
Use prefabs whenever the same object appears more than once or must be spawned during play.
Save a prefab
- Select an object in Arrange.
- Configure its children, components, variables, motion, and Object Flow.
- Use the prefab action in the inspector to save it.
- Find the result in the library, usually under Blueprints.
Name the prefab by role:
| Weak | Better |
|---|---|
thing | CoinPickup |
enemy | SlimeEnemy |
door | DoorToLevel2 |
button | RetryButton |
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:
| Override | Example |
|---|---|
| Transform | Put this coin at a different position |
| Component field | Give one slime more HP |
| Variable default | Set this door target to Level 3 |
| Visibility | Hide 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.
- Select a prefab instance and choose Actions → Edit Prefab.
- Select the prefab origin. In Prefab properties, choose an object/component field, give it a clear label, and add it.
- Save and exit prefab editing.
- 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:
- Choose Edit Prefab from a placed instance or the asset library.
- Change the prefab on its isolated stage.
- Save and exit to update the linked instances in the current scene.
- 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:
On Timer
-> Spawn Object (SlimeEnemy)or:
On Tap
-> Spawn Object (Projectile)
-> Play AudioPick 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
| Pattern | Structure |
|---|---|
| Pickup | Sprite + Pickup (or On Tap Flow) + GameState / inventory write + VFX + Destroy |
| Enemy | Parent group + sprite + Health + Collider 2D + Motion + Object Flow |
| Door | Sprite + Collider sensor + target scene variable + Go To Scene |
| Projectile | Sprite + Projectile + dynamic Rigid Body 2D (CCD) + Collider 2D |
| Spawner | Empty object + Spawner component + optional visual marker hidden in play |
Debugging prefab issues
If a prefab instance behaves strangely:
- Select the instance and check whether it is auto-synced or manual.
- Compare instance component fields against the prefab.
- Check child objects, not just the root.
- Verify the prefab asset still exists in the library.
- Use Graph Explorer's prefab anatomy view for complex templates.