Using Prototypes and Prefabs to Create Similar Game Objects

Often, you want to create a large number of identical objects: a set of cars, a battalion of soldiers, or trees in a forest. Prototype and prefab assets provide a convenient way to make multiple objects that are identical. The LevelEditor treats a prototype or prefab asset as any other game resource or asset, and you can place as many of the prototype or prefab assets in the world as you need. The following table describes the similarities and differences between prototype assets and prefab assets.

Prototype Assets

Prefab Assets

When you drag and drop a prototype asset to the Design View, LevelEditor creates a copy of the base prototype object as the newly created object.

If you edit the properties of a base prototype asset, those changes do not affect any instances (copies) of that prototype in the game level.

When you drag and drop a prefab asset to the Design View, LevelEditor creates a reference from the base prefab object to the newly created object.

If you edit the properties of a base prefab asset, those changes also affect all instances of that prefab in the game level.

If you edit the properties of an instance of a prefab asset, those changes remain local to that instance (they override those of the base prefab, but do not affect the base prefab itself).

 

To create a prototype or prefab asset, you must first create one or more game objects, set properties for each object, and associate resources with them. You then create a prototype or prefab asset from the game objects, and use the prototype or prefab asset as a template.

 

To create a prototype asset:

  1. Select one or more existing game objects in the Design View.
  2. Select File > Create Prototype to save the selected objects as a prototype asset. The Save As dialog opens so that you can define the prototype asset’s file name and folder location. Save the prototype asset within your Resource Root folder.
    Recommendation: Define a folder named “Prototypes” within your Resource Root folder to store your prototypes. Define subfolders within this new “Prototypes” folder as needed for each type of prototype asset.

 

To create a prefab asset:

  1. Select one or more existing game objects in the Design View.
  2. Select File > Create Prefab to save the selected objects as a prefab asset. The Save As dialog opens so that you can define the prefab asset’s file name and folder location. Save the prefab asset within your Resource Root folder.
    Recommendation: Define a folder named “Prefabs” within your Resource Root folder to store your prefabs. Define subfolders within this new “Prefabs” folder as needed for each type of prefab asset.

 

To use a prototype or prefab asset to create additional instances of a game object or set of game objects:

  1. Open the Resources list.
  2. Select the appropriate folder in the Resources list; for example, select the Prototypes folder or the Prefabs folder.
  3. From the right-hand pane of the Resources list, select the prototype or prefab asset. You can use the Resource Preview window to display the fully rendered view of the prototype asset.
  4. Drag the prototype or prefab asset to the world. The copy of the prototype or prefab asset appears as a game object in the world and is added to the Project Lister.

 

Game objects created from prototype assets appear in the Project Lister within a GameObjectGroup object, with each copy of the prototype as a child of the GameObjectGroup, whereas game objects created from prefab assets appear in the Project Lister as child objects of the prefab instance. You can work with each object individually by selecting the object; to work with the objects as a group, select the prototype's GameObjectGroup or the prefab instance in the Project Lister.