Monogame: Can't use more than 4 wireless gamepads [Desktop GL]

Created on 2 Mar 2017  路  9Comments  路  Source: MonoGame/MonoGame

1.

My game supports up to 8 players at once and I am getting complaints that only 4 wireless controllers are being detected.
I don't have more than 4 wireless controllers to test so I can't confirm what is happening.
I have tried a mix of wireless and different type of wired controllers and could manage to set up 8 players matches.

This is the Steam thread with the complaints in case you want to take a look:
http://steamcommunity.com/app/414370/discussions/0/152391995404760614/

Last player says that even with a mix of Xbox 360 and Xbox One wireless controllers only 4 of them are recognized.
This is pretty big issue for my game since "8 players" is its unique appeal :)

2.

Also I have successfully ported the game to Android and everything works great but on gamepads the dpad is not working. Tried with Xbox 360 and PS4 controllers and they work fine but dpad is not recognized. This is not a big deal, you can still play on left stick, but it would be nice if dpad is working.

Thanks,
Endi

Input

All 9 comments

In the Steam thread at the bottom you can see a tip from a developer about 4+ wireless gamepads:

"One the users of my game, Splody, pointed me to your thread, since my game has no problem with any number of any kind of controllers and thought I could help ;).
I see SDL2.DLL in your game, so it looks like you're using SDL, and, by default, SDL only supports 4 XInput devices at a time, and any non-XInput devices it passes through as DirectInput devices, but loses the extra XInput-captable devices. The solution is to disable XInput in SDL, and simply use DirectInput for everything. In C, that's done with SDL_SetHint(SDL_HINT_XINPUT_ENABLED, "0"), though I can't give you any specifics in C#. If you want to reliably support controllers being added and removed at run-time, you may also want this patch to SDL: https://bugzilla.libsdl.org/show_bug.cgi?id=3299
I might also be totally wrong, but wanted to share what helped for me ;). Feel free to contact me if you want more details."

Maybe this can help you to help me :)

SDL_SetHint(SDL_HINT_XINPUT_ENABLED, "0")

I was gonna write a comment about that, and yes, it probably solves the issue, XInput can only handle up to 4 devices at a time and SDL uses that by default: https://wiki.libsdl.org/SDL_HINT_XINPUT_ENABLED

The question now becomes will Gamepad detection work correctly with that disabled.

Test it out (when it builds, or download the source, your choice): #5537

Build link: http://teamcity.monogame.net/repository/download/MonoGame_PackagingWindows/37789:id/MonoGameSetup.exe?guest=1

New build link: http://teamcity.monogame.net/repository/download/MonoGame_PackagingWindows/38044:id/MonoGameSetup.exe?guest=1

Thanks @cra0zy ! Will test and let you know.

Hi! I don't use MonoGame, but I use SDL2 in my game Splody, which supports any number of any kind of controllers flawlessly (as far as my beta testers have found so far ;). The only other thing I did besides disabling XInput that might be relevant is the first change in the patch mentioned above (https://bugzilla.libsdl.org/show_bug.cgi?id=3299), specifically I needed to do this:

diff -r f0645cd8fd39 -r 7161a0cf5b92 src/joystick/SDL_gamecontroller.c
--- a/src/joystick/SDL_gamecontroller.c Sun Mar 20 15:35:34 2016 -0300
+++ b/src/joystick/SDL_gamecontroller.c Mon Mar 28 14:17:55 2016 -0700
@@ -660,7 +660,7 @@
     if (!mapping) {
         const char *name = SDL_JoystickNameForIndex(device_index);
         if (name) {
-            if (SDL_strstr(name, "Xbox") || SDL_strstr(name, "X-Box")) {
+            if (SDL_strstr(name, "Xbox") || SDL_strstr(name, "X-Box") || SDL_strstr(name, "XBOX")) {
                 mapping = s_pXInputMapping;
             }
         }

Some of my receivers and wired controllers show up as "XBOX Controller for Windows" in DirectInput, so it was missing them. Without that fix the controllers will still work, just show up under the Joystick API, not GamePad.

Only other caveat to be aware of is that the DirectInput drivers for Xbox controllers map the two shoulder buttons to one axis, so it's impossible to detect if both are pressed at the same time.

I do also recommend the patch I submitted in the bug above, but it is unrelated to >4 controller support (it fixes issues where SDL ends up with one controller controlling two device ids if you plug in new controllers at runtime).

Since this is not a MonoGame issue should I close it?

@Jimbly do you think you can create a SDL.dll for me for use with MonoGame with your changes included?

Since this is not a MonoGame issue should I close it?

Leave it open, it's still an issue after all.

Thanks for pointing that out @Jimbly !

My patch to SDL just helps some of these Xbox controllers work with the GameController API - some controllers, Xbox or otherwise, will always not work and fall back to the Joystick API. The main issue here is external to SDL - before initializing SDL you need to make the SDL_SetHint(SDL_HINT_XINPUT_ENABLED, "0") call, as mentioned above - just that change should get more than 4 XInput-capable controllers showing up - I don't know if that change has to be made in MonoGame or in your app though.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bjornenalfa picture bjornenalfa  路  5Comments

tomspilman picture tomspilman  路  4Comments

NET-D3v3l0p3r picture NET-D3v3l0p3r  路  3Comments

Ellesent picture Ellesent  路  5Comments

ryancheung picture ryancheung  路  4Comments