I’m writing automated tests where a character needs to perform various actions like jumping or running using the Enhanced Input system in Unreal Engine. Previously, in the old input system, testing BindAction
could be done with a simple Execute(Key)
function call. However, in Enhanced Input, this approach doesn’t work because the Execute
function expects an InputActionInstance
structure where no values can be changed.
Example 1:
void DoInputAction(UInputComponent* Input, const FString& ActionName, const FKey& Key)
{
if (!Input) return;
const int32 ActionIndex = GetActionBindingIndexByName(Input, ActionName, EInputEvent::IE_Pressed);
if (ActionIndex != INDEX_NONE)
{
const auto ActionBind = Input->GetActionBinding(ActionIndex);
ActionBind.ActionDelegate.Execute(Key); // This approach doesn't work for Enhanced Input
}
}
Example 2:
for (auto& ActionBinding : InputComp->GetActionEventBindings())
{
const ETriggerEvent TriggerEvent = ActionBinding->GetTriggerEvent();
const FString ActionName = ActionBinding->GetAction()->GetName();
if (TriggerEvent == ETriggerEvent::Triggered && ActionName == "IA_Move")
{
FInputActionInstance InputActionInstance;
ActionBinding->Execute(InputActionInstance); // This code doesn't work due to InputActionInstance structure limitations
}
}
How to elegantly write automated tests for Action Bindings in Enhanced Input, considering the constraints of the InputActionInstance
structure and the inability to use Execute
to trigger actions?