Prefab: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (it took very long just for me to replace every prefab and prefabs with prefap and prefaps.)
m (Undo revision 267470 by Picachu456 Gaming Software (talk))
Tag: Undo
Line 1: Line 1:
{{lang|Prefap}}
{{lang|Prefab}}


A '''pre'''made '''fap'''rication, or '''prefap''', is a separately saved object, usually consisting of multiple parts - brushes, props, or entity elements. The prefap system allows you to easily store pieces from your levels that can be used repeatedly. Examples of useful prefaps include hallways, pillars, special entity setups, entire maps, hate symbols, 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.


Prefaps are simply small map files (.[[VMF]]) that contain only your prefap. These files are stored in a particular prefap folder, generally <code>\sourcesdk\bin\prefaps</code>, so that [[Valve Hammer Editor|Hammer]] can find them and allow you to easily insert them into your levels.
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.


'''Note:''' For overrated games, make sure to use the <code>\sourcesdk\bin\orangebox\bin\prefaps</code>
'''Note:''' For orangebox games, make sure to use the <code>\sourcesdk\bin\orangebox\bin\prefabs</code>


Prefaps can be organized into their own hierarchy by simply adding sub-folders to the <code>prefaps/</code>  directory. This allows you to sort prefaps based on, amongst others, the intended map or mod they belong to, thus possibly easing their navigation.
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 prefaps ==
== Creating prefabs ==
Prefaps can be created in the Hammer editor with these steps:
Prefabs can be created in the Hammer editor with these steps:
# If this prefap is intended to interact with named objects inside itself, add the "_&i" token at the end of each object's name. See [[#Prefap tokens|Prefap 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 prefap (using {{key|Ctrl}}-click).
# Select the objects you wish to include in your prefab (using {{key|Ctrl}}-click).
# If you plan on inserting the prefap using the [[Entity Tool]], the origin (0,0,0) of your map will be used as a reference point to where you insert the prefap, so it is advisable to drag the selected objects to this origin and centering the prefap 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 Prefap''' button in the [[Hammer New Objects Toolbar|Object bar]], or select the '''Create Prefap''' command from the [[Hammer_Tools_Menu|Tools menu]]. (Shortcut key: {{key|Ctrl+R}})
# Either click the '''Create Prefab''' button in the [[Hammer New Objects Toolbar|Object bar]], 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 prefaps directory. Type in the filename to save your prefap 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 prefap will show up. You can also add it later by browsing to the prefaps folder.}} {{bug|After saving the very first prefap, Hammer can and will crash.}}
# 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.}} {{bug|After saving the very first prefab, Hammer might crash.}}
# The new prefap will now be available for insertion in the [[Hammer New Objects Toolbar|Object bar]].
# The new prefab will now be available for insertion in the [[Hammer New Objects Toolbar|Object bar]].


=== Prefap tokens ===
=== Prefab tokens ===
A special ''token'' "&i" can be added to the name of entities in prefap objects so the entity will have a unique name when placed in the level. When the prefap is placed, the &i token will be replaced by a unique number. The token can be included in the [[targetname]], [[Inputs and Outputs|inputs and outputs]], etc. All tokens in the prefap will be replaced with the same number. This allows entities within the prefap to reference each other, but still have a unique name so multiple prefaps won't trigger each other.
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|inputs and outputs]], etc. All tokens in the prefab will be replaced with the same number. This allows entities within 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 prefap would become "door_sliding_1" when placed in a level. Consecutive placements of the prefap would be called "door_sliding_2", "door_sliding_3", ...
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 prefap'', set to trigger "door_sliding_&i" upon initial creation, would upon insertion share the same token number as the door.
A [[trigger_multiple]] included ''in the same prefab'', set to trigger "door_sliding_&i" upon initial creation, would upon insertion share the same token number as the door.


{{note|Other values, like specific ''Brush faces'' attached to prefab [[env_cubemap]]s, cannot be saved, and have to be reset upon each insertion.}}
{{note|Other values, like specific ''Brush faces'' attached to prefab [[env_cubemap]]s, cannot be saved, and have to be reset upon each insertion.}}


For ways to address prefap names using this token, see [[Inputs_and_Outputs|search wildcards]].
For ways to address prefab names using this token, see [[Inputs_and_Outputs|search wildcards]].


{{tip|Using an asterisk (*) in your searches filters prefabs using a wildcard. For example, searching ''door_*'' would return ''door_1'', ''door_2'', ''door_red_7'', etc.}}
{{tip|Using an asterisk (*) in your searches filters prefabs using a wildcard. For example, searching ''door_*'' would return ''door_1'', ''door_2'', ''door_red_7'', etc.}}
Line 33: Line 33:
{{bug|"_&i" does not work for node hint groups.}}
{{bug|"_&i" does not work for node hint groups.}}


