# Is there a way to detect a gamepad?

**URL:** <https://forums.unrealengine.com/t/is-there-a-way-to-detect-a-gamepad/300603>\
**Category:** C++\
**Tags:** gamepad, unreal-engine, CPP, Blueprint, question\
**Created:** [December 4, 2014, 7:51pm UTC](https://forums.unrealengine.com/t/is-there-a-way-to-detect-a-gamepad/300603 "2014-12-04T19:51:44Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![OpticalShadows](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@OpticalShadows](https://forums.unrealengine.com/u/OpticalShadows)\
**Post date:** [December 4, 2014, 7:51pm UTC](https://forums.unrealengine.com/t/is-there-a-way-to-detect-a-gamepad/300603/1 "2014-12-04T19:51:44Z")

</div>

Is there a way to detect if a controller is connected or is there an event called when a gamepadis connected?  
Also is there a generic event for getting input from a gamepad(if any button is hit for example)?

It would be used for switching menu navigation icons for example. Press “B” to go back instead of “esc” whether or not a gamepad is connected.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_a4cc7aca](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_a4cc7aca](https://forums.unrealengine.com/u/anonymous_user_a4cc7aca)\
**Post date:** [December 4, 2014, 9:29pm UTC](https://forums.unrealengine.com/t/is-there-a-way-to-detect-a-gamepad/300603/2 "2014-12-04T21:29:21Z")

</div>

Under Project Settings/Input you’ll find where to create key bindings. You can assign “Esc” and “Gamepad\_FaceButton\_Bottom” to the same thing. In order to change HUD icons, Id just create a boolean somewhere in your HUD to either show PC icons or console icons, and set up a menu where your user can switch it to true or false. Not sure how you could do it by controller detection on a PC.

---

<div class="post-metadata">

**Author:** ![OpticalShadows](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@OpticalShadows](https://forums.unrealengine.com/u/OpticalShadows)\
**Post date:** [December 5, 2014, 2:49pm UTC](https://forums.unrealengine.com/t/is-there-a-way-to-detect-a-gamepad/300603/3 "2014-12-05T14:49:41Z")

</div>

I guess I wasn’t clear enough. I am looking for a way to detect if a gamepad is connected to the computer physically.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_957a4452](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_957a4452](https://forums.unrealengine.com/u/anonymous_user_957a4452)\
**Post date:** [December 12, 2014, 9:47am UTC](https://forums.unrealengine.com/t/is-there-a-way-to-detect-a-gamepad/300603/4 "2014-12-12T09:47:35Z")

</div>

Hi,

Unfortunately, there is no such function. But code you need lay in XInputInterface.cpp

```
/** Controller states */
FControllerState ControllerStates[MAX_NUM_XINPUT_CONTROLLERS];

```

This variable is private and XInputInterface has no function to get it. I think the simple way to access to that variable it is add interface that check gamepad.

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;
}

```

And call that where you need

```
TSharedPtr<GenericApplication> GenericApplication = SlateApplication::Get().GetPlatformApplication();
GenericApplication->IsGamepadConnected();

```

In addition, I think it is not very good idea to do that, because we add very specific functions to general functionality. But I hope it will be a start point for solving your problem.

Cheers

---

<div class="post-metadata">

**Author:** ![OpticalShadows](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@OpticalShadows](https://forums.unrealengine.com/u/OpticalShadows)\
**Post date:** [December 12, 2014, 7:36pm UTC](https://forums.unrealengine.com/t/is-there-a-way-to-detect-a-gamepad/300603/5 "2014-12-12T19:36:02Z")

</div>

Thanks for this! Since you said that this solution isn’t ideal, would it make it easier to toggle if any input is detected? For example a controller could be plugged in but until they hit a button/move a stick it’ll still be in “Keyboard” mode. Vice versa for switching from controller mode. Is there a function or utility to detect any keyboard/mouse input and any controller input?

---

<div class="post-metadata">

**Author:** ![OpticalShadows](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@OpticalShadows](https://forums.unrealengine.com/u/OpticalShadows)\
**Post date:** [December 12, 2014, 7:55pm UTC](https://forums.unrealengine.com/t/is-there-a-way-to-detect-a-gamepad/300603/6 "2014-12-12T19:55:01Z")

</div>

I thought of a kludgy solution of creating an action mapping in project settings that just contains every key and every button/axis for keyboard/mouse and controller respectively. Definitely not the best idea but I think it’ll work.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_db2fa921](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_db2fa921](https://forums.unrealengine.com/u/anonymous_user_db2fa921)\
**Post date:** [January 13, 2015, 3:44am UTC](https://forums.unrealengine.com/t/is-there-a-way-to-detect-a-gamepad/300603/7 "2015-01-13T03:44:37Z")

</div>

Did you find solution to this particular problem? I’m also looking this solution.  
However this problem is not crucial for me, since any games I played on PC, still enable keyboard inputs when gamepad controller is plugged.  
Even though the binding (by name with associated default input button/key) is handled on Project Settings/Input, it will be nice if I can check whether a gamepad controller is plugged, so I can show/hide Gamepad Controller setting Menu on my Options Menu game (to set custom key binding from players).

---

<div class="post-metadata">

**Author:** ![OpticalShadows](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@OpticalShadows](https://forums.unrealengine.com/u/OpticalShadows)\
**Post date:** [January 17, 2015, 4:25am UTC](https://forums.unrealengine.com/t/is-there-a-way-to-detect-a-gamepad/300603/8 "2015-01-17T04:25:35Z")

</div>

I did not find a solution. However I mentioned a kludgy solution below creating an action mapping called “InputFromController” containing every controller button/axis in its inputs. Basically this will fire whenever a button or trigger is pressed. Not the most ideal solution, especially when I comes to the keyboard equivalent.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_db2fa921](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_db2fa921](https://forums.unrealengine.com/u/anonymous_user_db2fa921)\
**Post date:** [January 19, 2015, 2:32am UTC](https://forums.unrealengine.com/t/is-there-a-way-to-detect-a-gamepad/300603/9 "2015-01-19T02:32:45Z")

</div>

Yes, same with me. It’ll be helpful if there is key events for the UI like in the UObject, so we can bind smoothly.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_478829031](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_478829031](https://forums.unrealengine.com/u/anonymous_user_478829031)\
**Post date:** [February 8, 2016, 8:49pm UTC](https://forums.unrealengine.com/t/is-there-a-way-to-detect-a-gamepad/300603/10 "2016-02-08T20:49:11Z")

</div>

This solution worked for me since I could rebuild my engine, but for coders who can’t rebuild their engines you can try the solution below that works based on some dark magic with #defines:

> **[Gamepad Connection Events](https://forums.unrealengine.com/questions/314998/gamepad-connection-events.html)**
>
> What is the recommended way to detect gamepad events? I’m thinking of the following scenarios: Gamepad is connected and gets disconnected Gamepad is disconnected and gets connected Also, battery level would be nice. I’m interested in Windows only.

---

<div class="post-metadata">

**Author:** ![LDbalance](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@LDbalance](https://forums.unrealengine.com/u/LDbalance)\
**Post date:** [January 9, 2017, 6:55pm UTC](https://forums.unrealengine.com/t/is-there-a-way-to-detect-a-gamepad/300603/11 "2017-01-09T18:55:26Z")

</div>

**FWindowsApplication** now has **IsGamepadAttached()** function

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_06f28069](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_06f28069](https://forums.unrealengine.com/u/anonymous_user_06f28069)\
**Post date:** [September 13, 2017, 1:36pm UTC](https://forums.unrealengine.com/t/is-there-a-way-to-detect-a-gamepad/300603/12 "2017-09-13T13:36:13Z")

</div>

Here is possible solution, only tested on windows so far.

File - New C++ Class

Choose parent class - Blueprint Function Library, hit next

Give it a name ( GamepadDetection )

**GamepadDetection.h**

```
    #pragma once
    
    #include "CoreMinimal.h"
    #include "Kismet/BlueprintFunctionLibrary.h"
    #include "GamepadDetection.generated.h"
    
    /**
     * 
     */
    UCLASS()
    class YOURPROJECTNAME_API UGamepadDetection : public UBlueprintFunctionLibrary
    {
    	GENERATED_BODY()
    	
    public:
    	/* Check if gamepad is connected at Runtime. */
    	UFUNCTION(BlueprintCallable, meta = (DisplayName = "GamepadConnected"), Category = "System Information")
    		static bool IsGamePadConnected();
    	
    	
    };

```

**GamepadDetection.cpp**

```
    #include "GamepadDetection.h"
    #include "SlateBasics.h"
    
    bool UGamepadDetection::IsGamePadConnected()
    {
    	auto genericApplication = FSlateApplication::Get().GetPlatformApplication();
    	if (genericApplication.Get() != nullptr && genericApplication->IsGamepadAttached())
    	{
    		return true;
    	}
    	return false;
    }

```

Then finally uncomment / enable slate module dependencies within your projectname.Build.cs and reboot your editor before hitting compile.

**YourProjectName.Build.cs**

```
    // Uncomment if you are using Slate UI
    PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });

```

Now you have a node inside blueprint to check if the gamepad is connected,

---

<div class="post-metadata">

**Author:** ![gurankas](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@gurankas](https://forums.unrealengine.com/u/gurankas)\
**Post date:** [November 18, 2021, 11:21pm UTC](https://forums.unrealengine.com/t/is-there-a-way-to-detect-a-gamepad/300603/13 "2021-11-18T23:21:16Z")

</div>

Well, I haven’t tried RhinoCode’s solution but based on the number of upvotes, it must work.  
But in case you want a pure blueprint solution, this worked for me pretty well

 ![352517-screenshot-2021-11-18-151718.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/7/0/77071349b2333550b96a6bcb7dfbcaab5bbbd33d.png)

The switch input is just a custom event in the HUD I made which executes custom logic to switch the HUD controls based on if the key pressed is on a controller or a keyboard

![352518-screenshot-2021-11-18-151740.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/c/e/1ce82616426db5801c8ddb06327ac7ea8a17fed2.png)

Just make sure your consume input bool in the details panel of the ‘any key’ is false so that all other inputs work fine

---

<div class="post-metadata">

**Author:** ![nonamed46](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@nonamed46](https://forums.unrealengine.com/u/nonamed46)\
**Post date:** [January 20, 2023, 5:00pm UTC](https://forums.unrealengine.com/t/is-there-a-way-to-detect-a-gamepad/300603/14 "2023-01-20T17:00:42Z")

</div>

Since this still shows up as one of the top threads on this topic:

Newer versions of Unreal have the CommonInput Subsystem which takes care of input events and device changes. You can simply bind an event to the input change like this:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/a/1/8a13b208f22065e8a84407025b926985f284e8d7.png)  
and the delegate will give you the device. You can also get the current input type and many other things.

As a subsystem this is accessible from anywhere without having to add any components and it should work in UI as well as any other code classes.

EDIT: it should be noted that this is part of the CommonUI Plugin so it does require a tiny bit of setup as seen on the CommonUI docs, though it’s likely it’ll become one of the standard plugins for UE5 when it has matured a little bit.

---

<div class="post-metadata">

**Author:** ![Mapachex](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mapachex](https://forums.unrealengine.com/u/Mapachex)\
**Post date:** [December 22, 2023, 6:51pm UTC](https://forums.unrealengine.com/t/is-there-a-way-to-detect-a-gamepad/300603/15 "2023-12-22T18:51:19Z")

</div>

![Input](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/1/9/f19b883a94c602a40a46001187768c655810be8f.png)

Hello, I also encountered this problem.  
I’ll tell you how I was able to solve it.

---

<div class="post-metadata">

**Author:** ![Slavamirov](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Slavamirov](https://forums.unrealengine.com/u/Slavamirov)\
**Post date:** [October 10, 2024, 7:11pm UTC](https://forums.unrealengine.com/t/is-there-a-way-to-detect-a-gamepad/300603/16 "2024-10-10T19:11:27Z")

</div>

It seems that this is what you were looking for: [Автоматическое распознавание геймпада в Unreal Engine](https://postby.ru/2024/09/29/avtomaticheskoe-raspoznavanie-gejmpada-v-unreal-engine.html) it can be done in blueprints
