We’re using the Unreal ImGui plugin which is driven through Slate. We would like to be able to open the debug menu with a more complex button combo on the gamepad e.g. left thumbstick and start button. Basically, we would be using the left thumbstick (or some other button) as a modifier in the same way that you might use shift or control on the keyboard.
Is there a way to either directly query the input state of the controller to see what buttons are currently down or is there a built in way to do button combos?
Yes, you can query the input state of the controller to see what buttons are currently down in Unreal Engine. You can use the GetInputKeyDown or GetInputKeyTimeDown functions of the APlayerController class to check whether a particular button is currently down.
To check if a button combination has been pressed, you can keep track of the current state of the modifier button (in this case, the left thumbstick) and the other button (in this case, the start button) in your game code. You can then check the state of both buttons in your game code to determine if the button combo has been pressed.
Here’s an simple example of a left thumbstick and start button combo:
bool bLeftThumbstickDown = false;
// check for the left thumbstick and start button combination
bool IsDebugMenuButtonComboPressed()
{
// get the player controller
APlayerController* PlayerController = GetWorld()->GetFirstPlayerController();
// check if the left thumbstick is currently down
if (PlayerController->GetInputKeyTimeDown(EKeys::Gamepad_LeftThumbstick) > 0.f)
{
bLeftThumbstickDown = true;
}
else if (PlayerController->GetInputKeyTimeUp(EKeys::Gamepad_LeftThumbstick) > 0.f)
{
bLeftThumbstickDown = false;
}
// check if the start button is currently down and the left thumbstick was pressed before
if (PlayerController->IsInputKeyDown(EKeys::Gamepad_Special_Right))
{
if (bLeftThumbstickDown)
{
// the button combo has been pressed
return true;
}
}
return false;
}
You can now call the IsDebugMenuButtonComboPressed function in your game code to check if the button combo has been pressed. If it returns true, you can then open the debug menu.