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.
| Prefab | Instancing | |
|---|---|---|
| Copies | a tree of objects | one object's geometry |
| Each copy | fully independent, editable | drawn only, not editable |
| Good for | a chair used in twelve rooms | ten thousand blades of grass |
| Edit once, update everywhere | yes | n/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.
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:
| Source | Arranges them |
|---|---|
grid | on a regular lattice, with optional jitter to break up the regularity |
scatter | loosely through a box or a sphere |
children | one 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:
| Setting | Effect |
|---|---|
scaleMin · scaleMax | each copy takes a random size between them |
rotationJitter | each copy gets a random spin |
colorA · colorB | each 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.
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.