Course contentsShow
← Unreal Engine Game Development
Lesson 234 of 8804. Advanced Input and PhysicsFree lesson

Creating Custom Input Modifier Classes

You will develop reusable C++ modifier classes to transform raw input values for unique gameplay mechanics like sensitivity curves or deadzone logic.

In this lesson, you will learn how to build your own C++ Input Modifier classes to mathematically transform raw player input before it reaches your game logic.

Why Create Custom Modifiers?

While the Enhanced Input system provides standard modifiers like "Deadzone" or "Negate," you will often need specialized behavior—like custom sensitivity curves for a sniper scope or a specific acceleration ramp for a vehicle. By inheriting from UInputModifier, you create a reusable logic container that can be plugged into any Input Mapping Context.

Implementing the Modifier

To create a custom modifier, inherit from UInputModifier. You must override the ModifyRaw function. This function takes the current input value and the FInputActionValue and returns the transformed result.

Here is a simple example of a "Power Modifier" that squares the input value to create a non-linear feel:

UCLASS(NotBlueprintable, MinimalAPI, meta=(DisplayName="Power Input Modifier"))
class UInputModifierPower : public UInputModifier
{
    GENERATED_BODY()

protected:
    virtual FInputActionValue ModifyRaw_Implementation(const UEnhancedPlayerInput* PlayerInput, FInputActionValue CurrentValue, float DeltaTime) override
    {
        // Get the current vector value
        FVector AxisValue = CurrentValue.Get<FVector>();
        
        // Apply a square power curve to the X axis
        AxisValue.X = FMath::Pow(AxisValue.X, 2.0f);
        
        return FInputActionValue(AxisValue);
    }
};

How It Works

  1. The Signature: ModifyRaw_Implementation provides the CurrentValue (raw data from the hardware) and the DeltaTime (in case your modification needs to be frame-rate independent).
  2. The Transformation: You manipulate the data inside the FInputActionValue object. Because it is a generic container, you can use .Get<FVector>() to access the underlying components regardless of whether the input is a 1D, 2D, or 3D axis.
  3. The Pipeline: Because these classes are processed within the Enhanced Input system, your custom modifier behaves exactly like a built-in one. You can stack it alongside others in your Input Mapping Context, allowing for modular, chainable input processing that keeps your Character code clean and focused.

Key Takeaway: Custom Input Modifiers allow you to encapsulate math-heavy input transformations into modular, reusable C++ classes that process raw input before it ever touches your gameplay logic.