Making games

Prefabs

A prefab is an object, with its children and components, saved as a file (.ofab) so you can place it as many times as you like. A crate, an enemy, a streetlight, a whole building: make it once, then use it everywhere.

Making one

Right-click an object in the Hierarchy and choose Save as Prefab…. The object and everything under it are written to the file you pick, and the object in the scene becomes the first instance of the prefab.

Importing a model makes a prefab of its objects for you; see Projects and assets.

Placing it

Find the prefab in the Assets panel and click the + on its row. A new instance is placed in the scene and selected.

Changing one instance

Edit an instance like any object. A property you change on an instance is an override: that instance keeps your value, and the rest still follow the prefab. Right-click the instance in the Hierarchy for what to do with them:

ChoiceWhat it does
Apply Prefab OverridesWrites this instance’s changes into the prefab, so every instance gets them.
Revert Prefab OverridesThrows this instance’s changes away; it’s the prefab again.
Unpack PrefabTurns the instance into ordinary objects with no link to the prefab.

The Hierarchy filter is:prefab lists every instance in the scene.

Spawning from a script

Scene.spawn places a prefab while the game runs, by its address:

fn drop_crate() {
    Scene.spawn("assets://prefabs/crate.ofab", self.position)
}

fn on_ready() {
    self.every(3.0, drop_crate)
}

It gives back a handle to the new object, like Scene.find does. See Working with objects.