Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

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,860
    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