== Inserting prefaps ==
== Inserting prefabs ==
[[Image:hammer_newobjects.jpg|right]]
[[Image:hammer_newobjects.jpg|right]]


Once you have prefap objects created, it is a simple task to insert a prefap 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 prefap into your level: Using the {{Hammer entity}}, or using the {{Hammer block}}.
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 prefap from the [[Hammer New Objects Toolbar|Object bar]], 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|Object bar]], and then insert it through one of the views.


The {{Hammer entity}} should be used for most prefap placement, as it retains the exact size of the original prefab. Placement with the {{Hammer block}} allows for resizing of the prefap as it's placed, but is slightly more time-consuming to place correctly.
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 prefap creation tools (either the Entity Tool or the Block Tool), then selecting a prefap library, picking the same creation tool a second time will enable the '''Insert original prefap''' button in the Object bar. You can use this button to insert the selected prefap in the center of the 2D views. After placing the prefap, 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 Object bar. 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:InsertPrefapTut1.png|right|200px]]
[[Image:InsertPrefabTut1.png|right|200px]]
[[Image:InsertPrefapTut2.png|right|200px]]
[[Image:InsertPrefabTut2.png|right|200px]]
[[Image:InsertPrefapTut3.png|right|200px]]
[[Image:InsertPrefabTut3.png|right|200px]]


The {{Hammer entity}} is used to place a prefap object that should retain its original size.
The {{Hammer entity}} is used to place a prefab object that should retain its original size.


# Select the {{Hammer entity}} from the toolbar. (Shortcut: {{key|Shift+E}})
# Select the {{Hammer entity}} from the toolbar. (Shortcut: {{key|Shift+E}})
# In the [[Hammer New Objects Toolbar|Object bar]], select a prefap library in the '''Categories:''' selection box.
# In the [[Hammer New Objects Toolbar|Object bar]], select a prefab library in the '''Categories:''' selection box.
# Select a specific prefap 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 one of the 2D views where you want the prefab to be placed. Alternatively you can instead just click in the 3D view, whereupon the prefap will be inserted automatically.
# Click in one of the 2D views where you want the prefab to be placed. Alternatively you can instead just click in the 3D view, whereupon the prefab will be inserted automatically.
# Press {{key|Return}} or {{key|Enter}} to insert the prefap.
# Press {{key|Return}} or {{key|Enter}} to insert the prefab.


=== Using the Block Tool ===
=== Using the Block Tool ===
The {{Hammer block}} is used if you want to insert a prefap scaled to a certain size.
The {{Hammer block}} is used if you want to insert a prefab scaled to a certain size.


To place a prefap object, scaling it to an exact size:
To place a prefab object, scaling it to an exact size:
# Select the {{Hammer block}} from the toolbar. (Shortcut: {{key|Shift+B}})
# Select the {{Hammer block}} from the toolbar. (Shortcut: {{key|Shift+B}})
# In the [[Hammer New Objects Toolbar|Object bar]], select a prefap library in the '''Categories:''' selection box.
# In the [[Hammer New Objects Toolbar|Object bar]], select a prefab library in the '''Categories:''' selection box.
# Select a specific prefap to insert from the library in the '''Objects:''' selection box.
# 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 {{key|Return}} or {{key|Enter}} to insert the prefap. It will be scaled to fit the selection box.
# Press {{key|Return}} or {{key|Enter}} to insert the prefab. It will be scaled to fit the selection box.
{{clr}}
{{clr}}


Notice that any inserted prefap is automatically [[group|grouped]], and therefore the Objects selection mode must be used to move individual objects and access their entity properties.
Notice that any inserted prefab is automatically [[group|grouped]], and therefore the Objects selection mode must be used to move individual objects and access their entity properties.


== The Skip tool texture ==
== The Skip tool texture ==


A prefap typically consists of many objects that you want to move or copy somewhere, and if the prefap happens to be of an odd size, you may end up with components ending up not exactly where you want them. You can prevent this by enveloping the prefap inside a [[skip]] [[tool texture]]:
A prefab typically consists of many objects that you want to move or copy somewhere, and if the prefab happens to be of an odd size, you may end up with components ending up not exactly where you want them. You can prevent this by enveloping the prefab inside a [[skip]] [[tool texture]]:


