Check if controller is plugged or not on Input System

Hello everyone,

I’m trying to implement a system where I can detect if the gamepad is plugged and not, and be able to change the UI based on that.

My code so far:

void Update()
    {

        if (Gamepad.current.device.enabled)
        {
            print("Plugged");
        }
        else
        {
            print("NOT PLUGGED");
        }
    }

I used to have a code that works fine on old Input system, but on the new Input System, I had to find another solution and now it only works if the controller is plugged, if I unplug the controller I keep getting the following error: (Check the attached image).

Is there any other way to detect if controller is plugged on new Input system.There is no problem if it’s Xbox/Playstation or just generic controller. Just want to detect if it’s plugged or not.

Did you ever find a solution to this?

I currently use

Gamepad.current != null

to detect whether a gamepad is plugged. Does this work for you?

That doesn’t work for me — Gamepad.current == null even though I have a gamepad plugged in and am using it to navigate the UI to where my test code fires.

https://www.reddit.com/r/Unity3D/comments/j2mcoo/new_input_system_how_to_detect_whether_a_gamepad/

This worked for me