Prefabs and instances
One file, placed many times
Section titled “One file, placed many times”A prefabprefab: A level built to be placed many times. Each placement is an instance, and its entities become children of the entity that places it. is a level built to be placed: a teleport pad, a lamp post, a parked car. There’s no
special prefab file. It’s an ordinary level, and placing it is a component: an entity with a prefab component
naming the level.
When the game spawns that entity, it builds the prefab’s entities underneath it, positioned from it. Each placement is an instanceinstance: One placement of a prefab. Every instance builds the same entities; each can change a few of their values with patches..
- Teleporters
- tp_pair_plazatransformprefabplaces teleport_pair.level
- pad_atransformmodelbox_trigger
- pad_btransformmodelbox_trigger
- tp_pair_garagetransformprefabplaces the same file again
- pad_atransformmodelbox_triggerpatched: cooldown
- pad_btransformmodelbox_trigger
So you edit a prefab once. Fix the pad in its own file and every placement of it, on every map, is fixed the next time the game runs.
Why instanced rows are read-only
Section titled “Why instanced rows are read-only”Open a map in Studio and select a prop, and most of the time the Inspector says:
Instanced from a prefab — open the prefab level to change it.
The prop isn’t stored in this level. The level only holds the placing entity; the prop is built from another file. An edit here would have nowhere to go, so Studio offers three things that do:
- Change the prefab for every placement: Entity▸Open Prefab opens its file.
- Change this one copy: patch it (below).
- Move the whole placement: select the placing entity, the one with the
prefabcomponent, and move that.
Patches: one copy, a little different
Section titled “Patches: one copy, a little different”A patchpatch: A change one prefab instance makes to a value inside it, without editing the prefab itself or any other instance. is a change one instance makes to a value inside it, without touching the prefab or any other instance. It’s how fifty copies of one prop become fifty different props: the same crate in fifty colours, the same pad with fifty destinations.
In Studio, you patch by editing the value where you see it. Where the placing entity is allowed to patch a field, the instanced row’s field is editable, and your edit is saved on the placing entity, not in the prefab. A dot marks a patched field; its reset arrow removes the patch and the value goes back to what the prefab says.
Prefabs inside prefabs
Section titled “Prefabs inside prefabs”Prefabs nest: a car prefab can place a wheel prefab four times. The rules are the same at every level, so an instance’s instances are read-only too, and a patch can reach into them.
Some placements are conditional: they only build their prefab when the match’s rules call for it. A map holds its mode-specific content this way (the basketball hoops, the flagpole, the treasure-hunt spawners) and only shows it in the modes that use it.
Making your own
Section titled “Making your own”Build something once in a level, then turn it into a prefab to place again:
- Select the entities that belong together. The last one you pick is the pivot: it ends up at the prefab’s origin, and everything else keeps its place around it.
- Entity▸Make Prefab… writes them into a new level file and puts one instance of it where they stood.
- Drag the new level from the Project window into any level to place it again.
Studio refuses a few selections, each for a reason: nothing selected; a row that’s itself inside a placed prefab (select the placing entity instead); entities under different parents; or a selection that points at something outside itself, which the new file couldn’t reach.
For programmers
A prefab is an ordinary level instanced by a prefab component: at spawn the engine spawns that level with the
host entity as parent. Instanced entities keep the prefab’s IDs, which repeat across placements. A patch is a
per-instance override stored on the host, keyed by the target component’s ID and a field name; the engine applies
it while the instance expands.
Where to go next
Section titled “Where to go next”Layers: one map file holds every season at once, and layers pick which one you see.