GameMaker Funky Gamepads Issue

NeoShade

Member
So I've been playing around with setting up some gamepad stuff, and figured I would start by nailing down the whole connected/disconnected thing. This is what I've got to start with:

Code:
// Save the async_load data into temporary variables for easier use.
var event = async_load[? "event_type"];
var padid = string(async_load[? "pad_index"]);

// Show debug messages whenever a gamepad is connected or disconnected.
// Also update the gamepads array when a controller is connected or disconnected.
switch (event)
    {
    case "gamepad discovered":
        show_debug_message("Gamepad " + padid + " has been connected.");
        for (var i=0; i<4; ++i)
            {
            if (gamepads[i] == noone)
                {    gamepads[i] = padid;   break;   }
            }
        break;
    
    case "gamepad lost":
        show_debug_message("Gamepad " + padid + " has been disconnected.");
        for (var i=0; i<4; ++i)
            {
            if (gamepads[i] == padid)
                {    gamepads[i] = noone;   break;   }
            }
        break;
    }
This is obviously running in the async system event, and an array has been set up in the create event of the same object. So far, these are the only objects in the room.
I'm also using the array to draw sprites for each controller, to give be an idea of what's connected and what's disconnected.


My problem is this: Plugging my controllers in (or connecting them with bluetooth) works fine. The array populates exactly as expected, and the sprites and debug messages all appear in the correct order. However, when I unplug the controllers, they tend to register a disconnect event for more than one of them at a time, resulting in some very weird issues.

I'm using 8BITDO NES30 Pro gamepads, which I admit can sometimes be a little finicky to get set up, but I've found them to be a really cool pad when they're working. I'd really like to either rule the controllers out as the source of the problem, or prove that they are the source of the problem, so I was hoping that somebody else with 4 USB controllers might be able to give my code a quick run and see if you're experiencing the same issue?

Otherwise, if anybody can see anything obvious that I've got wrong, can you please let me know?


Thanks very much in advance. ;)
 

hogwater

Member
Is "++i" the problem? I believe you want "i++" instead, to get the value after the operation occurs.

If that's not it, there has long been a bug where a controller can register in both slots 0 and 3 (for example) simultaneously. I've been told that it was fixed recently but haven't confirmed that.

I have and use a couple of 8bitDo pads with my game and they work fine.
 

NeoShade

Member
Oh, I didn't even consider that. That's just the code snippets for block (F4, 5). I use it all the time.

I'll test that change or when I get home tomorrow and see if it works.
 

NeoShade

Member
So, after some more testing, I've decided that changing the ++i to i++ hasn't made any difference at all. I also tried changing it to i+=1 for good measure, and the same problem occurs regardless.I also now tested with some xbox one controllers and tried plugging them in to see if the same issue occured, but they don't seem to be triggering an async event at all, despite them being picked up and appear to be working in windows.
 
Last edited:
The i++ or ++i couldn't make a difference. No matter if i is incremented before or after getting the value, the comparison in the for loop will always come after that.

I don't see why this happens in your code, but maybe this little test tool I made for myself helps you find the issue:
https://www.dropbox.com/s/rpqcj2xnvdr0mqu/GamePad_Async.yyz?dl=0
Just run it and plug in and out your gamepad. Mutliple state changes of multiple gamepads in quick succesion might give you a hint.

Also if you're testing on android you might observe 3 strange things:
- On my android devices slot 0 always is reserved
- tapping the back button on my tablet is registered as new gamepad with the description "sec_touchkey" and after that this slot is blocked
- holding the back button on my tablet is registered as new gamepad as well with the description "Virtual" and here again the slot is blocked after that

haven't tested the back button issue with my phone btw.
 

NeoShade

Member
I thought the same thing, but it never hurts to try.

I tested out my controllers with your project and ran into exactly the same problem. Connecting devices one at a time they all appear in the list correctly, however when using the devices, the first one appears to control all of the subsequent devices inputs (i.e. moving the analog stick on the first controller sets the values for controllers 2, 3 and 4). The controllers added after the first do not appear to be sending any input.
When removing devices, they do not disappear of the list, but simply get the "connected = no" listed against them. Still, removing one ends up setting multiple devices to be disconnected.

I have now also tried testing this on my desktop, plugging each controller into its own USB ports, where previously I had been working on my laptop and thus using a USB hub to connect all the gamepads. I thought that maybe the hub was dicky, but it turns out that the problem still exists on the desktop.