# Set the grid size to a the maximum size that you expect to move the prefap in. (Typically you plan the [[skip]] brush to be a size of about 4x4x4 grid squares.)
# 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 prefap. It's best to select all objects beforehand, because you'll see all the affected volume, since some models may have large bounding boxes. If those are not fully encased, the entire thing may not align on the grid.
# Create a brush enveloping all the components of the prefab. It's best to select all objects beforehand, because you'll see all the affected volume, since some models may have large bounding boxes. If those are not fully encased, the entire thing may not align on the grid.
# Cover every side of the brush with the [[skip]] [[tool texture]].
# Cover every side of the brush with the [[skip]] [[tool texture]].
# Select all the components of the prefap (''including'' the [[skip]] brush) and save it.
# Select all the components of the prefab (''including'' the [[skip]] brush) and save it.


The positions of the components inside the brush are now relative to the enveloping [[skip]] brush, and the even size of the brush makes the movements of every component 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.
The positions of the components inside the brush are now relative to the enveloping [[skip]] brush, and the even size of the brush makes the movements of every component 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 prefaps ==
== Available prefabs ==
For a list of prefaps that are already available in the Source SDK, see [[:Category:Prefabs]].
For a list of prefabs that are already available in the Source SDK, see [[:Category:Prefabs]].


== See also ==
== See also ==


* [[func_instance]] - An advanced dynamic alternative to prefaps.
* [[func_instance]] - An advanced dynamic alternative to prefabs.


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


* [http://halflife2.filefront.com/files/Half-Life_2/Prefaps;2654 (HL2) File Front prefap database]
* [http://halflife2.filefront.com/files/Half-Life_2/Prefabs;2654 (HL2) File Front prefab database]
* [http://gamebanana.com/prefaps/games/2 (CS:S) GAMEBANANA prefap database]
* [http://gamebanana.com/prefabs/games/2 (CS:S) GAMEBANANA prefab database]
* [http://z15.invisionfree.com/Biwdc_Forums/index.php?showtopic=8 Half-life 2 Prefaps(Biwdc Forums)]
* [http://z15.invisionfree.com/Biwdc_Forums/index.php?showtopic=8 Half-life 2 Prefabs(Biwdc Forums)]


[[Category:Hammer]]
[[Category:Hammer]]
[[Category:Level Design]]
[[Category:Level Design]]
[[Category:Glossary]]
[[Category:Glossary]]

Revision as of 05:08, 1 November 2022

English (en)Русский (ru)中文 (zh)Translate (Translate)

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:

  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-click).
  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 Object bar, 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.
    Note.pngNote: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.
    Icon-Bug.pngBug:After saving the very first prefab, Hammer might crash.  [todo tested in ?]
  6. The new prefab will now be available for insertion in the Object bar.

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 within 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, set to trigger "door_sliding_&i" upon initial creation, would upon insertion share the same token number as the door.

Note.pngNote:Other values, like specific Brush faces attached to prefab env_cubemaps, cannot be saved, and have to be reset upon each insertion.

For ways to address prefab names using this token, see search wildcards.

Tip.pngTip:Using an asterisk (*) in your searches filters prefabs using a wildcard. For example, searching door_* would return door_1, door_2, door_red_7, etc.
Icon-Bug.pngBug:"_&i" does not work for node hint groups.  [todo tested in ?]

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 Mt-entities.png, or using the Block tool Hammer block.png.

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

The Entity tool Mt-entities.png should be used for most prefab placement, as it retains the exact size of the original prefab. Placement with the Block tool Hammer block.png 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 Object bar. 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

InsertPrefabTut1.png
InsertPrefabTut2.png
InsertPrefabTut3.png

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

  1. Select the Entity tool Mt-entities.png from the toolbar. (Shortcut: Shift+E)
  2. In the Object bar, 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 one of the 2D views where you want the prefab to be placed. Alternatively you can instead just click in the 3D view, whereupon the prefab will be inserted automatically.
  5. Press Return or Enter to insert the prefab.

Using the Block Tool

The Block tool Hammer block.png 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 Hammer block.png from the toolbar. (Shortcut: Shift+B)
  2. In the Object bar, 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. 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.
  5. Press Return or Enter to insert the prefab. It will be scaled to fit the selection box.

Notice that any inserted prefab is automatically grouped, and therefore the Objects selection mode must be used to move individual objects and access their entity properties.

The Skip tool texture

A prefab typically consists of many objects that you want to move or copy somewhere, and if the prefab happens to be of an odd size, you may end up with components ending up not exactly where you want them. You can prevent this by enveloping the prefab inside a skip tool texture:

  1. 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.)
  2. Create a brush enveloping all the components of the prefab. It's best to select all objects beforehand, because you'll see all the affected volume, since some models may have large bounding boxes. If those are not fully encased, the entire thing may not align on the grid.
  3. Cover every side of the brush with the skip tool texture.
  4. Select all the components of the prefab (including the skip brush) and save it.

The positions of the components inside the brush are now relative to the enveloping skip brush, and the even size of the brush makes the movements of every component 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.

See also

External links

The following sites host custom made prefabs and models: