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
- The Signature:
ModifyRaw_Implementationprovides theCurrentValue(raw data from the hardware) and theDeltaTime(in case your modification needs to be frame-rate independent). - The Transformation: You manipulate the data inside the
FInputActionValueobject. 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. - 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.