Course contentsShow
← Unreal Engine Game Development
Lesson 104 of 8802. The Gameplay FrameworkFree lesson

Creating Custom Movement Modes

You will extend the Character Movement Component to add unique movement states like swimming, flying, or wall-running for specialized gameplay.

Creating Custom Movement Modes

In this lesson, you will learn how to expand the UCharacterMovementComponent to support specialized traversal styles, such as wall-running or sliding, by defining custom movement modes.

Why Custom Modes?

The CharacterMovementComponent (CMC) is the "brain" behind how your character interacts with the physics world. While Unreal provides standard modes like MOVE_Walking and MOVE_Flying, you often need more control for unique mechanics. A Custom Movement Mode allows you to override the default physics logic, enabling you to define exactly how velocity, gravity, and friction should behave in a specific state.

How it Works

To create a custom mode, you must extend the UCharacterMovementComponent class. You start by adding a new entry to the EMovementMode enum (or using the MOVE_Custom index).

The magic happens by overriding the PhysCustom(float deltaTime, int32 Iterations) function. This function acts as the gatekeeper for your custom logic. Whenever the movement mode is set to a custom state, the CMC triggers this function every frame instead of the standard movement code.

Here is a simplified look at how you might structure this:

void UMyCharacterMovementComponent::PhysCustom(float deltaTime, int32 Iterations)
{
    Super::PhysCustom(deltaTime, Iterations);

    switch (CustomMovementMode)
    {
        case CMOVE_WallRunning:
            PerformWallRun(deltaTime, Iterations);
            break;
        default:
            break;
    }
}

By branching inside PhysCustom, you can implement custom velocity calculations—such as sticking the player to a vertical wall—without breaking the existing walking or falling logic. You transition to this state by calling SetMovementMode(MOVE_Custom, CMOVE_WallRunning) within your character class.

Pro-Tip

Always ensure your custom physics calculations are performant and handle deltaTime correctly. Since PhysCustom runs every frame, heavy calculations here can significantly impact your game’s frame rate. If your logic involves complex environment queries, try to cache results or perform them only when the character’s state changes.

Key Takeaway: By overriding PhysCustom within a CharacterMovementComponent subclass, you can inject bespoke physics logic into the Unreal engine, allowing your character to defy standard movement rules.