Mantle
Explore how to create a Mantle system for your Unreal Engine 5 game.
Last updated
Explore how to create a Mantle system for your Unreal Engine 5 game.
Last updated
In this tutorial, we will explore how to create a Mantle system for your Unreal Engine 5 game. We will see how to enable your character to perform mantling movements on various surfaces.
For this tutorial, I will be using the ThirdPerson template
. I recommend you do the same to make it easier to follow. However, if you prefer, you can certainly work from an existing project or even start from scratch. Once the project is open, if you are not yet familiar with the installation and configuration of the plugin, I suggest following this quick tutorial beforehand.
If you have followed the installation correctly, your character class should normally inherit from AMS_Character
, and your CharacterMovementComponent
should inherit from AMS_CharacterMovementComponent
. Also, make sure to use the OnMoveOnGround
method to move. If everything is in place, then that's perfect!
The plugin is designed to be as unrestrictive as possible, allowing everyone to use the method they prefer. For our tutorial, we will use the Motion Warping plugin
, as it provides smooth and natural transitions, dynamically adapts to surfaces, and reduces the need for specific animations. This makes integration easier and enhances gameplay immersion.
In your project, go to Edit -> Plugins
to open the plugin browser. Once the plugins window is open, use the search bar to find Motion Warping
. Check the box to activate the plugin, then restart the editor to apply the changes.
To create a visually pleasing example, we will download high-quality animations from GASP demo provided by Epic Games. These animations, created by professionals, are available for free. Isn't that great?
Migrate the animation montage AM_M_Neutral_Traversal_Climb_Start_2_5_stand_F_Rfoot to your project.
If you’re not sure how to migrate elements from GASP to your project yet, I recommend checking out this tutorial. It’s really simple and quick to do, you’ll see!
If everything is good, you should have a folder named UEFN_Mannequin
added to your project with the animation montage you selected.
To start, you can go to the Details tab of the character and access the Debug Settings section to display the traces, if you wish. This will allow you to better observe the behavior of the detection in case of any issues.
Next, to configure the mantling detection, go to the Details tab of the CharacterMovementComponent. The search bar will help you quickly access the section dedicated to mantling. In this section, you will find the MantleDetectionTrace structure
, which includes several sub-structures that allow you to adjust the detection of walls and ledges, as well as the necessary available space.
You can adjust the distance by setting a fixed value called Base Distance
. If you wish, you can then dynamically modify this distance based on the speed and height of the capsule using the influence factors
. You also have the option to choose whether these influences apply only when you are on the ground, which is often the case.
Here’s an example where I set the MaxVelocityInfluenceFactor
value of WallDetectionForwardDistance
to 200
.
In this example, given that we are taking a simple approach with few animations, we will use static detection. However, we will make use of the influence factors
to adjust the detection based on whether the character is on the ground or in the air. Refer to the image below to configure the detection using the same settings as shown.
To perform a mantle, simply call the StartMantle
method to make the character climb on the next update.
If the checks in CanMantle
and the detection are valid, the method will then trigger the OnMantleStarted
event after executing all the necessary logic. We will use this event to trigger our animations as well as perform other actions. To do this, go to the Details tab of the CharacterMovementComponent and select the event to add it to the event graph.
We will use the PlayMontage
function of the SkeletalMesh
to play the animation montage AM_M_Neutral_Traversal_Climb_Start_2_5_stand_F_Rfoot
. This will allow us to handle the necessary events to stop the mantle at the right moment.
If you test the mantle near a wall, the animation should play as expected. You'll notice that, for now, it's the animation that controls the character's movement. In our case, what we want is to control the movement until the edge, and then let the animation handle the rest of the movement, but only once the character is properly adjusted.
To do this, we will use motion warping. The GASP animation montage already includes the necessary Animation Notifications
. Set the WarpPointAnimProvider
to static
and adjust the Z axis
(I set it to 260
).
If you're using UEFN mannequin or another that includes the Attach bone
, you can skip this step. Just make sure the WarpPointAnimBoneName
matches your bone's name.
Next, create a method in your character's Blueprint to generate the warp target that will be used by your anim montage. In my example, I named it CreateMantleWarpTargets
so that I can easily add other warp targets related to the mantle if needed. Add an input parameter of type MantleCheck
to the function, which contains all the relevant information sent by the trace. With this data, you'll be able to get the position and rotation of the FrontLedge
and use them to define your warp target.
Then, call the method you just created in the OnMantleStarted
event, right before playing your anim montage.
Great, the mantle system is now functional and adapts perfectly to different wall heights!