Doubt with UPlayerInput and UInputSettings

Hi all!

I have seen that these 2 classes have a TArray< struct FInputActionKeyMapping > ActionMappings variable, and was wondering about the difference among them.
If i want to change the key binded to my “Jump” action while i’m ingame, what variable should i modify?

As i see, only UInputSettings has a SaveKeyMappings() method.

See ya!

UInputSettings is the project level settings that are modified from the Input section of the Project Settings in the editor.

UPlayerInput is the runtime system.

In general I would think it would be best to use UInputSettings as your project defaults, and have an alternative system for storing the per-user configured keybinds and apply your user settings to the UPlayerInput array.

I’m testing doing this:



void UMappingsHelper::RemapTest()
{
    UPlayerInput* playerInput = Cast<APlayerController>(Cast<APawn>(GetOwner())->Controller)->PlayerInput;
    playerInput->ActionMappings[0].Key = EKeys::G;

    UE_LOG(LogTemp, Log, TEXT("Updated action %s with the G key."), *playerInput->ActionMappings[0].ActionName.ToString());
}


My first action mapping is Forward, and i have 2 keys binded to it (W and I).
If i’m not wrong, doing this i exchange the W key with the G key, so, Forward event should be fired if i push G key down, right?

The class is currently inheriting from UActorComponent, and i call the function from the blueprint system.
Also, the component is attached to my default Pawn, which is auto possessed by my player controller.

I have tested the code and i see the message, but when i push the G key nothing happens :S.

See ya!

You should use Add/RemoveActionMapping to remove the previous (W) mapping and add in the new (G) mapping. Ideally those arrays wouldn’t actually be publically visible (in fact, I might take a look at whether I can make them private), the arrays are used to build an efficient run time map structure, so until you cause that to be rebuilt (which Add/RemoveActionMapping) do, you won’t see the change reflected.

It works perfect, thanks!

I have noticed the changes dissapears when i exit from the play in editor mode, i suppose i have to call the SaveConfig method in the UPlayerInput class, right?

See ya!