Prefab: Difference between revisions
m (SnarkPit link was broken) |
MossyBucket (talk | contribs) (Templated. Capitalized(!). Made a section about the use of skip brushes.) |
||
Line 10: | Line 10: | ||
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 | # Select the objects you wish to include in your prefab (using {{key|Ctrl}}-click). | ||
# 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: | # 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: {{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. {{note|While the ''.vmf'' extension should be automatically added to the filename, some users have experienced this not being the case. To be on the safe side, add ''.vmf'' to the filename to ensure that the prefab will show up. You can also add it later by browsing to the prefabs folder.}} | # 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. {{note|While the ''.vmf'' extension should be automatically added to the filename, some users have experienced this not being the case. To be on the safe side, add ''.vmf'' to the filename to ensure that the prefab will show up. You can also add it later by browsing to the prefabs folder.}} | ||
# 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. | ||
Line 19: | Line 19: | ||
Prefab tokens are used for the names of entities, inputs and outputs within prefab systems to help solve problems with multiple prefabs. | Prefab tokens are used for the names of entities, inputs and outputs within prefab systems to help solve problems with multiple prefabs. | ||
The first token is the "&i" token. When you put it at the end of a name, then every prefab you insert will have it's own unique number. 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", ... | |||
The second token is the "*" token. When you put it in a name, then that name can be referred to as that name and any number after it. For example, two doors known as "Door_1" and "Door_2" could both be activated at the same time when the open input is sent to "Door_*". Likewise, a door known as "Door_*" can be activated by an output sent to "Door_2". | |||
== Inserting prefabs == | == Inserting prefabs == | ||
Line 28: | Line 28: | ||
Once you have prefab objects created, it is a simple task to insert a prefab into your level. | 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 | There are two ways of putting a prefab into your level: Using the {{Hammer entity}}, or using the {{Hammer block}}. | ||
The process is basically the same for both tools: First select the tool you wish to use, then select the prefab from the [[Hammer New Objects Toolbar|New Objects toolbar]], and then insert it through one of the views. | The process is basically the same for both tools: First select the tool you wish to use, then select the prefab from the [[Hammer New Objects Toolbar|New Objects toolbar]], and then insert it through one of the views. | ||
The | The {{Hammer entity}} should be used for most prefab placement, as it retains the exact size of the original prefab. Placement with the {{Hammer block}} allows for resizing of the prefab as it's placed, but is slightly more time-consuming to place correctly. | ||
{{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 === | ||
The {{Hammer entity}} is used to place a prefab object that should retain its original size. | |||
# Select the | # Select the {{Hammer entity}} from the toolbar. (Shortcut: {{key|Shift+E}}) | ||
# In the [[Hammer New Objects Toolbar|New Objects]] toolbar, select a prefab library in the '''Categories:''' selection box. | # In the [[Hammer New Objects Toolbar|New Objects]] toolbar, select a prefab library in the '''Categories:''' selection box. | ||
# Select a specific prefab to insert from the library in the '''Objects:''' selection box. | # Select a specific prefab to insert from the library in the '''Objects:''' selection box. | ||
# Click in the '''3D view''' where you want the prefab to be placed, or click in one of the '''2D views''' and press | # Click in the '''3D view''' where you want the prefab to be placed, or click in one of the '''2D views''' and press {{key|Enter}} to insert the prefab. | ||
=== Using the Block Tool === | === Using the Block Tool === | ||
{{Hammer block}} is used if you want to insert a prefab scaled to a certain size. | |||
[[Image:InsertSizedPrefab.png|right]] | [[Image:InsertSizedPrefab.png|right]] | ||
To place a prefab object, scaling it to an exact size: | To place a prefab object, scaling it to an exact size: | ||
# Select the | # Select the {{Hammer block}} from the toolbar or by pressing {{key|Shift+B}}. | ||
# In the [[Hammer New Objects Toolbar|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. | # In the [[Hammer New Objects Toolbar|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. | ||
# 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 | # Press {{key|Enter}}. The prefab will inserted, and scaled to fit the selection box.{{clr}} | ||
== The Skip tool texture == | |||
A prefab typically consists of many objects that you want to move or copy somewhere, and if you group them together so that their size is odd, you may end up with components ending up not exactly where you want them. You can prevent this by grouping enveloping the prefab inside a [[skip]] [[tool texture]]: | |||
# Set the grid size to a the maximum size that you expect to move the prefab in. (Typically you plan the [[skip]] brush to be a size of about 4x4x4 grid squares.) | |||
# Create a brush enveloping all the components of the prefab. | |||
# Cover every side of the brush with the [[skip]] [[tool texture]]. | |||
# Select all the components of the prefab (''including'' the [[skip]] brush) and group them together. | |||
The positions of the components inside the brush has now been made relative to the [[skip]] brush, making their movements on par with the Hammer editor's graph. As the brush is covered in a [[skip]] [[tool texture]], it will not be compiled with the map. | |||
== Available prefabs == | == Available prefabs == | ||
For a list of available | For a list of prefabs that are already available in the Source SDK, see [[:Category:Prefabs]]. | ||
== External links == | == External links == |
Revision as of 08:15, 12 February 2011
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.
Note: For orangebox games, make sure to use the \sourcesdk\bin\orangebox\bin\prefabs
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:
- 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.
- Select the objects you wish to include in your prefab (using Ctrl-click).
- 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 New Objects toolbar, or select the Create Prefab command from the 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.
Note:While the .vmf extension should be automatically added to the filename, some users have experienced this not being the case. To be on the safe side, add .vmf to the filename to ensure that the prefab will show up. You can also add it later by browsing to the prefabs folder.
- The new prefab will now be available for insertion in the New Objects toolbar.
Prefab tokens
Prefab tokens are used for the names of entities, inputs and outputs within prefab systems to help solve problems with multiple prefabs.
The first token is the "&i" token. When you put it at the end of a name, then every prefab you insert will have it's own unique number. 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", ...
The second token is the "*" token. When you put it in a name, then that name can be referred to as that name and any number after it. For example, two doors known as "Door_1" and "Door_2" could both be activated at the same time when the open input is sent to "Door_*". Likewise, a door known as "Door_*" can be activated by an output sent to "Door_2".
Inserting prefabs
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.

Using the Entity Tool
The Entity tool is used to place a prefab object that should retain its original size.
- Select the Entity tool
from the toolbar. (Shortcut: Shift+E)
- In the New Objects toolbar, select a prefab library in the Categories: selection box.
- Select a specific prefab to insert from the library in the Objects: selection box.
- 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
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:
- Select the Block tool
from the toolbar or by pressing Shift+B.
- 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.
- 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.
The Skip tool texture
A prefab typically consists of many objects that you want to move or copy somewhere, and if you group them together so that their size is odd, you may end up with components ending up not exactly where you want them. You can prevent this by grouping enveloping the prefab inside a skip tool texture:
- Set the grid size to a the maximum size that you expect to move the prefab in. (Typically you plan the skip brush to be a size of about 4x4x4 grid squares.)
- Create a brush enveloping all the components of the prefab.
- Cover every side of the brush with the skip tool texture.
- Select all the components of the prefab (including the skip brush) and group them together.
The positions of the components inside the brush has now been made relative to the skip brush, making their movements on par with the Hammer editor's graph. As the brush is covered in a skip tool texture, it will not be compiled with the map.
Available prefabs
For a list of prefabs that are already available in the Source SDK, see Category:Prefabs.
External links
The following sites host custom made prefabs and models: