I have set up a simple test map consisting of a slab of BSP, a
skylight, a playerstart, a skydome, and a directional light.
I will only be using default editor assets which can be found
in the EditorMeshes and EditorMaterials
packages.
I added the default mesh cube as a static mesh to the map, converted
it to an interpactor, and then made it somewhat thin.
What is a Prefab?
A prefab is a custom-built assembly of actors and/or Kismet
athat is saved in a package and can be reproduced through the
game as it's own discrete placable system. In other words, you
can create a door system, save it as its own 'thing' and then
duplicate the whole door system and place it elsewhere - you
don't have to re-create it from scratch each time you want that
door somewhere.
***Advantages:
Create it once, save it once, and use it over and over again.
Easily propagate changes on a single system, to all the other
systems in a level.
***Disadvantages:
Used in excess (the same thing over and over again) can cause
lack of variation in design. Prefabs can be updated at any time,
however, if individual instances of prefabs have been altered,
they'll be 'reset' when the prefab is updated. The last downside
is that there is no 'Select all Prefabs of this type' selection
available.
Creating Prefabs:
To create a prefab, select the actors that will be part of it.
Right click on them and select 'Create Prefab'. If any Kismet
is attached to the items, the prefab will contain that Kismet
as well. If this is the case, the Kismet must
be in its own, self-contained, subsequence, otherwise the Prefab
will grab all the Kismet in the 'level' that the prefab kismet
is in. After 'Creating Prefab' UEd will ask you for a location
to save it. Prefabs are saved in packages just like textures,
materials, staticmeshes, etc... Or you can save it in your map's
package. If any Kismet is attached, it wil ask you if you want
to include the Kismet. Finally, it will ask you if you want
to keep the system as-is, or replace it completely with an instance
of the prefab.
Placing Prefabs:
Just like placing a mesh, select the Prefab in the generic browser,
then right click in the world and select 'Place Prefab ___ here'.
You'll see a new instance of the system appear with a large
'P' sprite at its center pivot point. You can now select the
whole Prefab by clicking on any piece of it, or by selecting
the giant P. If you need to select certain actors within the
prefab, you can toggle 'whole' or 'piece' selection by using
the 'P' icon in the toolbar in UEd.
Altering Prefabs:
If you need to make a change to a prefab that you already have
set up, choose one prefab to work in. Make the changes you need
to just that prefab. When finished, right-click on it, and select
'Update Prefabs from this Instance'. This will propagate the
changes you made on that one prefab, to all the other prefabs
based off of that one. Re-save the map/package the prefab is
stored in.
Now, let's actually apply this knowledge to create a destruction prefab we can place around the level.
Destruction Prefab: Destruction in a level
can be set off many ways, but the two most common are from an
Event in a level, like a trigger touch, or from the item taking
damage, for example from being shot by the Player. I'm going
to use the final destruction assembly from the Destruction
From Event/Damage tutorial as the base to build our prefab.
I already have the system assembled and ready to go. I've also
made sure its associated Kismet is in its own isolated sequence.
1) Select all the pieces, right-click, and 'Create Prefab'.
|
|
2) Tell Ued where you want to save it. In my example, I saved
is in a new 'Prefabs' group in my map itself. Then it asked
me if I wanted to include the Kismet sequence that was a part
of the system. Finally, it asked me if I wanted to replace it
with an instance of the prefab. I said 'Yes'.
|
|
3) Test it. See if it still works as expected.
4) Save it. If it's in your map file, then save your map. If
you put it in a seperate package, save the package.
5) Now you can select the prefab in your generic browser and
place new instances, or you can duplicate your prefab in the
level and move it around, and duplicate it some more.
That's about it. Prefabs are incredibly useful for scattering simple little systems around a level to 'liven' it up a little.
|