Creating Custom Characters for UDK
This document discusses creating new character meshes for use in the Unreal Development Kit, as well as how to import the mesh content into the engine and configure it to quickly get it up and running in the engine. For more information on programming custom behavior for characters, see the Characters Technical Guide.
Below are 4 different skeletons which can be used as guides or foundations for building your own characters for use in UDK:
NOTE: A Biped rig is included with some of the skeletons. The Biped rig is just an additional skeleton that's easier to animate. When an animation is done, we bake the animation onto the original skeleton, delete the biped, and export the animation.
Additionally, the following first person skeleton is available for reference:
A good workflow is to use what might be called a “master skeleton” file which should contain all bones used by every character of that type within your game. It is not necessary for a character mesh to make use of all the bones; however it is necessary that the master skeleton have every bone for every character. For example, if one wants to create a character with a new cloth type that doesn’t exist yet, like cloth hanging from each wrist, those bones need to be added to the master skeleton so that each mesh works correctly during the character creation process.
Because the master skeleton has every bone that exists, it is a good idea to use the master skeleton max file for skinning a new mesh since it is easy to see all the bones available for use.
For simplicity’s sake, this document is going to go over getting characters imported using bones that already exist in order to make use of the existing animation sets within UDK.
Weighting a Mesh to a Skeleton
When creating a custom mesh, it is best to create the mesh with the skeleton in mind. The mesh should be modeled with all the joints matching the location already defined by the skeleton. For meshes that don’t follow this rule, the skeleton joints can be rotated to get them to line up to joints in a mesh. The animations in game will orient the bones back to where they need to be to play correctly. Although bones can be rotated, they should never be translated or moved to try and place them where joints are in a mesh. This will give unexpected results in game and squash or stretch a mesh because the animations define where the bones translation will be. For example, if a mesh has shorter legs than defined by the skeleton, and the skeleton’s leg bones are moved to compensate, the legs will be stretched longer in game to match the length of the other character’s legs. This keeps all pieces connected correctly during the in-game character setup. The correct way to fit meshes to the skeleton is to rotate the joints as needed to get them as close as possible if needed and/or modify the mesh to fit. Creating characters with different proportions will require a new master skeleton, and if the proportions are very different than characters that already exist, they may require their own animations as well which is beyond the scope of this document.
Take the mesh below as an example. It has been modeled with the male skeleton in mind. All the major joints and body parts line up well with the skeleton so that no major adjustments are necessary. This makes it extremely simple when it comes time to weight the mesh to the skeleton.
Merge in the bones from the UT3_Male.max file, delete the bones that aren’t needed, and then weight the mesh to the skeleton. In this case, the mesh has no extra parts or ‘flappy bits’ that would require extra bones so only the bare essentials are left on the skeleton for the weighting.
Next is to export your character and get it into the engine. Skeletal meshes are exported from the 3D application by using the FBX exporter that is built-in to the application. Then follow the guide on exporting your mesh into a skeletal mesh using the FBX file format.
Open up Unreal Editor and open the Content Browser. Then follow the guide on importing skeletal meshes using the FBX file format.
Once the mesh has been imported, save the package in the following directory:
Adding Sockets to the Mesh
Sockets are user-defined points on a skeletal mesh. They can be added to any skeletal mesh; and in UDK, they are used for many things, including points from which to emit particles or places to attach weapons. These need to be added to each mesh in order for your character to function correctly in-game. To add sockets, double-click on the skeletal mesh on which you would like to add them in the Content Browser window. A skeletal mesh/animation set editor (the AnimSet Editor) window will come up. Click on the Socket Manager icon, or select Socket Manager from the Mesh menu to bring up the Socket Manager window.
Sockets are created by selecting New Socket, choosing which bone the socket will be attached to, and then creating a name for the socket.
The UTGame characters that come with UDK have specific sockets that are required in order for a custom character to work with the current codebase. If you wish to be able to drop in your own characters and have them work properly without any extra coding, your meshes need to have, at the very least, these sockets:
The character’s feet or boots need two sockets to give a place for particles to emit from when using jump boots. These socket names are L_JB for the left foot and R_JB for the right foot. For example, to add the L_JB socket, select New Socket, choose the bone b_LeftAnkle, then for the socket name type L_JB.
Sockets can be translated and rotated so they can be placed in the correct place relative to the mesh. Upon creation, these sockets appear at the origin of the ankle bone; but the particles need to emit from the bottom of the foot. In the Socket Manager window, the first two icons are translate socket and rotate socket. With translate socket on, move the socket to the bottom of the foot. Some sockets may need rotating as well to make sure that particles emit the correct direction or that objects attach with the correct orientation. You can open the Socket Manager window on other skeletal meshes that shipped with the game to get an idea of how and where these sockets should be placed.
More information about sockets can be found here.
Quickly copying sockets from an existing UDK character
If you are using the same skeletal rig in your skeletal mesh as another existing skeletal mesh that is stored in the package, you can quickly copy the sockets over without having to recreate them yourself. For example, open up the Skeletal mesh stored as CH_LIAM_Cathode.Mesh.SK_CH_LIAM_Cathode. Open the Socket Manager, and click on the Copy Sockets button.
Then open up your skeletal mesh. Open up the Socket Manager, and click on the Paste Sockets button and you're done!
Setting Up Your Character for Use In-Game
The final step is to configure UDK to make use of your new character. This process is going to require diving into UnrealScript to create one new class, a subclass of UTFamilyInfo, and to modify one existing class, UTPlayerReplicationInfo. Of course, there is a lot more we could do in order to create a completely custom playable character in UDK, but much of that is beyond the scope of this document. We are only going to focus on the bare essentials of getting your character up and running.
UTFamilyInfo class is basically a container for properties which allow you to specify which meshes, physics assets, animsets, materials, gibs, etc. to use for a particle character or group of characters. While this class does contain some other functionality, for the purposes of this document it is acceptable to simply see it as a place to set some properties to allow you to put your character into UDK.
In this example, we will be creating a single subclass and using it for just one character. You could, in theory, create a hierarchy of these classes where a class would subclass from
UTFamilyInfo and define the general properties for a group of characters that all share something in common. For example, a group of characters might all share a common theme in terms of their appearance. These characters would be considered part of the same faction. You could then create multiple subclasses of this new class. Each of these could be for a specific character within that faction and they could even specify a family they belong to within that faction to further categorize your characters.
Before you go any further, you first need to create a new subclass of this class for your character.
Now, in the default properties block of this class, you can set or override properties to create your custom character. The most important property in your new UTFamilyInfo class is the CharacterMesh property. As you may have guessed, this property should reference the skeletal mesh you imported previously. For our example this would be:
Class UTFamilyInfo_SpaceMarine extends UTFamilyInfo
You should continue to go through and continue setting the properties to point to your own custom assets. Some of the important properties are described below.
Of course there are many more properties which you may want to set and can all be found in the UTFamilyInfo.uc script, most with descriptive comments.
Once you have set up the properties for your character, save it in the following directory:
- Faction – The name of the overall group this character or group of characters belongs to.
- FamilyID – The name of the family this character belongs to.
- CharacterTeamBodyMaterials – This is an array of the materials to use as the character’s body material for team games. 0 index is for red, 1 index is for blue.
- CharacterTeamHeadMaterials - This is an array of the materials to use as the character’s head material for team games. 0 index is for red, 1 index is for blue.
- PhysicsAsset – This is a reference to the physics asset created for your character’s skeletal mesh.
- AnimSets – This is an array of the AnimSets to use for your character(s).
- ArmMeshPackageName – The name of the package containing the 1st person arms mesh for this character.
- ArmMesh – This is a reference to the 1st person arms mesh for this character
- ArmSkinPackageName – The name of the package containing the materials for the 1st person arms mesh.
- RedArmMaterial – This is a reference to the red team material for the 1st person arms mesh.
- BlueArmMaterial - This is a reference to the blue team material for the 1st person arms mesh.
Now, you need to tell UDK to use this new class instead of the current default class. This can be done in the UTPlayerReplicationInfo.uc file in the default properties block. The last line should currently read:
All you need to do is modify the class to point to your newly created
UTFamilyInfo class. In this example, the line would now be:
Save the UTPlayerReplicationInfo.uc script and then rebuild the scripts. Hopefully, you will not be met with any errors from the compiler and you can go test out your new character in the game.