Creating Prefabs to store in external libraries

In this recipe, we will show you how to create a Prefab and look at some of the global uses for them.

Getting ready

  • Before we begin, you must have Sandbox 3 open
  • Then open My_Level.cry
  • Create the house object again from the Editing and Merging Solids recipe
  • Then place down the Objects/natural/trees/hill_tree/hill_tree_large_bright_green.cgf as a brush near the house

How to do it...

The house and the tree are just two objects that will be used to demonstrate creating a Prefab.

Before we begin, we must create a new library to store these objects:

  1. Open the DataBase View (View | Open View Pane | DataBase View).
  2. Open the Prefabs Library tab.
  3. Create a new Prefab library named My_Prefabs.
  4. Select both the House and the Tree.
  5. In the main toolbar, click on Prefabs | Make from Selection.
  6. Group = Houses.
  7. Name = House_with_tree.
  8. Click on the Save Modified Libraries in the DataBase View.

    Note

    If you do not perform step 8 and close the level, you risk losing your Prefab!!

This has now created a new Prefab for you:

How to do it...

How it works...

Prefabs are much like groups of any object/entity within the engine. The difference is that they are self-contained groups that can be propagated to all other maps if the Prefab itself changes.

The major benefit of Prefabs is that any logic, sound, art, AI navigation, or additional work may be done on this grouped asset without the level designer needing to place a whole new asset every time. Each time the Prefab gets updated, the level designer will see the change once the level is re-opened with the new Prefab library.

Note

Modified Prefabs will NOT be seen in the game mode unless the level has been exported with the latest Prefab in the Editor.

There's more...

Here are some extra functions that can be used with Prefabs.

Extract Object and Extract All

After the Prefab is selected in the level, you can then select an object from the Prefab list and choose to extract that object from the Prefab. This allows the designers to take objects out of the Prefabs if required and modify them on their map individually.

Extract All will allow the designers to unpack everything from the Prefab completely. This is normally done to allow designers access to link logic to objects within the Prefab (Prefabs do not allow any links to pass outside of their packed content).

Open/Close

Without extracting the objects, it's still possible to change any of the properties of an object within that group. Simply open the group and select the object you wish to manipulate inside.

To close the Prefab, select the group and click on the Close button.

Pick and Attach/Remove Object and Update Prefab

You may also choose to pick and attach other objects/entities and put them into the already existing Prefab. Simply align the object/entity to the relative location you wish to have it within the Prefab. Then click Pick and Attach and select that object.

Alternatively, you can select an object from the Prefab's list and click Remove Object. This will remove the object from the Prefab and leave it where it was located on the map.

Both of these methods affect what is stored in the Prefab, however the Prefab itself is not automatically updated. After you've chosen to modify the Prefab in any way, (Pick and Attach/Remove Object/Modified an Object inside the Prefab) you must then click on Update Prefab. This will make sure the Prefab is re-written into the DataBase View. To make sure the Prefab library is saved, go to the DataBase View and save the Prefab Library.

See also

  • The Grouping the objects recipe
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.179.100