Prefab: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(Hammer adds the vmf extention automatically. (Tested this.))
m (minor cleanup)
Line 1: Line 1:
A '''pre'''made '''fab'''rication, or '''prefab''', is a separately saved object, usually consisting of multiple parts, either brushes, props, or entity elements. The prefab system allows you to easily store pieces from your levels that can be used repeatedly. Examples of useful prefabs include hallways, pillars, special entity setups, etc.
A '''pre'''made '''fab'''rication, or '''prefab''', is a separately saved object, usually consisting of multiple parts - brushes, props, or entity elements. The prefab system allows you to easily store pieces from your levels that can be used repeatedly. Examples of useful prefabs include hallways, pillars, special entity setups, etc.


Prefabs are simply small map (.[[VMF]]) files that contain only your prefab. These files are stored in a particular prefab folder, generally \sourcesdk\bin\prefabs, so that [[Valve Hammer Editor|Hammer]] can find them and allow you to easily insert them into your levels. Prefabs can be organized into their own hierarchy in the /prefabs directory - Using a folder of prefabs for each map, mod, etcetera, as determined by the user.  
Prefabs are simply small map files (.[[VMF]]) that contain only your prefab. These files are stored in a particular prefab folder, generally <code>\sourcesdk\bin\prefabs</code>, so that [[Valve Hammer Editor|Hammer]] can find them and allow you to easily insert them into your levels.


Prefabs can be organized into their own hierarchy by simply adding sub-folders to the <code>\prefabs</code>  directory. This allows you to sort prefabs based on, amongst others, the intended map or mod they belong to, thus possibly easing their navigation.


== Creating prefabs ==
== Creating prefabs ==
Prefabs can be created in the Hammer editor with these steps:
Prefabs can be created in the Hammer editor with these steps:
# If this prefab is intended to interact with named objects inside itself, add the "_&i" token at the end of each object's name. See [[#Prefab tokens|Prefab tokens]] below.
# If this prefab is intended to interact with named objects inside itself, add the "_&i" token at the end of each object's name. See [[#Prefab tokens|Prefab tokens]] below.
# Select the objects you wish to include in your prefab (using <Ctrl>-click).
# Select the objects you wish to include in your prefab (using <Ctrl-LMB>).
# If you plan on inserting the prefab using the [[Entity Tool]], the origin (0,0,0) of your map will be used as a reference point to where you insert the prefab, so it is advisable to drag the selected objects to this origin and centering the prefab on it.
# If you plan on inserting the prefab using the [[Entity Tool]], the origin (0,0,0) of your map will be used as a reference point to where you insert the prefab, so it is advisable to drag the selected objects to this origin and centering the prefab on it.
# Either click the '''Create Prefab''' button in the [[Hammer New Objects Toolbar|New Objects]] toolbar, or select the '''Create Prefab''' command from the [[Hammer_Tools_Menu|Tools menu]]. (Shortcut key: <Ctrl>-R)
# Either click the '''Create Prefab''' button in the [[Hammer New Objects Toolbar|New Objects]] toolbar, or select the '''Create Prefab''' command from the [[Hammer_Tools_Menu|Tools menu]]. (Shortcut key: <Ctrl>-R)
# A '''Save As...''' dialog will open, displaying the Hammer prefabs directory. Type in the filename to save your prefab as and click the '''Save''' button. (The ''.vmf'' extention will be added automatically.)
# A '''Save As...''' dialog will open, displaying the Hammer prefabs directory. Type in the filename to save your prefab as and click the '''Save''' button. (The ''.vmf'' extension will be added automatically.)
# The new prefab will now be available for insertion in the '''New Objects''' toolbar.
# The new prefab will now be available for insertion in the '''New Objects''' toolbar.


=== Prefab tokens ===
=== Prefab tokens ===
Line 35: Line 34:
{{tip|After choosing one of the prefab creation tools (either the Entity Tool or the Block Tool), then selecting a prefab library, picking the same creation tool a second time will enable the '''Insert original prefab''' button in the New Objects toolbar. You can use this button to insert the selected prefab in the center of the 2D views. After placing the prefab, it can be moved into place. Make sure [[Hammer_Map_Operations_Toolbar|Texture Locking]] is turned on!}}{{clr}}
{{tip|After choosing one of the prefab creation tools (either the Entity Tool or the Block Tool), then selecting a prefab library, picking the same creation tool a second time will enable the '''Insert original prefab''' button in the New Objects toolbar. You can use this button to insert the selected prefab in the center of the 2D views. After placing the prefab, it can be moved into place. Make sure [[Hammer_Map_Operations_Toolbar|Texture Locking]] is turned on!}}{{clr}}


===Using the Entity Tool===
=== Using the Entity Tool ===
[[Image:Mt-entities.png]] The '''Entity Tool''' is used to place a prefab object that should retain its original size.
[[Image:Mt-entities.png]] The '''Entity Tool''' is used to place a prefab object that should retain its original size.


Line 43: Line 42:
# Click in the '''3D view''' where you want the prefab to be placed, or click in one of the '''2D views''' and press <Enter> to insert the prefab.
# Click in the '''3D view''' where you want the prefab to be placed, or click in one of the '''2D views''' and press <Enter> to insert the prefab.


