Prefabs can be used to bundle a group of assets together (vehicles, static objects, triggers, etc.) so that they can be loaded or unloaded at any time while a level is running. They can also be used as a template, allowing you to copy and paste a group of objects easily. Prefabs can be saved and loaded in two formats: .prefab
, and .prefab.json
. Currently, .prefab
is recommended.
Prefabs can be in a packed or unpacked state. A packed prefab is compiled and ready for the game to use; an unpacked prefab is basically in edit mode, and you can modify its contents. Repacking an unpacked prefab automatically saves the prefab file.
Overview
In the Scenetree, prefabs will look like this, with a package icon:
Right-click on a prefab, and select Unpack Prefab to make it usable for editing:
Right-click on the unpacked prefab, and select Pack Prefab to update and save it.
Editing
New Prefab
Here is how to create a new prefab:
-
Place some objects that you want to use in the world. If you need more info about how to do this, see Asset Browser .
-
When you are done, select those objects. You can select multiple objects in the Scenetree by holding down CTRL or SHIFT, and then left-clicking the object names in the Scenetree.
-
Right-click on any selected object in the Scenetree and select Put Into New Group.
You can actually pack the prefab at this step. However, it is recommended to have your objects in a group folder first, so that it will have no position offset when the prefab is created. This will save some trouble if you are making a prefab for a mission.
-
Right-click on the newly created group folder and select Pack Prefab.
Existing Prefab
Here is how to load an existing prefab, if it is not already present in the Scenetree.
-
Open the Asset Browser. For more info about this, see Asset Browser .
-
Browse for the prefab that you would like to load.
-
Right-click on the prefab file and select Spawn Prefab at Origin. This will load the prefab and its objects at the intended position.
-
Now you can unpack, edit, and repack the prefab by interacting with it in the Scenetree. Remember, packing the prefab will automatically save it; you do not need to save the level.