Skip to main content

Prefabs and instancing

Both let you have many of something. They solve completely different problems, and choosing the wrong one is a common source of either tedium or slow scenes.

PrefabInstancing
Copiesa tree of objectsone object's geometry
Each copyfully independent, editabledrawn only, not editable
Good fora chair used in twelve roomsten thousand blades of grass
Edit once, update everywhereyesn/a — they are all the same object

Prefabs

A prefab is a saved tree of objects you can drop into scenes again and again: a lamp with its light and its glow, a door with its frame and its sound, a fully rigged character.

Change the prefab and every instance of it updates. That is the whole point — you fix the door handle once, not in twelve rooms.

Each instance is a real part of your scene: you can move it, and you can change things on it that are specific to where it sits.

Build the second one as a prefab, not the fifth

The moment you catch yourself copying a small group of objects for the second time, make it a prefab. Retrofitting one after you have twelve scattered copies means reconciling twelve sets of small differences.

Instancing

Instancing draws one object's geometry many times in a single call. A thousand copies cost roughly what one does, which is what makes grass fields, crowds, asteroid belts and forests possible at all.

Three ways to arrange the copies:

SourceArranges them
gridon a regular lattice, with optional jitter to break up the regularity
scatterloosely through a box or a sphere
childrenone copy per child object, at each child's position

The children source is the "make this fast" option: place things by hand where you want them, then switch it on and they collapse into a single draw. The children stop drawing themselves while it is on.

Making copies look different

Copies are the same geometry, so without help they look identical and read as wallpaper. Three settings break that up:

SettingEffect
scaleMin · scaleMaxeach copy takes a random size between them
rotationJittereach copy gets a random spin
colorA · colorBeach copy takes a tint between the two

For more than that, a material graph can read which copy is being drawn and vary anything you like from it — swaying at a different phase, a different worn-ness, a different pattern.

The arrangement is generated, never stored

A count, a shape and a seed produce the same arrangement everywhere — in the editor, on a phone, for every participant in a multiplayer room. Nothing is synchronised, so ten thousand copies cost nothing on the network.

Change the seed for a different arrangement from the same settings.

maxCount is a safety rail: copies beyond it are not drawn, so a slipped digit cannot try to allocate an impossible amount of memory.


Next: Loading and the launch screen