===Using the Block Tool===
=== Using the Block Tool ===
[[Image:Mt-block.png]] The '''Block Tool''' is used if you want to insert a prefab scaled to a certain size.
[[Image:Mt-block.png]] The '''Block Tool''' is used if you want to insert a prefab scaled to a certain size.
[[Image:InsertSizedPrefab.png|right]]
[[Image:InsertSizedPrefab.png|right]]
Line 52: Line 51:
# Drag a selection box in one of the 2D views, making sure it is the size and in the position that you want the prefab to be in each of the views.
# Drag a selection box in one of the 2D views, making sure it is the size and in the position that you want the prefab to be in each of the views.
# Press <Enter>. The prefab will inserted, and scaled to fit the selection box.{{clr}}
# Press <Enter>. The prefab will inserted, and scaled to fit the selection box.{{clr}}


== Available prefabs ==
== Available prefabs ==
For a list of available prefabs in the Source SDK, see [[:Category:Prefabs]].
For a list of available prefabs in the Source SDK, see [[:Category:Prefabs]].


== External links ==
== External links ==
 
The following sites host custom made prefabs and models:
Various sites that host custom made prefabs and models:


* [http://www.snarkpit.net/editing.php?page=files&game=HL2&type=prefabs&subcat=examples SnarkPit prefab database]
* [http://www.snarkpit.net/editing.php?page=files&game=HL2&type=prefabs&subcat=examples SnarkPit prefab database]

Revision as of 09:39, 21 September 2007

A premade fabrication, or prefab, is a separately saved object, usually consisting of multiple parts - brushes, props, or entity elements. The prefab system allows you to easily store pieces from your levels that can be used repeatedly. Examples of useful prefabs include hallways, pillars, special entity setups, etc.

Prefabs are simply small map files (.VMF) that contain only your prefab. These files are stored in a particular prefab folder, generally \sourcesdk\bin\prefabs, so that Hammer can find them and allow you to easily insert them into your levels.

Prefabs can be organized into their own hierarchy by simply adding sub-folders to the \prefabs directory. This allows you to sort prefabs based on, amongst others, the intended map or mod they belong to, thus possibly easing their navigation.

Creating prefabs

Prefabs can be created in the Hammer editor with these steps:

  1. If this prefab is intended to interact with named objects inside itself, add the "_&i" token at the end of each object's name. See Prefab tokens below.
  2. Select the objects you wish to include in your prefab (using <Ctrl-LMB>).
  3. If you plan on inserting the prefab using the Entity Tool, the origin (0,0,0) of your map will be used as a reference point to where you insert the prefab, so it is advisable to drag the selected objects to this origin and centering the prefab on it.
  4. Either click the Create Prefab button in the New Objects toolbar, or select the Create Prefab command from the Tools menu. (Shortcut key: <Ctrl>-R)
  5. A Save As... dialog will open, displaying the Hammer prefabs directory. Type in the filename to save your prefab as and click the Save button. (The .vmf extension will be added automatically.)
  6. The new prefab will now be available for insertion in the New Objects toolbar.

Prefab tokens

A special token "&i" can be added to the name of entities in prefab objects so the entity will have a unique name when placed in the level. When the prefab is placed, the &i token will be replaced by a unique number. The token can be included in the targetname, inputs and outputs, etc. All tokens in the prefab will be replaced with the same number. This allows entities in the prefab to reference each other, but still have a unique name so multiple prefabs won't trigger each other.

For example, a func_door entity with the name "door_sliding_&i" in the prefab would become "door_sliding_1" when placed in a level. Consecutive placements of the prefab would be called "door_sliding_2", "door_sliding_3", ...

A trigger_multiple included in the same prefab, with the name "trigger_sliding_&i", would share the same token number and be renamed "trigger_sliding_1", "trigger_sliding_2", "trigger_sliding_3", ...

Inserting prefabs

Hammer newobjects.jpg

Once you have prefab objects created, it is a simple task to insert a prefab into your level.

There are two ways of putting a prefab into your level: Using the Entity Tool, or using the Block Tool.

The process is basically the same for both tools: First select the tool you wish to use, then select the prefab from the New Objects toolbar, and then insert it through one of the views.

The Entity Tool should be used for most prefab placement, as it retains the exact size of the original prefab. Placement with the Block Tool allows for resizing of the prefab as it's placed, but is slightly more time-consuming to place correctly.

Tip.pngTip:After choosing one of the prefab creation tools (either the Entity Tool or the Block Tool), then selecting a prefab library, picking the same creation tool a second time will enable the Insert original prefab button in the New Objects toolbar. You can use this button to insert the selected prefab in the center of the 2D views. After placing the prefab, it can be moved into place. Make sure Texture Locking is turned on!

Using the Entity Tool

Mt-entities.png The Entity Tool is used to place a prefab object that should retain its original size.

  1. Select the Entity Tool from the toolbar or by pressing <Shift+E>.
  2. In the New Objects toolbar, select a prefab library in the Categories: selection box.
  3. Select a specific prefab to insert from the library in the Objects: selection box.
  4. Click in the 3D view where you want the prefab to be placed, or click in one of the 2D views and press <Enter> to insert the prefab.

Using the Block Tool

Mt-block.png The Block Tool is used if you want to insert a prefab scaled to a certain size.

To place a prefab object, scaling it to an exact size:

  1. Select the Block Tool from the toolbar or by pressing <Shift+B>.
  2. In the New Objects toolbar, select a prefab library in the Categories: selection box. Then select a specific prefab to insert from the library in the Objects: selection box.
  3. Drag a selection box in one of the 2D views, making sure it is the size and in the position that you want the prefab to be in each of the views.
  4. Press <Enter>. The prefab will inserted, and scaled to fit the selection box.

Available prefabs

For a list of available prefabs in the Source SDK, see Category:Prefabs.

External links

The following sites host custom made prefabs and models: