Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Question Check if controller is plugged or not on Input System

Discussion in 'Input System' started by GUSRG, Dec 7, 2020.

  1. GUSRG

    GUSRG

    Joined:
    Feb 29, 2020
    Posts:
    6
    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:
    Code (CSharp):
    1. void Update()
    2.     {
    3.  
    4.         if (Gamepad.current.device.enabled)
    5.         {
    6.             print("Plugged");
    7.         }
    8.         else
    9.         {
    10.             print("NOT PLUGGED");
    11.         }
    12.     }
    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.
     

    Attached Files:

    Last edited: Dec 7, 2020
  2. Zaine7673

    Zaine7673

    Joined:
    Feb 15, 2018
    Posts:
    238
    Did you ever find a solution to this?
     
  3. TimHellmann

    TimHellmann

    Joined:
    Mar 6, 2011
    Posts:
    66
    I currently use
    Code (CSharp):
    1. Gamepad.current != null
    to detect whether a gamepad is plugged. Does this work for you?
     
  4. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,848
    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.
     
  5. Cheesemcpuff

    Cheesemcpuff

    Joined:
    Oct 9, 2020
    Posts:
    1