Creating and Using Prefabs

From C4 Engine Wiki

Jump to: navigation, search

This tutorial will show you how to create and use prefabs within your world.

A prefab can be considered as an object you wish to decorate your world with. A prefab could consist of a simple geometry that is created within an external modeling application and imported into the engine, or created directly within the C4 World Editor. It could be a simple, single object or a series of objects that construct a scene. Prefabs are not limited to just geometries, they can contain lights, sounds, effects and anything else you might need.

Generally speaking, the point of a prefab is to be able to place and use common objects within multiple worlds. It is a time saving system that has the additional advantage of allowing alterations to be made to one instance of an object and having it updated automatically in any world that references to that object.

Contents

Step 1 — Creating the Prefab

The first thing we need to do is determine where we are going to store our prefabs. By default they are stored within a folder named "pieces" which is located in the "C4/Data/wld" folder. You can choose to use that existing folder or you could create your own new folder. I have created my own folder which I have named "Prefabs".

Open a fresh, new world. Do this by hitting Ctrl-N or by selecting New World from the Tools drop down menu. If you have created a scene with an external modeling tool, select World -> Import Scene from the top menu bar. Otherwise go ahead and start building your scene with the World Editor's primitive geometries.

Once you have finished creating your prefab, save the world within your "Prefabs" folder or wherever you would like to store them.

Step 2 — Using the Prefab within a World

A prefab is placed in a world using the Reference Marker tool (shown to the right) in the Markers page in the World Editor. Place the Reference Marker where you would like your prefab to appear. With the Reference Marker selected, hit Ctrl-I (Cmd-I on the Mac) or select Get Info from the Node pulldown menu, to open the Node Info dialog. Next, click on the Reference tab in the Node Info dialog. Now you can specify which world is to be used for your prefab.

Image:RefMarkerInfo2.png

Toggling Referenced Worlds

If you cannot see your prefab within the world editor, click the Toggle Referenced Worlds icon which is shown to the right.

Why not use an MDL?

MDL's, which are created by using the Export Model command, are not intended to be used as props within worlds. One reason for this is that MDL's do not store any editor based data, WLD files do. MDL files are entities and are to be used as such. They are generally supposed to be things that will move around in a game and are typically placed in a world via a marker.

Personal tools