UDN
Search public documentation:

SettingUpWeapons
日本語訳
中国翻译
한국어

Interested in the Unreal Engine?
Visit the Unreal Technology site.

Looking for jobs and company info?
Check out the Epic games site.

Questions about support via UDN?
Contact the UDN Staff

UE3 Home > Gameplay Elements > Setting Up Weapons

Setting Up Weapons


Modeling Weapons - Setup and Rigging


Weapons in Unreal Engine 3 use a skeletal mesh to render in both first person and third person. The first person mesh will generally be higher-poly as it is usually seen close up. Depending on the placement of the weapon when being used in first person, any polys that will never be seen can be omitted to save on rendering time. The third person mesh is usually used when viewing the player in third person and as the pickup mesh. As such, it has the ability to be seen from all angles and should not have any omitted polys. It won't usually be seen up close, however; so small details can be left out the keep the poly count as low as possible.

firstpersonmesh.jpg thirdpersonmesh.jpg

How you set up the skeleton for for the first person mesh of any particular weapon is dependent on what will be needed to setup the desired animations. In general, a weapon will have a root bone located where the player would grip the weapon and a child bone where the muzzle flash would be located. The bone is not used directly for attaching muzzle flashes and other effects, but sockets based on them will be used and having them in the right positions makes setting up the sockets that much easier.

For the third person mesh, the skeleton will probably be much simpler as most of the animation used when viewing the weapon in first person is skipped in third person as it isn't needed. The root bone shoud be placed where the weapon will be gripped with the dominant hand. A child bone may be placed where the off hand would grip the weapon if this is desired for the particular weapon or supported in your game in general. As with the first person mesh, a child bone can be placed where the muzzle flash will be located.

An example of a weapon skeleton is shown here:

firstpersonskeleton.jpg

It will probably be desirable to decide upon a naming scheme ahead of time to use for any bones or sockets that will be accessed directly through script or make sure your programmers provide the ability to specify the names of the bones being used.

Weapon Export


Exporting a weapon skeletal mesh into the engine is done in exactly the same way as a standard skeletal mesh. You can either choose to use ActorX to export your mesh and animations to a .PSK and .PSA file, respectively; or you can make use of Unreal's FBX Import pipeline by exporting your mesh and animations to an .FBX file with your 3D application's built-in export tools. You should export the mesh and each of the animations that will be needed for that particular weapon.

Weapon Import and Setup


The .PSK file (or .FBX file depending on your preferred file format) for the weapon should be imported into the Content Browser as a skeletal mesh.

meshimportpsk.jpg meshimport_fbx.jpg

Textures and materials for the weapon should also be imported, set up, and assigned to the skeletal mesh. In the AnimSet Editor, you can create a new AnimSet for the weapon from the File menu by choosing New AnimSet... and then providing a Package, Group (optional), and Name.

newanimset.jpg

Then, the .PSA file containing any animations for the weapon should be imported into the weapons's AnimSet by choosing Import PSA..., again from the File menu in the AnimSet Editor.

newanimation.jpg

If you are using the .FBX file format, you would choose Import FBX Animation... here, instead, to import your animations.

Setting Up Sockets

Sockets were mentioned previously as being used as attachment points for muzzle flashes as well as any additional effects the weapon may require. Sockets are essentially locators parented to a specific bone which can named and then be offset and given their own individual rotation. This provides an easy way to attach or spawn items at specific locations.

Sockets are added to a skeletal mesh inside of UnrealEd through the AnimSet Editor. Press the toolbar_socket.jpg button in the toolbar to open the Socket Manager.

socketmanager.jpg

The newsocket_button.jpg button will open a new dialog that lists all the bones available in the mesh.

newsocket_bone.jpg

Select the bone that was added at the tip of the barrel of the mesh and then press OK. This will bring up another dialog where the new socket can be given a name that will be used to identify it in code.

newsocket_name.jpg

Once you've entered a name, press OK to add the new socket. It should appear in the Preview Pane of the AnimSet Editor and in the socket list of the Socket Manager.

newsocket_complete.jpg

Creating Projectiles

