Unity thinks I have controllers connected when I don't. How can I debug this properly?

Simply trying to detect whether a controller is connected using a simple bool.

            if (Input.GetJoystickNames().Length > 0)
            {
                usingController = true;
            }
            else
            {
                usingController = false;
            }

I don’t have any controllers connected. However, to get a false reading on usingController, I have to do it like this:

            if (Input.GetJoystickNames().Length > 2)
            {
                usingController = true;
            }
            else
            {
                usingController = false;
            }

It’s the strangest thing! I’ve been trying to debug this in Awake like this:

            foreach (string joystick in Input.GetJoystickNames())
                print(joystick);

But this only returns the following:


UnityEngine.MonoBehaviour:print(Object)
PlayerController:Awake() (at Assets/Scripts/PlayerController.cs:95)

I’m truly at a loss and would really appreciate the help. Maybe it’s something I’ve set up in my computer?

The controller handling in the old input manager is pretty bad, sometimes it can report devices with an empty name. I guess something on your system is being counted as a gamepad but there’s no real way to tell what.

I suggest you use the new input system instead. It should be more robust and you can inspect the connect devices using the Input Debugger.

You know man, I gave it a shot - there just isn’t that much community support on it, and I got lost in a major way. I figured I should just stick with the OG manager.

There really isn’t any other way to confirm controller counts?

So I figured out a workaround and wanted to come back here and post it. There really isn’t much help for this particular issue! Considering I’m using the standard Unity input manager v1.

Anyway, here’s what I decided to do - open to any criticism! My coding isn’t incredible.

void Start()
{
canDetectController = true;
        usingController = false;
}

    void Update()
    {
        if (Input.GetAxis("AimHorizontal") != 0 || Input.GetAxis("AimVertical") != 0)
        {
            if (canDetectController && !usingController)
            //Input.GetJoystickNames().Length > 0
            {
                CheckController();
            }
        }
}

    public void CheckController()
    {
        usingController = true;
        canDetectController = false;
    }