Prefabs
Prefabs… When I think of Prefab, I think of a prefabricated structures that are already constructed with desired load capacity, design, and length. When needed, those prefabricated structures are transported to the site and installed. Similarly, if you have a GameObject that is fully configured, or have all the desired components in it, you can save that object as a Prefab. This prefab can then be reused as needed in the project. It can be shared between two game scenes, or between two projects without having to edit anything. Just Drag and Drop!! Easy, right!
Another beneficial use of Prefabs is that if you edit original Prefab then it automatically changes the attributes of the respective instances in the project.
How to Create a Prefab?
Once an object is configured, to create a Prefab, you can simply drag and drop the object from the Hierarchy Window into Project Window (Figure 1).
Prefabs are saved as *.prefab file format.
Figure 1. Creating a Prefab
How to Identify a Prefab in Hierarchy Window?
When prefabs are included in Hierarchy window, they appear as a blue text with a blue cube icon on the left (Figure 2).
Figure 2. Prefabs in Hierarchy
Take a Closer Look at Inspector Window!
When a prefab is created, new options in the inspector window appear (Figure 3).
Figure 3. New buttons in Prefab
Editing Prefabs!
A single instance of a Prefab can be edited as per the requirement of the project
The changes made in an instance of a Prefab can be applied to all instances.
Open Button: opens the prefab window, where changes can be made to that instance of the Prefab
Select Button: It highlights the original Prefab in the Project window from which that instance was created (Figure 4)
Overrides dropdown shows all the changes made to a prefab. Once the change is made, it will give you two options, Revert All and Apply All
Revert All: to revert all the changes shown in the override list
Apply All: to apply all the changes made to prefab. This change will be applied to all the instances.