Hello, following this old post, I have tried to implement the code to detect whether gamepad is connected.
//GenericApplication.h
virtual bool IsGamepadConnected() { return false; }
//WindowsApplication.h
virtual bool IsGamepadConnected() override;
//WindowsApplication.cpp
bool FWindowsApplication::IsGamepadConnected()
{
return XInput->IsGamepadConnected();
}
//XInputInterface.h
bool IsGamepadConnected();
//XInputInterface.cpp
bool XInputInterface::IsGamepadConnected()
{
for (int32 ControllerIndex = 0; ControllerIndex < MAX_NUM_XINPUT_CONTROLLERS; ++ControllerIndex)
{
FControllerState& ControllerState = ControllerStates[ControllerIndex];
if (ControllerState.bIsConnected)
return true;
}
return false;
}
//MyPlayerController.cpp
TSharedPtr<GenericApplication> GenericApplication = SlateApplication::Get().GetPlatformApplication();
GenericApplication->IsGamepadConnected();
The function “GenericApplication->IsGamepadConnected()” returns “true” in the editor (PIE), but in a “package build” or a “Standalone Game” returns “false” (Windows). Anyone know why?
Another problem is that “ControllerStates[MAX_NUM_XINPUT_CONTROLLERS]” is private, and to implement it I must to do on the Source version. This is a problem because all computers on our team have Binary version installed.
It would be possible to add a “getter” (accessor method) to access the attribute in a new fix of the engine?
If this is not possible, any workaround?
Thx a lot