As originally posted in the UDK forums here comes a more permanent page including this mini-tutorial, which will guide you through the steps to have body part disemberment in your characters using the BoneBreak feature in UDK, a mostly unknown and undocumented feature.
This is a guide for advanced users that already know how to weight their models, get them exported and have a certain knowledge of UnrealScript. This won’t cover basic topics like ‘how to export’ or ‘how to set the weights’.
Also notice this has been tested on the UDK April’11 build and later ones, and it’s not guaranteed to work on earlier versions.
For this guide, we’ll assume we want to break the head off, which is rigged to use the bone Bip01-Head (the one we’ll be breaking)
1. Prepare your skeletalmeshes for dismemberment. to do this, the part you want to break needs to have its own unique polygons/vertices where you’d want to break it. UDK will not break your meshes, only the bones, your meshes must already come “pre-broken”. to be sure it’s correct, in 3dsmax go to sub-object -> element, select the one you’d want to break and move it, if you see stretching then it won’t break off. it needs to already look breakable like this:
2. Export your skeletalmesh normally, then duplicate it. now on the duplicate, modify the bone weights so that the breaking bone (the head bone) fully affects the breakable element of the mesh and nothing more (ie. the neck bone needs to have zero influence on the head section, and the head bone to have zero influence on the neck).
now export the duplicate as a different skeletalmesh file
3. Make sure your character uses a Phys Asset (ie. ragdoll must work on your character). what you’ll really be breaking isn’t really the bones of the character, but the phys bodies attached to those bones instead. this means that for a bone to be breakable, there needs to be a phys body specifically attached to that bone in your Phys Asset (bodies attached to child bones won’t work)
4. Make your skeletalmesh use the BoneBreak feature. Follow [this] guide if you need detailed info, else do the following:
4a. In content browser, the double click your skeletal mesh to open it via the animset editor
4b. In the top left, click on the ‘Alt. Bone Weighting’ menu, select ‘Import Mesh Weights’, leave ‘0’ as the Existing LOD Level, click ‘Ok’.
4c. In the dialog, under `Mesh Base Filename’, click the […] button to select your base mesh (the regular in-game mesh). then under ‘Mesh Weights Filename’ click the […] button and select the special duplicate mesh you already exported. click ‘Ok’.
4d. In the next dialog, leave the ‘Weight Usage Type’ option as ‘Full Weight Swap’ and click ‘Ok’.
4e. To toggle between the regular and bone-breakable versions of the mesh click on the ‘Alt.Bone Weighting’ menu and select ‘Toggle Mesh Weights’.
4f. If you did everything correctly, you should be able to move the bone using the widget and it should move cleanly without stretching any verts (if you have the ‘Toggle Mesh Weights’ option ticked, else you’ll see it stretch). If this isn’t the case, check that the weights are correct to every bone on the duplicate mesh in 3dsmax, re-export the duplicate again, and repeat steps 4-b to 4-e of this guide.
5. Save your packages, exit the editor, open your script files and find the part where the pawn takes damage (event TakeDamage)
at the top of the TakeDamage function you’ll need a new vector and a new int for an iterator
local Vector Impulse, HitLoc;
local int LODIdx;
And then somewhere else inside that function, add the following lines of code:
Mesh.BreakConstraint(Impulse, HitLoc, ‘Bip01-Head’);
for (LODIdx=0; LODIdx < Mesh.LODInfo.length; LODIdx++ )
I’m using a modular Pawn, so ‘Mesh’ and ‘TorsoMesh’ in the previous code are the meshes from the pawn that I’m updating the weights for (which does exactly what the editor does when you check ‘Toggle Mesh Weights’ but in-game). In this case I’m breaking the ‘Bip01-Head’ bone so I’m updating my character’s Head and Torso meshes (my pawn’s ‘Mesh’ is the head).
If you’re not using a modular Pawn (ie. you only use a single mesh) you just need to update your base mesh.
If you wish to break a different bone you’d need to run the BreakConstraint function with the appropriate bone name, and toggle the relevant meshes for a modular Pawn (ie. to break the bone name ‘Bip01-RUpperArm’ I would need to toggle my TorsoMesh and ArmRMesh).
You’ll probably want to run checks to see that the character is about to die before taking his head off though.
note: the broken part won’t have physics until the character enters ragdoll (unless you use the phys asset as physics instead of the regular phys cylinder, which isn’t recommended), this means if your character doesn’t die the broken part will fall through the floor.
In case you’re wondering, on the BreakConstraint function if you use a real (ie. non-blank) vector for the Impulse, the head will fly away using that impulse. HitLoc is better left as a blank vector so that the snapping occurs just where the head was though (I believe if you change the HitLoc, the head will be teleported to this new location and then snap, but I’m not sure)
Edit: Found an easier and more effective way to have the verts correct, by using the ‘Full Weight Swap’ option instead of ‘Partial Weight Swap (Gore)’. This also needed a few extra lines of code but it’s now included as well