I'm only testing on Windows, so the Android stuff isn't an issue for me (at least not at this stage).

Any insight at all into this would be wonderful. As far as I can tell, this has to be a bug in GMS, but I'd love to be proven wrong!
 
Sorry. I don't get that gamepad behaviour with my test project. Not on windows and not on android anyways. No idea how to help you further then.
 
J

Jace Boechler

Guest
I thought the same thing, but it never hurts to try.

I tested out my controllers with your project and ran into exactly the same problem. Connecting devices one at a time they all appear in the list correctly, however when using the devices, the first one appears to control all of the subsequent devices inputs (i.e. moving the analog stick on the first controller sets the values for controllers 2, 3 and 4). The controllers added after the first do not appear to be sending any input.
When removing devices, they do not disappear of the list, but simply get the "connected = no" listed against them. Still, removing one ends up setting multiple devices to be disconnected.

I have now also tried testing this on my desktop, plugging each controller into its own USB ports, where previously I had been working on my laptop and thus using a USB hub to connect all the gamepads. I thought that maybe the hub was dicky, but it turns out that the problem still exists on the desktop.

I'm only testing on Windows, so the Android stuff isn't an issue for me (at least not at this stage).

Any insight at all into this would be wonderful. As far as I can tell, this has to be a bug in GMS, but I'd love to be proven wrong!
Anybody have any insight into this? I'm having the exact same issue, even down to testing with USB hubs and on different machines. Seems like something funky within GMS2's async events? Might be a bug straight up.
 

RangerX

Member
I have now also tried testing this on my desktop, plugging each controller into its own USB ports, where previously I had been working on my laptop and thus using a USB hub to connect all the gamepads. I thought that maybe the hub was dicky, but it turns out that the problem still exists on the desktop.
On a fresh boot?
Because GMS2 doesn't necessarily go back to normal after the hub is unplugged, especially if there's a bug caused by it.
 

NeoShade

Member
It was a fresh boot, and a fresh project even, since the initial testing using the USB hub was on my laptop, and then I tried it out on my desktop later on and had the same results.
I haven't tested this out for a while though.
 

Mick

Member
I have this issue also, in both GMS1.4 and GMS2. I noticed it only for directinput gamepads (ids >= 4). When disconnecting one gamepad, another one was disconnected. I also had the trouble with one gamepad causing inputs for two controller ids in GMS. Please report it as bugs, I did a couple of months ago, but I don't think I got a confirmation that it was inserted into the bug list.
 

NeoShade

Member
I hope it's alright if I revive this topic after so long, but I figured it was better to reply than to create another topic on the same issue.
After giving up on gamepads for a while, I've recently decided to give them another try, hoping that whatever weird behaviour I was seeing might have been patched out. This doesn't seem to be the case though, as I'm experiencing exactly the same problems as before where the first controller plugged in will disconnect all other controllers when it's unplugged.

I'm just wondering if anyone has any insight on this issue, and if others are still having similar problems?
 
Z

Zackary200

Guest
I hope it's alright if I revive this topic after so long, but I figured it was better to reply than to create another topic on the same issue.
After giving up on gamepads for a while, I've recently decided to give them another try, hoping that whatever weird behaviour I was seeing might have been patched out. This doesn't seem to be the case though, as I'm experiencing exactly the same problems as before where the first controller plugged in will disconnect all other controllers when it's unplugged.

I'm just wondering if anyone has any insight on this issue, and if others are still having similar problems?
@NeoShade Does this count as a similar issue?
When I connect my Bluetooth Gamepad my project lags around 45-58 fps.
But when I use a Wired USB gamepad or without one, It runs 60 fps.
 
E

Excalipur

Guest
I hope it's alright if I revive this topic after so long, but I figured it was better to reply than to create another topic on the same issue.
After giving up on gamepads for a while, I've recently decided to give them another try, hoping that whatever weird behaviour I was seeing might have been patched out. This doesn't seem to be the case though, as I'm experiencing exactly the same problems as before where the first controller plugged in will disconnect all other controllers when it's unplugged.

I'm just wondering if anyone has any insight on this issue, and if others are still having similar problems?
Sorry to revive the thread again, but I wanted to mention I'm having the same issue. Unfortunately I don't have any idea how to fix it. It just seems to be a Game Maker bug... Might look for a more appropriate place to report this as a bug. It specifically happens when trying to play with more than one PS4 controller in particular. Mixing and matching other controllers (even a PS4 "pro" controller) doesn't seem to cause issues.

