#unreal

There are two ways to adjust mouse sensitivity in Enhanced Input:

  1. If you want to adjust sensitivity just for development purposes, you can go into your Look Input Action and add a Scalar modifier. This allows you to tweak the value, but it’s hardcoded.
  2. For a more useful sensitivity adjustment function, you need to store the sensitivity value somewhere. Enhanced Input provides an Enhanced Input System User Settings class for this purpose. A custom input modifier can then read the sensitivity value from the configuration, allowing it to be changed on the fly, or via an options menu.

Creating a user settings class

The first step is creating a user settings class for enhanced input settings. The purpose of this class is to store the sensitivity value, so that we can later use it elsewhere. This class will also automatically work correctly in packaged games, so if you create an options menu which allows changing the sensitivity value, it will work and save the settings correctly.

//h
UCLASS()
class MY_API UMyEnhancedInputUserSettings : public UEnhancedInputUserSettings
{
	GENERATED_BODY()
 
public:
	void SetAimSensitivity(float SensitivityX, float SensitivityY);
 
	FVector GetAimSensitivityVector() const;
	
protected:
	UPROPERTY(EditAnywhere, Config)
	float AimSensitivityX = 1;
	
	UPROPERTY(EditAnywhere, Config)
	float AimSensitivityY = 1;
};
 
//cpp
void UMyEnhancedInputUserSettings::SetAimSensitivity(float SensitivityX, float SensitivityY)
{
	AimSensitivityX = SensitivityX;
	AimSensitivityY = SensitivityY;
 
	//this does nothing by default except trigger a delegate you could
	//bind to in order to update UIs or such
	ApplySettings();
}
 
FVector UMyInputUserSettings::GetAimSensitivityVector() const
{
	//this is purely a convenience function that we can use in the input modifier
	return FVector(AimSensitivityX, AimSensitivityY, 1);
}

To make this work, you need to go into Project Settings, Enhanced Input, and enable Enable User Settings. Then change the User Settings Class value to your new settings class.

Creating an input modifier

Next, we need to create an Input Modifier. The modifier changes the “raw” input value based on the saved sensitivity value.

//h
UCLASS()
class MY_API UMyInputModifierAimSensitivity : public UInputModifier
{
	GENERATED_BODY()
 
protected:
	virtual FInputActionValue ModifyRaw_Implementation(const UEnhancedPlayerInput* PlayerInput, FInputActionValue CurrentValue, float DeltaTime) override;
 
	UPROPERTY(Transient)
	UMyEnhancedInputUserSettings* Settings;
};
 
//cpp
FInputActionValue UMyInputModifierAimSensitivity::ModifyRaw_Implementation(const UEnhancedPlayerInput* PlayerInput, FInputActionValue CurrentValue, float DeltaTime)
{
	if(!Settings)
	{
		Settings = PlayerInput->GetOwningLocalPlayer()->GetSubsystem<UEnhancedInputLocalPlayerSubsystem>()->GetUserSettings<UMyInputUserSettings>();
	}
	
	return CurrentValue.Get<FVector>() * Settings->GetAimSensitivityVector();
}

With the input modifier class created, you need to add it into the modifiers list for your look action. Once this is done, the sensitivity value should affect the look speed. For ease of testing during development, I recommend Creating a custom SetMouseSensitivity console command for Enhanced Input

Other tips

Many games have more than one sensitivity setting. In that case, you can either make separate modifiers for each setting, or make one modifier which is configurable.

A simple way to make the modifier configurable is to use a Gameplay Tag. For example, you can have tags such as Input.Sensitivity.Mouse or Input.Sensitivity.LeftStick. You can give the modifier a UPROPERTY for the tag, which allows you to configure it from the input configuration assets. Similarly, you can add a TMap<FGameplayTag, float>, or some other similar solution, to your user settings class. This way you can easily get and set different sensitivity values via tags.

See also