Unity reusable objects named Prefabs

by Lance Gold

A prefab is a game object that can be created over and over again to use in the game, instantiated at runtime.

Return to index

Here is a basic primitive, a capsule, ready to be put into play over and over again.

Laser game object created for use as Prefab object

Laser game object created for use as Prefab object

Create a new ‘Assets’ folder to hold the ‘Prefabs’ game objects

New folder in Assets to be named Prefabs

New folder in Assets to be named Prefabs

Hover click and drag the game object (‘Laser’) down from the Hierarchy to the Project Assets Prefabs folder.

Game object dragged into Prefabs folder

Game object dragged into Prefabs folder

The ‘Prefabs’ name for a folder is special. Notice the color of the ‘Laser’ object changed to blue after its addition to the ‘Prefabs’ folder.

Object in Prefabs folder changes color to blue in Hierarchy

Object in Prefabs folder changes color to blue in Hierarchy

Next step is to set duplicates of the prefab object to be created with same material components

Add a Component material. Here Rigidbody is added, ‘ri’ in Search to start.

Add Rigidbody Component

Add Rigidbody Component

All the materials can be Overridden to Laser copies, or…

Override with Apply All

Override with Apply All

Materials can be chosen one by one to Override to object copies.

Override with ‘Use Gravity’ unchecked

Override with ‘Use Gravity’ unchecked

There is a way to isolate the view to the prefab object. Click highlight the object in the Hierarchy and click on ‘Open’ in the Inspector.

‘Open’ in Inspector for prefab view

‘Open’ in Inspector for prefab view

Some components are not visible in the Inspector during prefab view, such as Rigidbody.

Exit the prefab object's view with a click in the Hierarchy frame on the ‘<’.

Exit object's view

Exit object’s view

To remove a component from a series of prefab objects, click the 3-dot icon for the menu. Click the name, ‘Rigidbody’ in this case, and click ‘Apply All’.

Remove a component from multiple prefab objects

Remove a component from multiple prefab objects

Now add a material to the prefab. in the Material folder, not the Prefabs folder.

New Laser material

New Laser material

Add color.

Color change

Color change

Click and drag material onto Laser object in Hierarchy (not to prefabs). This is a new component to the prefab object, so click on the Overrides menu and ‘Apply All’ again.