Prefabs
Last updated
Last updated
Prefabs are a tool that helps with management and optimization of a space by creating assets that work much like a template object. When you update the Prefab, all assets in your space will be updated as well.
If you plan on using the one asset in multiple places in your environment, then it is recommended to use Prefabs to do so.
This improves performance as well as prefabs placed in a space act like instances of the asset, which allows Unity to render them to the space with less resources than if you placed the same model in the space manually.
Setting up a prefab is as easy as dragging the asset from the Hierarchy to the Project folder. It's recommended to have a folder in your Project labelled Prefabs, and then drag your assets into that.
There are several ways to update a prefab, and therefore all the assets in the space that use that prefab. Which one you choose completely depends on your process, but will basically come down to two results, editing in Context and editing in Isolation.
In Context will open the prefab in the space, so you can see the space around the asset if that is important or useful to visualise next to the asset.
In Isolation will open the prefab in it's own space, so you know exactly what is included in the Prefab itself.
Right mouse click the prefab asset in the Hierarchy, and use either :
Prefab > Open Asset in Context
Prefab > Open Asset in Isolation
This will open the asset itself allowing you to edit it as you see fit. Once you return to the main space (at the top left) all instances of the Prefab will also be updated.
Click on the arrow to the right of the asset in the Hierarchy to open the asset in context. If you hold the Alt key it will open in Isolation.
It is possible to update the Prefab after you have edited the asset in the space using the Overrides pulldown at the top right of the Inspector on the prefab itself with the blue box (not the asset you have edited if it is a child of the prefab).
It is also possible to revert back to the original prefab if you do not like the changes you have applied.
Double click the Prefab in the Project to open it in Isolation.
Use the Open button on the prefab at the top of the inspector. It is also possible to select the Prefab asset in the Project with the Select button next to it if required.
After you have edited your Prefab, you can usually return to the Space itself by using the Top Left of the Space window.
Occasionally you may want to remove an asset from the Prefab itself. You do this by Right clicking on the gameobject in question and use :
Prefab > Unpack
Prefab > Unpack Completely
Unpack Completely will remove all prefabs within the asset, whereas Unpack will remove the links to the prefab on the gameobject in question.
This is useful on assets that produce a warning about editing Prefabs or Nested prefabs, and removes the warning. However note that the asset is no longer a prefab, and will not benefit from their advantages unless you make it a prefab again and use it as the Template.
It is possible to make variations on Prefabs without updating the prefab itself. These are done using what are called Overrides, and can be applied to the following elements of a Prefab.
Overriding the value of a property
Adding a component
Removing a component
Adding a child GameObject
To do this all you have to do is modify the asset directly and then make sure you do NOT update the prefab itself. Any overrides to the prefab will be visible in bold, and the Prefab icon (the blue box) may have a Plus on it notifying you that the asset has been modified.
An overridden property will always have priority over updates you make to the original prefab.