Unreal Engine Dismemberment 1

Overview
I will show you two ways to implement simple limb dismemberment in Ureal Engine.
The first way needs no extra assets but requires that you can separate your skeleton mesh.

The second way requires assets for the limbs you want to dismember.

Dismemberment 1

Your mesh has detachable limbs which do not “stretch”. You will know what I mean by “stretching” as soon as your try it yourself. If they are detachable, they should look like this.

All you have to do here is remove the bone’s constraints. If you also add an impulse, the bone will fly away.

Blueprint

C++

GetMesh()->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
GetMesh()->BreakConstraint({0.f, 0.f, 0.f}, {0.f, 0.f, 0.f}, "lowerarm_r");

Dismemberment 2

Let’s say your skeleton mesh is not detachable but instead starts to stretch. Then it gets a little bit more complicated. Let’s start with the setup.

First, create an actor blueprint and add StaticMesh or SkeletalMesh component depending on what kind of mesh your limb is.

Second, add a socket to the bone you want to detach. Add your mesh as a preview asset and adjust the location and rotation of the socket such that it will overlap with the original arm.

Now we have to hide the bone, which gets separated and spawn the limb at the same position.

Blueprint

C++

GetMesh()->HideBoneByName("BoneName", EPhysBodyOp::PBO_Term);

auto const BoneSocketLocation = GetMesh()->GetSocketLocation("YourSocket"));
auto const BoneSocketRotation = GetMesh()->GetSocketRotation("YourSocket");

FActorSpawnParameters SpawnParameters;
SpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;

GetWorld()->SpawnActor(YourLimbClass,
                  &BoneSocketLocation,
                  &BoneSocketRotation,
                  SpawnParameters);

That’s it. For example, you can execute these parts of code in an overlap or hit event. These provide you access to the overlapped actor and, therefore, access to the skeletal mesh.

Leave a Reply

Your email address will not be published. Required fields are marked *