Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How do you detect a second gamepad for splitscreen?

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?

Product Version: UE 4.12
more ▼

asked Aug 03 '16 at 09:03 AM in Blueprint Scripting

avatar image

48 5 10 13

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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:


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.)

more ▼

answered Aug 03 '16 at 01:07 PM

avatar image

48 5 10 13

avatar image SerzaNT Feb 13 '19 at 02:19 PM

Exactly what I looked for!! Thanks!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question