Edit: Upon further testing. It seems like it could be related to the "classic" style PS4 controller (the one that's colored like a PS1 controller). It seems to have issues when combining with the PS4 "pro" controller that even the normal black PS4 controller wasn't having. It seems like the "classic" style controller is greedy and wants to take both controller slot 4 and slot 5.
 
Last edited by a moderator:

NeoShade

Member
I actually did some further testing with this earlier in the year myself and discovered the same thing. I tested this time using PS4 controllers as well, and found that (of the 4 in my house) they seemed to conflict in pairs. Two of them conflicted with each other but not the other two, and vice versa. Further inspection showed that controllers with the matching model number (part number? device id? I can't remember the exact terminology) would conflict with each other.
 

kburkhart84

Firehammer Games
One thing I see that I don't quite understand...

[quote
case "gamepad discovered":
show_debug_message("Gamepad " + padid + " has been connected.");
for (var i=0; i<4; ++i)
{
if (gamepads == noone)
{ gamepads = padid; break; }
}
break;
[/code]

This is in your original code. You discover a padid. Then, you loop through 4 indices of an array, and if all four of those are noone, you assign that same padid to all four of them. Was that intentional? You will never end up assigning a second gamepad if that's the case.

I've been working with my input system for years. I've always just done it another way that the documentation describes it, which works perfect on Windows, but I'm sure doesn't on Linux, and don't know about Mac. I know one part of the documentation says to discover gamepads using async events. But the other part of the documentation claims that you can simply directly use devices 0 to 3 for XInput, and 4 to 11 for DInput. And that's exactly how it seems to work fine for me on Windows. However, on Linux, device ids seem to start at 20, on Android I think someone told me that device 0 is skipped but then the rest use 1, 2, 3, etc... in order. And I've never had anyone tell me what happens on Mac.

So, since I'm never really worried about anything but Windows, I just do it using devices 0 to 12. You can easily check if one is connected by directly polling it. And I use my input system for action mapping stuff, so I NEVER have to poll gamepads directly, rather I tell the system to search for an input, the player presses a button(or moves an axis), and that gets assigned to the action. Then the game objects just check the action and don't care if the input comes from the keyboard or whatever gamepad. So since I'm literally looping through all 12 gamepads, checking if they are even connected, I'm never worried about detecting if the gamepads are discovered, etc... I DO have functions however that will warn you if a gamepad input is assigned and the device got unplugged.

So basically, the documentation describes two ways to do it. Since I'm directly mapping ids and inputs to actions and detecting and assigning these based on actual inputs, I don't have to worry about async events at all. However, the sacrifice I make is that the input system won't directly work on Linux, atleast for gamepads. I AM eventually going to get a Linux thing set up, even if I do it in a VM, so I can work this out and do it the other way as well, even if the gamepad ids aren't stable between game runs, what can I do? I'm hoping Yoyo eventually unifies the input system eventually so it is exactly the same on ALL OSs. And I'm hoping they eventually support more than 8 DInput devices too. It isn't that I want to play with 8 gamepads at once, rather I have both a GameCube Controller adapter and a WiiMote receiver, and that right there is 8 devices. GMS2 builds crash if I have 8 devices and connect a ninth, it however doesn't crash if the devices are connected before running the game.

******EDIT

Forgot to mention, it doesn't seem like it is this...but where you guys are seeing controllers take multiple IDs, I'm wondering if those controllers are being detected as both XInput and DInput. I have an XBOX360 controller, and I know that for the most part XInput devices also come up as DInput devices, and its preferred to use the XInput version since the DInput drivers for these is wonky(with the triggers being a single axis for example). In my input system I simply handle that by doing the search thing on the XInput side first. It may be picking up the DInput stuff as well, but since the search stops as soon as it detects a button pressed, it detects it on the XInput device, and assigns THAT id to the mapping instead of the DInput one, and it never actually picks up the DInput one because of that. This only applies on Windows though.
 

NeoShade

Member
Theres also a break inside the loop...

GML:
if (gamepads == noone)
{ gamepads = padid; break; }
 
Last edited:

kburkhart84

Firehammer Games
Theres also a break inside the loop...

GML:
if (gamepads == noone)
{ gamepads = padid; break; }
LOL!!!!!!!!!!!! Doesn't matter how good someone thinks they get...we will never be perfect. I somehow completely missed that break statement. I never put the breaks on the same line like that so I think that's why I was completely oblvious that it was there.

My other thoughts are still valid though, whether they apply or not.
 
Top