Unity prefabs (short for prefabricated object) allow you to create, store, and modify GameObjects as reusable assets together with all its components, property values, and child GameObjects. Prefabs are easily created by dragging an object from the scene Hierarchy window into the Project window, or they may be imported as part of a Unity asset package. You can read more about prefabs in the Unity Manual at https://docs.unity3d.com/Manual/Prefabs.html.
Let's see how this works by creating a simple reusable model built from simple geometric elements.
Creating and instantiating a prefab
We're going to create a reusable character prefab named BobHead. First, let's build the little guy from a few primitive 3D objects, as follows:
- In the Hierarchy, create an empty GameObject named BobHead (by clicking on +| Create Empty; name it BobHead).
- Set its position to something like Position (3, 0.75, 1.25). ...