A projectile is the physical representation of the weapon fire. The visual component of Projectiles in Unreal are simply particle systems. Creating particle sytems for projectiles is a straightforward process similar to making any other particle system. Essentially, you want to set up a particle system that recreates how you want to the projectile to appear while in flight. The particle system can be made up of as many emitters as necessary to get the desired effect.

Some examples of projectile particle systems are shown below:

projectile_link.jpg projectile_rocket.jpg projectile_shock.jpg

Setting Up Muzzle Flashes

Muzzle flashes are used to simulate the projectile being expelled from the barrel of the weapon, like the flash you would see when a gun is fired in real life. The weapon system in Unreal uses a particle system as the visual component of a muzzle flash. As with projectiles, the particle system for a muzzle flash can be made up of as many emitters as necessary to get the desired look.

Some examples of muzzle flash particle systems are shown below:

mf_link.jpg mf_rocket.jpg mf_shock.jpg

For Programmers


Once you have all the assets set up correctly, you need to give some information to a programmer for implementation. The information the programmer will need is:

  • The name of the 1st Person Mesh.
  • The name of the Animation Set.
  • The name of the Pickup Mesh.
  • The names of the Pick up, Equip, Put down, and Firing Sounds.
  • The names of the Projectile Particle Systems (if firing projectiles).
  • The names of the Muzzle Flash Particle Systems.
  • The name of the Crosshair Texture and Coordinates.

For efficient iteration, it's best to come up with a set of standards for this information.

Creating The Script File

Here is how you would enter all of the needed information into a very basic UnrealScript .uc file for your weapon:

MyWeapon.uc

class MyWeapon extends UTWeapon;

defaultproperties
{
   Begin Object class=AnimNodeSequence Name=MeshSequenceA
      bCauseActorAnimEnd=true
   End Object

   // Weapon SkeletalMesh
   Begin Object Name=FirstPersonMesh
      SkeletalMesh=SkeletalMesh'WP_LinkGun.Mesh.SK_WP_Linkgun_1P'
      AnimSets(0)=AnimSet'WP_LinkGun.Anims.K_WP_LinkGun_1P_Base'
      Animations=MeshSequenceA
      Scale=0.9
      FOV=60.0
   End Object

   // Pickup SkeletalMesh
   Begin Object Name=PickupMesh
      SkeletalMesh=SkeletalMesh'WP_LinkGun.Mesh.SK_WP_LinkGun_3P'
   End Object

   WeaponFireTypes(0)=EWFT_Projectile
   WeaponProjectiles(0)=class'UTProj_LinkPlasma'

   WeaponEquipSnd=SoundCue'A_Weapon_Link.Cue.A_Weapon_Link_RaiseCue'
   WeaponPutDownSnd=SoundCue'A_Weapon_Link.Cue.A_Weapon_Link_LowerCue'
   WeaponFireSnd(0)=SoundCue'A_Weapon_Link.Cue.A_Weapon_Link_FireCue'
   WeaponFireSnd(1)=SoundCue'A_Weapon_Link.Cue.A_Weapon_Link_AltFireCue'
   PickupSound=SoundCue'A_Pickups.Weapons.Cue.A_Pickup_Weapons_Link_Cue'

   MuzzleFlashSocket=MuzzleFlashSocket
   MuzzleFlashPSCTemplate=ParticleSystem'WP_LinkGun.Effects.P_FX_LinkGun_MF_Primary'

   CrosshairImage=Texture2D'UI_HUD.HUD.UTCrossHairs'
   CrossHairCoordinates=(U=384,V=0,UL=64,VL=64)
}

Tuning Weapons

There are many parameters which control how a weapon functions, found within several classes including the weapon class itself as well as classes for any projectiles being used. An explanation of many of the commonly used parameters as well as how weapons function on the code side is available on the Weapons Technical Guide page.

Useful Console Commands

One feature of the Unreal Engine which is very useful for tuning weapons is the editactor console command. While using the weapon you can type editactor class=weapon at the console, and a property window should pop up. This allows you to tune almost all of the parameters as you use the weapon, making iteration very quick.