In Unity’s PrefabAn asset type that allows you to store a GameObject complete with components and properties. The prefab acts as a template from which you can create new object instances in the scene. More info
See in Glossary system, Prefab Assets act as templates. You create Prefab Assets in the Editor, and they are saved as an Asset in the Project window. From Prefab Assets, you can create any number of Prefab instances. Prefab instances can either be created in the editor and saved as part of your ScenesA Scene contains the environments and menus of your game. Think of each unique Scene file as a unique level. In each Scene, you place your environments, obstacles, and decorations, essentially designing and building your game in pieces. More info
See in Glossary, or instantiated at runtime.
To create a Prefab Asset, drag a GameObjectThe fundamental object in Unity scenes, which can represent characters, props, scenery, cameras, waypoints, and more. A GameObject’s functionality is defined by the Components attached to it. More info
See in Glossary from the Hierarchy window into the Project window. The GameObject, and all its components and child GameObjects, becomes a new Asset in your Project window. Prefabs Assets in the Project window are shown with a thumbnail view of the GameObject, or the blue cube Prefab icon, depending on how you have set up your Project window.
This process of creating the Prefab Asset also turns the original GameObject into a Prefab instance. It is now an instance of the newly created Prefab Asset. Prefab instances are shown in the Hierarchy in blue text, and the root GameObject of the Prefab is shown with the blue cube Prefab icon, instead of the red, green and blue GameObject icon.
You can create instances of the Prefab Asset in the Editor by dragging the Prefab Asset from the Project viewA view that shows the contents of your Assets folder (Project tab) More info
See in Glossary to the Hierarchy or Scene viewAn interactive view into the world you are creating. You use the Scene View to select and position scenery, characters, cameras, lights, and all other types of Game Object. More info
See in Glossary.
You can also create instances of Prefabs at runtime using scripting. For more information, see Instantiating Prefabs.
You can replace a Prefab by dragging a new GameObject from the Hierarchy window and dropping it on top of an existing Prefab asset in the Project window.
If you are replacing an existing Prefab, Unity tries to preserve references to the Prefab itself and the individual parts of the Prefab such as child GameObjects and Components. To do this, it matches the names of GameObjects between the new Prefab and the existing Prefab that you are replacing.
Note: Because this matching is done by name only, if there are multiple GameObjects with the same name in the Prefab’s hierarchy, it is not possible to predict which will be matched. Therefore if you need to ensure your references are preserved when saving over an existing prefab, you must ensure all GameObjects within the Prefab have unique names.
Also note: You may encounter a similar problem in the case of preserving references to existing Components when you save over an existing Prefab, if a single GameObject within the Prefab has more than one of the same Component type attached. In this case it is not possible to predict which of them will be matched to the existing references.
2018–07–31 Page published
Nested Prefabs and Prefab Variants added in 2018.3
Did you find this page useful? Please give it a rating: