Prefabs and instancing
Prefabs and instancing both give you many copies of something, but they solve different problems. Here is how to pick the right one.
| Option | What it copies | Each copy | Good for |
|---|---|---|---|
| Prefab | a group of objects | a real object you can move and edit; updates when you change the prefab | a chair used in twelve rooms |
| Instancing | one object's geometry | only drawn; you cannot edit it on its own | ten thousand blades of grass |
With the wrong choice, you either repeat the same edits over and over, or your scene gets slow.
Prefabs
A prefab is a saved group of objects that you can add to scenes again and again. For example: a lamp with its light and glow, a door with its frame and sound, or a fully rigged character.
When you change the prefab, every copy of it updates. You fix the door handle once, not in twelve rooms.
Each copy is a real part of your scene. You can move it, and you can change settings that apply only where it sits.
As soon as you copy a small group of objects for the second time, make it a prefab. If you wait until you have twelve copies, you will have to reconcile twelve sets of small differences.
Instancing
Instancing shows one object's geometry many times. A thousand copies cost about as much as one. This is what makes grass fields, crowds, asteroid belts and forests possible.
You can arrange the copies in three ways:
grid: in a regular grid. Add jitter to make it look less regular.scatter: spread loosely through a box or a sphere.children: one copy at the position of each child object.
Use children to speed up objects you placed by hand. Place them where you want them, then switch
children on. While it is on, a copy is shown in place of each child.
Make copies look different
All copies share the same geometry, so by default they look identical and repetitive. These settings add variety:
scaleMin·scaleMax: each copy gets a random size between the two.rotationJitter: each copy gets a random rotation.colorA·colorB: each copy gets a tint between the two colours.
For more variety, a material graph can read which copy is being drawn and change anything based on it. For example, each copy can sway at a different moment, look more or less worn, or show a different pattern.
The count, the shape and the seed produce the same arrangement everywhere: in the editor, on a
phone and for everyone in a multiplayer room. Ten thousand copies add no network traffic.
Change the seed to get a different arrangement with the same settings.
maxCount limits the number of copies. Copies above it are not drawn, so a typo in the count
cannot make the engine try to use an impossible amount of memory.
Next: Loading — what loads before your scene opens, and the launch screen.