Prefab: Difference between revisions
m (Corrected mistake: Ctrl, not Shift.) |
(clarified use of prefab tokens) |
||
Line 1: | Line 1: | ||
A Premade Fabrication, 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 Premade Fabrication, 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. | ||
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 | 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. | ||
# If this prefab is intended to interact with named objects inside itself, | == Placing prefabs == | ||
For information on how to place prefabs in a map, see [[Brush Creation#Inserting Prefabs|Inserting Prefabs]]. | |||
== 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|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>-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. | ||
Line 12: | Line 18: | ||
# 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 === | |||
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 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", ... | |||
== External links == | == External links == |
Revision as of 12:40, 17 August 2006
A Premade Fabrication, 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.
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 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.
Placing prefabs
For information on how to place prefabs in a map, see Inserting Prefabs.
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.
- 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", ...
External links
Various sites that host custom made prefabs and models: