I wrote this to get the action name, as I base my character State on the action name. I used the key given by the InputAction Is there a more simple way ?
void URequestActionStateChange::BeginPlay()
{
Super::BeginPlay();
SetCurrentActionState(DefaultState);
GetActionAndKeyArray();
}
//filling the provided TArray<FInputActionKeyMapping> with ActionName and Key value
void URequestActionStateChange::GetActionAndKeyArray()
{
ActionAndKeyArray.Empty();
UInputSettings* InputSettings = InputSettings->GetInputSettings();
//empty array to be filled by iterator
TArray<FName> ActionNames;
//filling ActionNames array with action names
InputSettings->GetActionNames(ActionNames);
//filling ActionNameAndKey array with ActionName and Key value
for (size_t i = 0; i < ActionNames.Num(); i++)
{
FName ActionName = ActionNames*;
InputSettings->GetInputSettings()->GetActionMappingByName(ActionName, ActionAndKeyArray);
}
return;
}
FString URequestActionStateChange::GetActionNameFromKeyPressed(FKey KeyPressed)
{
for (FInputActionKeyMapping Mappings : ActionAndKeyArray)
{
FString Action = Mappings.ActionName.ToString();
FKey Key = Mappings.Key;
if (Key == KeyPressed)
{
return Action;
}
}
return FString("Error : Key Not Found in URequestActionStateChange::GetActionNameFromKeyPressed");
}