Difference between the PlayerInput from controller and the UInputSettings

I do not understand why we have action and axis mapping in the PlayerInput from the player controller and also in the UInputSettings.

In the player controller I can access action key mapping

		TArray<struct FInputActionKeyMapping> ActionKeys = LocalPlayer->PlayerController->PlayerInput->GetKeysForAction(ActionName);

But I can find exactly the same in the UInputSettings.

UInputSettings* Sets = UInputSettings::GetInputSettings();

I’m trying to change the action and axis mapping dynamically.

If I change the action mapping using the PlayerInput from the controller and save it, nothing is saved on the disk.

LocalPlayer->PlayerController->PlayerInput->ForceRebuildingKeyMaps();
LocalPlayer->PlayerController->PlayerInput->SaveConfig();

Now If I change the action and axis mapping from the UInputSettings and call the

UInputSettings* Sets = UInputSettings::GetInputSettings();
Sets->SaveKeyMappings();

Also nothing is saved to the Input.ini

I don’t understand why we do have the same information at two places.
And therefore, do we have to change the action and axis mapping to the UInputSettings OR to the PlayerInput from the Controller.

And why in both cases, nothing is saved ?

Hello domzorg,

If you want to add or remove key mappings at runtime you need to get the UInputSettings and pass a FInputActionKeyMapping or FInputAxisMapping to the relevant function. You can find your key mappings stored in Inttermediate->Config->CoalescedSourceConfigs->Input.

   UInputSettings *Settings = const_cast<UInputSettings*>(GetDefault<UInputSettings>());
	if (Settings)
	{
		FInputAxisKeyMapping axisMap;
		axisMap.AxisName = "TestInput";//Name of the axis map
		axisMap.Key = FKey(FName("V"));//The actual input you have to use for that axis or action
		axisMap.Scale = 1.0f;
		Settings->RemoveAxisMapping(axisMap);
		Settings->SaveKeyMappings();
		UE_LOG(LogTemp, Warning, TEXT("Setttings altered"));

		FInputActionKeyMapping tempMapping;
		tempMapping.ActionName = "NewActionMapping";
		tempMapping.Key = FKey(FName("U"));
		
		tempMapping.bAlt = false;
		tempMapping.bCmd = false;
		tempMapping.bCtrl = false;
		tempMapping.bShift = false;

		Settings->AddActionMapping(tempMapping, true);
		Settings->SaveKeyMappings();

		//IC = Input Component
		IC->BindAction("NewActionMapping", IE_Pressed, this, &AMyPawn::PrintName);
	}

From,

UInputSettings:

1 Like

Thank you. It works with the UInputSettings.
As I can finally see, when the UInputSettings is changed, the InputSettings from the PlayerController is updated.