# How do you detect a second gamepad for splitscreen?

**URL:** <https://forums.unrealengine.com/t/how-do-you-detect-a-second-gamepad-for-splitscreen/365975>\
**Category:** Multiplayer & Networking\
**Tags:** unreal-engine, splitscreen, Multiplayer, CPP, Blueprint, question\
**Created:** [August 3, 2016, 9:03am UTC](https://forums.unrealengine.com/t/how-do-you-detect-a-second-gamepad-for-splitscreen/365975 "2016-08-03T09:03:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dunenkoff](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@dunenkoff](https://forums.unrealengine.com/u/dunenkoff)\
**Post date:** [August 3, 2016, 9:03am UTC](https://forums.unrealengine.com/t/how-do-you-detect-a-second-gamepad-for-splitscreen/365975/1 "2016-08-03T09:03:31Z")

</div>

I’m building a local splitscreen multiplayer (which is completely optional), and it’s kinda stupid to just create a second PlayerController without actually checking there’s a second gamepad connected/receiving some input from second gamepad.

Everything Blueprints have to offer is just not enough to solve this (a pretty simple) task, so what do I do? Write my own C++ extension?

---

<div class="post-metadata">

**Author:** ![dunenkoff](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@dunenkoff](https://forums.unrealengine.com/u/dunenkoff)\
**Post date:** [August 3, 2016, 1:07pm UTC](https://forums.unrealengine.com/t/how-do-you-detect-a-second-gamepad-for-splitscreen/365975/2 "2016-08-03T13:07:06Z")

</div>

I’ve found the solution that works for now and I’m posting an explanation here for everyone to use it and build upon.

I’ve subclassed `AGameMode`, since I do all my player management there, and put this in `BeginPlay`:

```
OnControllerConnectionHandle = FCoreDelegates::OnControllerConnectionChange.AddUFunction(this, FName("OnControllerConnectionChange"));

```

with `OnControllerConnectionChange` being declared like this:

```
UFUNCTION(BlueprintImplementableEvent, Category = "Input", Meta = (DisplayName = "On Controller Connection Change"))
void OnControllerConnectionChange(bool Connected, int32 UserID, int32 ControllerID);

```

Now, `OnControllerConnectionChange` fires every time a gamepad or any other controller recognized by Windows is plugged in or pulled out.

Note: `UserID` is pretty much useless right now, as it always returns -1, but `ControllerID` will always return the index of the controller, starting from 0. If you plug the second gamepad, it will have index == 1, and if you pull out the first one after that, the index of the second won’t change, so you can (almost) safely tie `ControllerID` to `PlayerController` index.

Another thing - editor is completely unreliable when testing this. First of all, the event fires for _every controller plugged_ on the game launch, so you can actually launch splitscreen right on or safely tie `ControllerID` to player indices, but only in Standalone mode or packaged builds, it doesn’t in the editor. Second, pulling out/plugging in during PIE fires the event 3 (three) times. Third, and it really grinds my gears - sometimes pulling out/plugging in silently crashes/closes the editor.

Don’t forget to call `Remove` for `OnControllerConnectionHandle` on `EndPlay` so you don’t crash anything:

```
FCoreDelegates::OnControllerConnectionChange.Remove(OnControllerConnectionHandle);

```

I’m still working on exposing input events from second gamepad without creating `PlayerController` specifically for this.

(You should also check out `FCoreDelegates`, it has lots of interesting stuff not exposed to blueprints.)

---

<div class="post-metadata">

**Author:** ![SerzaNT](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@SerzaNT](https://forums.unrealengine.com/u/SerzaNT)\
**Post date:** [February 13, 2019, 2:19pm UTC](https://forums.unrealengine.com/t/how-do-you-detect-a-second-gamepad-for-splitscreen/365975/3 "2019-02-13T14:19:17Z")

</div>

Exactly what I looked for!! Thanks!

---

<div class="post-metadata">

**Author:** ![Roghshire](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Roghshire](https://forums.unrealengine.com/u/Roghshire)\
**Post date:** [November 27, 2023, 3:42pm UTC](https://forums.unrealengine.com/t/how-do-you-detect-a-second-gamepad-for-splitscreen/365975/4 "2023-11-27T15:42:02Z")

</div>

For those finding this from Google; as of 5.1 this approach has been deprecated.

The updated solution:

> [@How to get IPlatformInputDeviceMapper?](https://forums.unrealengine.com/t/how-to-get-iplatforminputdevicemapper/717675/6):
>
> I ran into this issue today. To expand on this a bit more, add this to your header file: UFUNCTION() void OnControllerChanged(EInputDeviceConnectionState connectionState, FPlatformUserId userID, FInputDeviceId inputDeviceID); Connect to the delegate: void SOMEFILE::BeginPlay() { Super::BeginPlay(); IPlatformInputDeviceMapper::Get().GetOnInputDeviceConnectionChange().AddUObject(this, &SOMEFILE::OnControllerChanged); } Function that gets called: void SOMEFILE::OnControllerChanged(EInpu…
