Blog

Tutorial: BoneBreak for dismemberment

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.

If you follow the guide properly you’ll be able to see the enemy’s head chopped off cleanly. In my case I also have it set up for more body parts :)

 

 

 

 

 

 

 

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++ )
{
Mesh.ToggleInstanceVertexWeights(true, LODIdx);
TorsoMesh.ToggleInstanceVertexWeights(true, 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

This Post Has 8 Comments

  1. KillerSneak says:

    Hi smi-great tutorial.

    Some extra screenshots of the process would be nice. When you have an all cut up/pre-broken mesh your animations will look freaky as the “skin” isn’t really one skin anymore but every part will have it’s separate skin?

    Hope you’re willing to explain it some more or at least try to add a screenshot at each step.

    Kind regards,
    KillerSneak

    • Chosker says:

      You can add the same Skin modifier to multiple objects in max. If you only rely on Skin Envelopes for your vertex weights you won’t have weighting problems at the seams.

      This tutorial was only meant to fill in the ‘code’ part that UDN missed, and I won’t be adding more explanations. What part are you having trouble with?

  2. .Wrath says:

    Any notes on the resource economy of this feature? I’m trying to make a general judgement of how intensive it will become if I have a number of enemies in my level all getting their limbs blown off by clients. I assume that the dismembered body part is still part of the same skel mesh component so the cleanup of the lost limb happens when that pawn dies and/or is restarted?

    • Chosker says:

      I never really made a proper performance comparison test but it didn’t seem any intensive. Probably just slightly more expensive than using regular ragdolls.
      The dismembered body part is still part of the same skeletalmesh, yes. if you delete the Pawn the body parts get deleted, just like a regular ragdoll as well.

  3. 9454 says:

    Is it possible to locate the position of the chopped off head lying on the floor, so that I can spawn a blood decal at that position?

Leave A Reply