fbpx
What are prefabs and nested prefabs?2019-03-13T07:07:04+00:00

Guides

Be an expert with our advanced guides and build beautiful high-quality games.
Get a head start and receive knowledge directly to your inbox:

Expert Workflows

“I am constantly updating and extending this guide. Let me know in the comments what you would like to know about!”
– Max

What are prefabs and nested prefabs?

Written by Max Plooi
Creator of Nested Prefabs for Unity

What is a prefab?

Prefabs are collections of game objects that can be reused. Prefabs are saved in your project as an asset and share their data between all places where the prefabs are reused. If you change a prefab and save it, then all other instances of that prefab are updated with the same changes as well.

This is useful for objects that are used often throughout your game or level. Such as doors, windows, houses, weapons, bullets, etc.

How does that work?

All prefab instances in your scene are “empty” game objects that contain a reference to the prefab asset. All the data for the instances are saved in the prefab asset and not in the scene.

This means that the prefab instances in your scene directly show and use the data from the prefab asset. So if you edit the data in the prefab asset, then all instances automatically use those changes as well.

And what about nested prefabs?

A nested prefab is a prefab that is placed inside another prefab. Such as a window prefab inside a house prefab. By nesting prefabs, you can create larger and more complex structures.

These nested prefabs are still connected to their original prefab asset. So they are automatically updated if you modify the original prefab, even though the nested prefab is saved within a different prefab.

The data for nested prefabs is stored in the same way as prefab instances. The nested prefab only stores a reference to the original prefab asset and does not store any data itself.

The prefab system in Unity 2018.3 has been overhauled to make it easier to nest prefabs. In previous versions of Unity you must download an additional package to nest prefabs.

Creating prefabs

Continue to the next article to learn how to create prefabs.

Get a head start

Become an expert by reading more of our advanced guides and build beautiful high-quality games. Get a head start and receive knowledge directly to your inbox:

Your thoughts

Let us know what you think. If you have any feedback, ideas, or just something awesome to say. We would love to start a conversation with you: