Created
June 1, 2017 21:42
-
-
Save OmarShehata/a9f86e091fe14c050fc200a1fa31fa10 to your computer and use it in GitHub Desktop.
Rebinding Keys at runtime in Unreal Engine 4.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void RebindAction(FName ActionName, FKey NewKey) { | |
// Adapted from Rama's VictoryBPFunctionLibrary (https://wiki.unrealengine.com/Rebinding_Keys_At_Runtime_in_Packaged_Game) | |
UInputSettings* Settings = const_cast<UInputSettings*>(GetDefault<UInputSettings>()); | |
if (Settings) { | |
TArray<FInputActionKeyMapping>& Actions = Settings->ActionMappings; | |
for (FInputActionKeyMapping& Each : Actions) | |
{ | |
if (Each.ActionName == ActionName) { | |
Each.Key = NewKey; | |
UE_LOG(LogTemp, Warning, TEXT("%s is triggered by %s"), *Each.ActionName.ToString(), *Each.Key.ToString()); | |
} | |
} | |
//SAVES TO DISK | |
const_cast<UInputSettings*>(Settings)->SaveKeyMappings(); | |
//REBUILDS INPUT, creates modified config in Saved/Config/Windows/Input.ini | |
for (TObjectIterator<UPlayerInput> It; It; ++It) | |
{ | |
It->ForceRebuildingKeyMaps(true); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment