UT3 Custom Gun Tutorial

Custom Weapons: Blender -> UT3 tutorial

This is a quick guide of the complete end to end creation of custom weapons in UT3 using blender.

Some preliminaries you will need the following for this tutorial:

Some notes on your models I will go through the basics of UV unwrapping in Blender but if you are familiar with how to do this in what ever package then feel free to do that before importing into blender it will save a few steps. It also helps if you make your UV maps so that the same one is used for the 1st person model as is the 3rd person model this means you can apply the same materials to both models and everything will line up properly. Usually this can be achieved by doing a base model used for both 1st and 3rd then UV unwrapping and then diverging the models.

You will need at least 2 models the high resolution 1st person model that will have all the fancy animation and so on and a lower resolution 3rd person version used for pickups and showing in other people/bots hands.

Typical poly count we are looking at for weapons is 1st person 5k-10k tri's, 3rd person 2k-3k tri's.

If you want to then you can make a much higher resolution mesh of your weapon and then add detail manually or with sculpt tools (like blenders or zbrush or mudbox) and then bake the normals from the high res mesh to the low res mesh. I will cover the baking Normals in blender in the tutorial for those that want to do that or you could use third party tools like the free xnormal (http://www.xnormal.net/).

Ensure your meshes are correctly located around the origin. Picture the origin as where the character will be looking from so for first person the handle should be just in front the weapon continuing just below the origin plane. For third person the origin should be where the character would grip the weapon so at the handle.

Typically axes wise Z is Up Y is along the gun and X is across.

So with those preliminaries out of the way lets get going with building a custom weapon.

For this tutorial I'm going to use a very simple mesh I put together in a few minutes using some quick cube modelling. Once you get more advance in your use of unreal script and the various tools available to you then you can create almost any weapon but for these initial steps its easier to base it on one of the pre-existing types. For this tutorial I'm going to use the shock rifle as a base. It's one of the simplest weapons in the UT arsenal in terms of the complexity of the model the number of animations so it's a good base to build on.

So load your model into blender, it should appear in the main window like this.

The blender window system is highly configurable you can divide it up however you want and have many different views and menus up at once. This makes it incredibly flexible but also a bit daunting for the first time user.

Basics are right click on the edge of any window allows you to split or join. Split divides the selected window in two join will get rid of one of the windows and enlarge the other depending on selection.

Basic controls the numpad controls the views with

  • 1 = front

  • 3 = side
  • 7 = top
  • 0 = current camera.
  • 4 and 6 rotate the view left and right from the current view,
  • 8 and 2 rotate up and down.
  • 5 turns on and off orthographic projection (basically perspective or not useful when modelling).

Be careful about pushing numbers on main keyboard as these control what layer you are viewing if all your models disappear you may have changed the layer hit 1 on the main keyboard to return to the correct layer.

Basic mouse controls left click positions the 3d cursor (a point in 3d space blender uses to use as a creation point or a snapping point or an axis or rotation depending on setting it has many uses more than can be covered in this small tutorial). Right click selects indicated by a pink border. Middle button rotates the view Mouse wheel zooms the view shift middle button translates the view.

Tab switches between object and edit mode (one of several modes each indicated in the mode dropdown on the 3d view menu bar).

The modes we will be using are Object mode (overall object selection and control), Edit mode (edit the individual geometry of the model or adjust bones directly) and pose mode (used when animating a skeleton or armature as it's called in blender.

G is Grab or translate current selection (object or points on a mesh or bones). R is rotate current selection. S is Scale current selection. With these modes you can lock the transformation to a single axis by simply typing the letter (ie X,Y, or Z) and you can also numerically enter the amount to move rotate or scale by typing it in (useful when rotating to specific angles) holding control will lock things to the grid.

Other useful keys are A which is select all or deselect all if stuff is already selected. B - which give box select on left clickdrag box unselect on right clickdrag press B again and you get paint select which allows you to paint your selection using a round selection brush whose size can be altered with the mouse wheel in this case left to select, middle to deselect, right click to deactivate the tool. Space bar brings up the menu, loads of features in there so I won't cover them. Z switched between solid and wire frame views. H hides geometry to make working easier, alt H unhides.

On the bottom of the 3d window you have your selection modes vertex, edge, and face the dictated how the system handles selection you can have multiple modes selected at once.

That's all I can think of right now I will try and detail things as I do them if you want to know more see the many online tutorials on blender like this
one http://www.blender.org/education-help/tutorials/tutorial-folder/blender-user-interface-tutorial/

So How to go about turning our meshes into a gun.

Step one the 1st person weapon. First things first the UV coordinates. Typically to simplify this step I do this on model before I make the 1P and 3P models since then they can have the same UV's and can share texture and normal maps and I can increase (or decrease the number of polygons to conform to our budgets).

So we have a model of how our gun should look we can add or take away geometry easy enough. So from here we now do the UV unwrapping.

For those who don't know UV is a way of describing how textures map onto 3d models. It's a much more precise and advanced technique than things like cube or sphere or flat mapping and it gives us a great deal of control over what goes where as it conforms to the object geometry.

Basically it works by mapping each point in 3d space on the model surface (in xyz coords) into 2d texture space (in U and V coords hence UV mapping). You can imagine the unwrapping process as a bit like taking a 3d paper model and flattening it out. There are multiple ways of achieveing this some automatic others more manual. We will do a bit of both.

So first things first in object mode select your model and enter edit mode by pressing tab. Now we will split the window so we can see our UV's. Right click the bottom of the 3d view and hit "Split Area" and divide your main window in two. Now on the bottom of the new window at the left bottom corner you should see a small icon that looks like a grid click it and a menu that says window type should pop up select "UV/Image Editor" you should then get a flat empty grid.

Move your focus back to your model and do a select all (the a key) with all the vertexes selected. Nothing much should change in the right hand window. This is because we have no UV's generated. Let's make some, in the left window press U to bring up the UV window. You will see many ways of generating UV's for now let's just use the automatic mode by clicking Unwrap.

You will probably get a pink square appear on the right side or a mesh that looks like a complete mess. This is because the unwrap algorithm needs a little help working out how to divide up the model.

We need to insert some seams to tell the unwrapper how to break apart our model. This is equivalent to the cuts on a flat paper construction.

Since the model is symmetric lets try dividing it down the middle. Go to the front view in the 3d window by pushing 1 on the the num pad then using the box select tool select the middle of the mode being careful not to select anything else. Now we need to mark a seam with these points selected hit Ctrl+E then click "Mark Seam" deselect everything with A and you should see an orange line around the middle of the model signifying a seam.


Hit Select all the Unwrap again (A then U then click Unwrap) and see the difference now we should have two identical blobs of mesh still a bit of a mess but getting there.

Now one thing to be aware of is what this actually means in terms of how the model will appear we are mapping each side of the gun to two separate sets of coordinates with a seam running down the middle. Depending on what texturing we do on that it may or may not be visible to the end user. Most of the time I like to keep the seams out of view where possible. Sometimes a seam is good where we want a neat break in texturing between one area and another but that very much depends on the model in question.

A seam down the middle would probably be fairly obvious bad joins where texture maps seam in plain view are often very glaring in games so let's redo that. select all with A then Ctrl+E and click clear seam. This will reset the seams. It probably won't reset the UV mapping as it will just keep our last best.

Let's think of this model more as a cube shape and cut it such that it folds out neatly. Here I've separated the handle the front and the main body of the gun with seams so it unfolds

In the third iteration we've separated out the main body the front and the side with a few compromises and the handle underneath it isn't bad for a quick go you can obviously spend longer tweaking and smoothing things.

One trick you can use to make the most of the texture space is take advantage of the fact that multiple parts of a model can all map to the same UV's for a symmetric model like this that allows us the option to use the same area of the map and have more detailed texture on both or more room for other textures.

You can do this by manually editing the UV data on the image. It responds to most of the same commands as the editing window grab rotate scale multi select and so on.

Some downsides with this is that you are using the same texture and any text may get reversed or rotated due to the duplication or in the case of normals inverted. Also when baking normals you may get odd errors this can be mitigated by removing the duplicated parts from the UV image before baking and putting them back in afterwards.

So once you have your model UVmapped and ready to go you can save an image to use as the basis of the texture you will use in UT3. You can use blender to paint the image but it lacks the more sophisticated tools that you might want so I would tend to use gimp or photoshop.

So first to save the texture in the UV window in edit mode click the UVs menu then scripts and Save UV Face Layout this will save a targa into the same directory as your current working area with the face layout. Make sure you set the resolution correctly texture maps for UT3 typically run to 2048 square (UV images are always square so it only asks for one size) for the main textures and normals some of the more esoteric texture options use different resolutions bit that's beyond the scope of this tutorial.

Paint up the UV with the desired colours and textures. Keep a copy of the original layout so you can use it to tweak any normal maps.

here is the saved layout

and here is a quick texture map

and this it what it looks like not wonderful there is an obvious seam on the front but good enough for this tutorial

Baking Normals: It's a good idea to ensure your meshes are all smooth so in editing buttons (little icon on the bottom with a square with dots at the corners or you can press F9) under the link and material pane hit set smooth with the model selected. You can get jagged normals if you don't do this or additional features you don't want. Do this on both meshes hi res and low res.

Here is a high res mesh I've worked up from the low res mesh

Import your highres model into blender with your ingame model. They should sit over the top of each other. Now select the ingame model and go to the UV window hit tab to go to edit mode press A to select all then select the menu Image then new and give it a correct size for the normal map typically 2048 square.

Hit Tab to exit edit mode and ensure the image is still selected in the UV window (usually called untitled in the drop down). In the outliner or the 3d window select your hi resolution mesh by right clicking. Then hold Shift and select your low resolution mesh. Go to the scene buttons little icon with a mountain(or press f10) under the render submenu (same icon as the first one first on the left in the second group that shows up when you press f10) select the Bake tab. Then hit the Normals button select Tangent in the coordinate dropdown and press the Selected to Active button. With all that done hit the Bake button and you should see the image on the UV pane fill with Normal data (which is typically blueish with areas of green and red indicating features) once this is complete you can save this to disk and use this as your normal map or tweak it using an image editing package.
The resulting normal map

what the normal map looks like applied to the low res model

If the program says no image is selected or the image comes out completely one shade of blue then make sure you have all the selections in the right order and the image you are baking to selected in the UV window for your low res mesh.

Manually making normals is also possible you can make a black and white displacement map and then convert it to a normal map using the plug in. You can also manually make by recreating the map using the colours several examples exist of how to do this. You can also blend several normal maps together. Create a normal based on the model and then add extra detail using the plugin.

Here is a manual normal map made with the plug in with some added detail that would be hard to add to the high res mesh.

The combined normal map using layers set to overlay

A render of the model with the new normal map without the texture making it easier to see the effect.

A render of the model with the textures

How to view your handy work. You could wait and just load it all into UT3 but sometimes it's good to get a feel for how things look before that since the packaging process is a bit involved. Load your in game model, select the Shading button which looks like a little sphere (or press f5 then select the materials sub pane form the list on the left (sphere icon second from the left) create a new material for your object by hitting Add New. The go to the texture tab little leopard print icon (or f6) add in a new texture (or two if you also want to test your normal maps) by clicking the add new button on an empty texture slot in the texture pane. In the texture type drop down select image. In the image pane that will now appear on the right hit the open button (little folder icon usually orange in colour) then select your texture.

If this is a normal map press the normal map button in the map image pane and select Tangent for the type.

Now go back to the materials sub pane go to the far tabs labeled texture, Map input, map to (if this is off the edge of the screen scroll over by pressing the middle mouse button)

Got to the texture tab and make sure your colour map is selected. Then in Map Input press UV this tells it to map the texture to the UV coordinates. For the colour texture make sure the Col option is selected in the Map To tab for the normal hit Nor and deselect the colour.


You can now render your model and see it with the texture map and the normals by pressing f12.

Rigging your model:

To animate the model in ut3 it needs a set of bones to use to describe how to move it and a set of actions to tell it what to do. Step one is if you are working from a preexisting model type find out what animations you need. For this example we need WeaponPutDown, WeaponIdle, WeaponFire, WeaponAltFire, and WeaponEquip.

The names are important as they will be what UT3 binds to with more custom work the names can be altered in the script but for this simple example we will stick to what the shock rifle uses.

First we need to create an armature. This is a construct in blender that holds the bones and stores pose information.

In object mode with the 3d cursor at the origin (click as near as you can get then do shift+s snap cursor to grid) press space to bring up the menu hit Add then Armature an armature with a single bone at the origin should pop up.

With the armature selected switch to edit mode by pressing tab and the bones should now go pink. You'll notice the bones have a sort of arrow shape this is so they can hinge UT3 doesn't use all the information they provide merely the origin point of the bone and the heirachy.

I tend to orient my bones all the same way and don't use the Connected function of Blender as UT3 doesn't store this information.

I make the bone so the tip points away in the direction the player would be but this is purely my own preference. Name the first bone root (for the 1p model mostly UT3 doesn't use the bones names as such they are more for our purposes)

Add a new bone by hitting space Add then Bone or duplicate the root by hitting Shift+D drag this to the front of you gun where you want the fire point to be. Rename this bone MuzzleFlash this bone will be used later to tell Ut3 where to draw the muzzle flash. Add bones where you want parts of your model to move or rotate then add them to a heirachy by parenting the bones together you can do this by selecting the bone in the Child Of drop down in the Armature bones pane under Editing (f9). You must ensure all bones are parented at least to the root at some level (if you parent a bone to another one that is parented to the root that is fine but you must have a tree like hierarchy). Once you have all your bones in position switch to object mode by pressing tab and select the 3d model then shift select the armature. Hit Ctrl+P a dialog should pop up that says Make Parent To: then a list click Armature (if this doesn't pop up try reselecting make sure you select the model then the armature) it should then ask if you want to create vertex groups click Name Groups this will create a list of vertex groups for each of the bones we have (Vertex groups tell Blender and Ut3 what vertex's move with what bone)


Now select the model and switch to edit mode with tab. In the link and material pane in Editing (f9) you should see a heading Vertex Groups then a drop down for each of the groups go through selecting all the vertexes you want to move with the corresponding bone (you can also do this by bone weight painting but that is beyond the scope of this tutorial) at the simplest you can just select all and assign them to the root group. If you want more elaborate movement each separate moving piece must have its own bone and corresponding vertex group.

Once this is done we are ready to animate. Switch to object mode and select the armature. Now we want to switch to Pose mode selected in the mode drop down on the 3d window. The bones should now go blue. It is a good idea to switch the deform options under the armature tab in editing (f9) so only vertex groups is selected this prevents blender moving stuff using other methods that UT3 can't support.

If you still have the UV window select Action Editor in the window type instead. there are a few other window types that can be useful for animating but for now I'll stick with the basics.

The action window has a timeline along the bottom and a green bar representing the current frame. You can also select the current frame using the numerical indicator on the buttons menu. Hitting right arrow key also advances a single frame up advances 10 left goes back a frame down goes back 10.

Make sure you are at frame 1 and we will start with the idle animation (this is the one that Unreal executes as you just walk about and is the default state typically these just wobble a bit to give the impression of someone moving the gun around a little) It's worth noting that every animation starts from the idle state so make sure this is your base for any animation that moves from it (fire altfire putdown etc ) and make sure your equip goes into it.

For this basic tutorial we will just have the gun static but you can add more animation to it later if you wish.

First we create the action do this by selecting the action drop down in the action window which is the second dropdown from the left with a sort of thumb tack icon ahead of it. Select ADD NEW from the dropdown. It will create an action typically called Action rename this action WeaponIdle by clicking the dropdown and typing in the new name.

Select all the bones by pressing A in the 3d window (they will all go light blue). Then press I to add a keyframe a menu will pop up asking what to keyframe hit LocRotScale a series of yellow diamonds should appear on the Action editor at frame one next to all the bone names in a list down the left side.

Next we need to make a Fire Action, add a new action with the WeaponIdle action selected in the drop down (When you create a new action with another one selected it copys the current action into the new one which saves us a bit of work) rename it to WeaponFire.

Select the keyframes in the action editor at frame one either by doing a border select by pressing B or shift clicking till they are all yellow (they might all be yellow anyway :) )

Duplicate the keyframes at frame 1 and then move them to frame 40 or so by pressing Shift+D to duplicate the dragging the duplicated keyframes along to 40 on the timeline. Left click to set their new position.

Set the frame to somewhere in the middle 20 or so ish then in the 3D view select the root bone. Hit G to grab and move the bone and R to rotate it and make the gun appear as if it has fired and gained some recoil. Hit I and add a keyframe with LocRotScale

If you play the animation either by hitting alt-a (The play range is selected in the render tab) or dragging the green frame in the action editor window with left click you can see how the thing will look. You can obviously add more keyframes and more elaborate animation of multiple bones scripting can also assume control over bones. UT accepts rotation of bones (and will do translation if you select the option) but not scaling.

Add another animation from the WeaponFire rename it WeaponAltFire modify it for an alt fire or leave it the same.

Add another animation from the WeaponIdle state Rename it WeaponPutDown and add another keyframe that makes it as if the weapon is being put away just out of sight.

Add another animation from the WeaponPutDown rename it WeaponEquip we can save some time here by simply reversing the put down. Select all the keyframes in the action editor by hitting A (they should all go yellow) press S to scale on the keyboard type -1 then left click to set the scale. Hit G and reposition the start so it is at frame 1 (scaling by -1 effectively swaps everything around so the start is at the end and the end at the start).

Now we have all our 1P animations we are ready to export the PSK/PSA files for UT3 to read.

It's good to save a copy of this so we can come back to it a tweak it later.

Exporting to UT3

To export first we need to trianglize the model as UT3 works in triangles not quads. Select the model go to Edit mode by pressing tab then press Ctrl+T to convert to triangles it is also worth recalculating our normals just in case press Ctrl+N and select recalculate Normals Outside we are now good to go.

In one of your window type select Scripts Window assuming you have the plug in installed go to the menu Scripts then Export then Unreal Skeletal Mesh / Animation (.psk and .psa) Mod and click that. A dialogue box will fill the window asking where you want to save and what to call it.

I tend to name my 1p mesh and animations with 1P in the name somewhere so I know which is which.

Choose a name and click Export PSK/PSA File. Blender will sit there for a bit and eventually a little popup will appear under the mouse saying Export Complete!

Congratulations you have completed the 1p model.

Now we need to do the same on the 3rd person model:)

Starting from your 3rd person mesh add the armature. This time the model should be centered on the origin as if this is where the persons hand holding the weapon is. Relocated the vertexes so the mesh is correctly centered. 3p models and animations (if any) are not as detailed as 1p we will not bother with animation for this simple demo just giving enough bones for Unreal to postion thing correctly.

The bones now tell Unreal how the person is holding the weapon where the muzzle flash is and so on so we need to name them effectively.

The root bone that corresponds to where the character will grip the gun in their hand should be named b_gun_root add another bone to tell it where the left hand steadying the gun should go. Call it b_gun_left_hand and parent it to the root. Add a final bone for the muzzle flash. This will be socketed so you can name it what you like.

Parent the 3P mesh to the armature and create the vertex groups. Assign all the points to the root bone b_gun_root.


We are not going to bother with animation for the 3p view so now all we need to do is prepare the mesh for export. Recalculate the normals with Ctrl+N and convert the mesh to triangles with Ctrl+T.

Follow the export steps above but name this with 3P in the name to signify a 3rd person mesh.

For more advanced animations there is an additional step you need to create 1st person animations of the characters arms for things like loading and reloading. This involves using an arm rig and creating animations with your model then saving those animations sets that unreal can then use with the appropriate model in the game. This is quite advanced and tricky to accomplish (I've not yet figured it out) so we'll leave this for now.

You are now read to start importing your weapon into Unreal.

Creating the weapon package

Load Unreal Ed. it is in your unreal start menu items.

Open the generic browser (it may open automatically) by clicking View then BrowserWindows then Generic.

Once the browser pops up hit File then New

A dialogue box should pop up that asks for package, group and name then factory in a drop down.

Enter WP_Custom_Gun in the package box, Materials in the group, and then WP_Custom_Gun_Mat in the Name. Select Material in the factory drop down.

With almost all of these names you can substitute what ever you want so long as you remember the substitutions so you can make the same alterations to the name in the script later.

This will create a new package which you can find your new weapon in the resource list on the left hand side of the browser. Find WP_Custom_Gun and hit the plus symbol next to it so you can see all the groups. Note the Materials has been created and now contains a material with the requested name.

Importing our resources:
Now we need to get our meshes into unreal. Go to file and hit Import. A dialogue box will pop up and ask you to select a file. Go to where ever you saved the PSK/PSA files earlier and load the first person PSA file.

Another dialogue will pop up much like the one we had when we created the package. Set the Group to Mesh and the name to WP_Custom_Gun_1P.

Hit OK and now wait, very little will happen for a while. Somewhere in the background (usually under the generic browser window) a progress bar will appear. If nothing happens for a really long time look for this and see if it actually doing something. One of the problems is that if the mesh you import has problems it will crash unreal ed and give no feedback on what went wrong. If this happens double check the mesh has been converted to triangles and the armature is properly parented and the vertexes are all assigned to groups.

This is one of the reasons I start with the meshes to reduce the pain if it crashes unreal after setting up everything else.

OK so assuming it all worked you will have a new group called Mesh with the skeletal mesh we did for the 1st person weapon. Double click this and it will bring up a window that will let you view it. Left click rotates Right Click zooms middle translates the Camera. For some reason the models always seem really small though they look fine in game (may need some more experimentation with model sizing).

Close this window for now we will come back to it.

We should now import all the rest of our assets just like this one. I'm just going to list the names groups and types to set rather than detail each step.

3rd person mesh: Group = Mesh, Name = WP_Custom_Gun_3P
Colour Texture: Group = Materials, Name = Colour_Tex
Normals Texture: Group = Materials, Name = Normal_Tex

At the end of this you should have the textures and the meshes loaded in.

Ok Let's create the material we are going to use for our gun. Go to the materials group and click on it the browser should now have our material WP_Custom_Gun_Mat and two textures Colour_Tex and Normal_Tex.

Double click the WP_Custom_Gun_Mat Icon and the material manager should appear. Unreal can do some quite sophisticated multi pass materials using a nodes system in this window we are only going to do the basics.

You will see the material and its various connections that map to various effects. We are just going to use diffuse and normal.

First we need out textures. Without closing the material window go back to the main browser and select the colour texture so it is highlighted. Go back to the material manager and find TextureSample in the list on the right of the window. Left click it and drag out onto the materials area and release the left mouse button. You should get a little box appear with out texture in. Repeat the process for the Normals texture.

You will notice on each block or node is a series of little squares these are either inputs or outputs depending on the block and can be strung together to make intersting and advanced textures. That is beyond the scope of this tutorial.

For now we are just going to link the colour to the diffuse and the normal to the normals. To do this left click one of the outputs from the textures and drag it to the coresponding input on the material then release the mouse button.

You can move the blocks around by pressing control.

Now we have our quick and easy texture click the first of the tick marks to save it ready for use. Then Close the Material Manager.

Go back to the generic browser and select the 1st person mesh in Mesh. Double click it.

Go to the Mesh Tab select the materials and in the first slot ([0]) type in WP_Custom_Gun_Mat

The model should now have our texture on it. Repeat the process for the 3rd person model.

Now it's time to get the animations in go to the browser with our custom gun selected and right click to bring up the menu. Click Anim Set and a familiar dialogue will appear.

Enter Anim for the group and WP_Custom_Gun_1P_Anim for the name.

A dialogue should pop up that looks a bit like the mesh dialogue.

First select the correct model in the skeletal mesh dropdown. WP_Custom_Gun_1P

Our mesh should now show up in the window. Since the animations are tied to our mesh we need the right one selected.

Now click File then Import PSA

In the Anim tab our animations should now appear. You can play them back by selecting them in the Anim tab and then clicking the play button or dragging the slider. If your animations use translation as well as rotation then be sure to deselect bAnimRotationOnly in the AnimSet Tab.

They might play really fast again it's a possibly due making them too short or some such you can probably adjust the scaling factors in the parameters.

OK one final thing to do now. We need to set up the sockets. Go to the Mesh group and double click the first person mesh. In the dialogue that pops up click Mesh then SocketManager.

When the socket manager pops up click New Socket select the MuzzleFlash Bone from the drop down and then name the socket MuzzleFlashSocket in the next dialogue.

Repeat this for the 3rd person model where the bone is called b_gun_muzzleflare but name the socket the same as above.

OK now we have everything ready.

Close this window and save the package to the disk by clicking File then Save in the generic browser. Unreal ed will compile the package into a upk file.

Adding the Unreal Script:
Now we need to give this package some code to run. Note my paths are vista paths XP may be different it should be under My Documents area tho I think. First we need to put the package where the unreal compiler will find it. Go to C:\Users\\Documents\My Games\Unreal Tournament 3\UTGame\Unpublished\CookedPC you should find the WP_Custom_Gun.upk file we just built.

Copy it to your published directory at C:\Users\evilmatt\Documents\My Games\Unreal Tournament 3\UTGame\Published\CookedPC or else the compiler will have trouble finding it.

Ok now we need to create our code. First we need to install the source. Go to C:\Users\\Documents\My Games\Unreal Tournament 3\UTGame and create a Src directory Open the archive we downloaded earlier and copy the contents into the src directory. When that is done create a folder in Src called CustomGun in that folder create another one called Classes.

Now we need the basis for our code. To save time we will just copy the shockrifle code. Go to Src/UTGame/Classses and copy three files from there to our Src/CustomGun/Classes area. The three files are UTAmmo_ShockRifle.uc, UTAttachment_ShockRifle.uc and UTWeap_ShockRifle.uc.

With out copied versions rename them so rather than Shockrifle they say CustomGun on the end.

These three files define the shockrifle UTAmmo_ShockRifle defines the ammo and it's properties. UTAttachment_ShockRifle defines how it attaches to players. UTWeap_ShockRifle defines the weapon and how it works.

Now we need to do some coding (well mostly replacing the names for the ones we picked) you can use any text editor to do this. There are a few that recognise UnrealScript like Notepad++ (you have to watch that notepad++ doesn't encode the text in some odd format I kept getting errors with my script because it was using some odd unicode but was fine when I selected ANSI) and Jedit these make things a touch easier.

Open UTAmmo_CustomGun.uc

Change line 4 to this
class UTAmmo_CustomGun extends UTAmmoPickupFactory;

line 9 to this:
TargetWeapon=class''

these redefine the name of the class and retarget the ammo to the correct weapon. If you like you can play with line 8.
AmmoAmount=8
which defines the amount of ammo per clip

notice further down at line 14 it pulls in a mesh from the shock rifle. We could change this to a mesh of our own so the ammo would look different. I'm not going to bother in this tutorial.

Open UTAttachment_CustomGun.uc

change line 4 to:
class UTAttachment_CustomGun extends UTWeaponAttachment;

line 24:
End = Start + vector(Instigator.Controller.Rotation) * class'UTWeap_CustomGun'.default.WeaponRange;

line 117:
SkeletalMesh=SkeletalMesh'WP_Custom_Gun.Mesh.WP_Custom_Gun_3P'

line 131:
WeaponClass=class'UTWeap_CustomGun'

we are mostly just redirecting the weapon to the custom gun from the shock rifle we are also telling it to use the Custom Gun skeletal mesh for the 3rd person view.

Now open UTWeap_CustomGun.uc

change line 4:
class UTWeap_CustomGun extends UTWeapon;

change line 345 and 346:
SkeletalMesh=SkeletalMesh'WP_Custom_Gun.Mesh.WP_Custom_Gun_1P'
AnimSets(0)=AnimSet'WP_Custom_Gun.Anim.WP_Custom_Gun_1P_Anim'

line 352:
AttachmentClass=class'UTAttachment_CustomGun'

line 355:
SkeletalMesh=SkeletalMesh'WP_Custom_Gun.Mesh.WP_Custom_Gun_3P'

line 400:
MuzzleFlashSocket=MuzzleFlashSocket

Compiling the weapon:
Ok now we are ready to compile our weapon. It's a good idea to have unreal ed closed as it can interfere with the compiler.

First we need to tell Unreal that it needs to compile our weapon. Go to C:\Users\\Documents\My Games\Unreal Tournament 3\UTGame\Config and open UTEditor.ini

Find he section starting [ModPackages] and add ModPackages=CustomGun

No unreal should compile our gun when we run the compiler. To do this either make a copy of your ut3 shortcut and edit the properties so the target has make on the end of it then run that. Or you can fire up a command prompt and go to the unreal directory under Binaries and type UT3 make.

A text window should pop up and run and compile your code it will give you any warnings or errors.

Assuming no errors you can now use your weapon. Either copy the unpublished code into published like we did for the weapon package or run UT3 with the -useunpublished command by adding it to another shortcut like we did with make.

The easiest way to then get your weapon in game is use the weapon replacement mutator which allows you to swap any weapon for any other type of weapon. Go through and swap some of the common types of weapons for out custom one which will be called UTWeap_CustomGun.

Here are a few shots of our finished weapon in action. Note it is probably a bit small and possibly needs to be further forward in the first person view. But still not a bad start.

You can see this rushed model is probably too small and not very detailed still you can see it working here.

The lighting effects on firing really bring out the normal mapping

This is alt fire I animated it to kick more as you can see in the still

The size issue is more apparent in the 3rd person model shown here in a weapon spawn. These are all tweaks we could make later to improve our model


Here is the exterior view everyone else sees it does look like she is holding a water pistol so I probably made the model too small. Not sure why her left hand is that far out maybe I needed to add another socket or maybe it's just the size issue again.

got a whole load of pictures

got a whole load of pictures to go in that show in more detail what to do they are up on my picasa steam punk pirates album I just need to add them to this thing.

What I'm going to do is edit the original post as I go to refine and update as I add more stuff or correct any mistakes or clarify stuff.

Feel free to shout if something doesn't make sense and I'll try and improve it

Thats a huge amount of work

Thats a huge amount of work there...well done!

It was displaying strangely on my screen , so I've taken the liberty of cleaning up the HTML a bit, and I've added a rough approximation of an index (at where I guessed new sections were).

I typed it up in google docs

I typed it up in google docs and their html export is rubbish. I could have just copied the text across but couldn't be arsed to do a load of rehighlighting

Ok added the pictures

Ok added the pictures

I've added the stuff about

I've added the stuff about importing the files from blender into Unreal Ed building the weapons package and also creating the scripts to drive the mesh and get the weapon in game.

If this were a real weapon there is a lot more on top of this that you;d do but this is enough to get started.

So there we have it managed it in just under 7k word. Not bad

feel free to point out things that need embelishing or where I've cocked up.

If people want I can stick my source files for everything up somewhere for people to download and try.

Oh and all the images link

Oh and all the images link to much larger versions on picasa where you can see what is going on and I've highlighted stuff

or they used to till google

or they used to till google regenerated their addresses

bugger

not sure what I can do about that they'll just update the addresses again if change them now

well you can look at the full sized ones on the picassa site here http://picasaweb.google.com/warriner.matt/SteamPunkPiratesSt...

Redid the images so they

Redid the images so they link to the picasa page