Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by jonagill · Jan 30, 2013 at 09:52 AM · inputcontrollerjoystickconnected

Check whether specific joystick connected

Does anyone know of a way to check whether a specific joystick number is connected to Unity? I'm trying to detect when a controller is disconnected from my multiplayer game, but Unity does not seem to give any access to the information about which joysticks are currently connected to which input numbers.

I'm familiar with Input.GetJoystickNames(), but the names aren't very useful (every controller I have is named "Controller (Xbox 360 Wireless Receiver for Windows)"), and the array shrinks to only return the names of the currently connected controllers. This means that, even if Unity is currently receiving input from Joystick 1 and Joystick 3 (because Joystick 2 was just disconnected), Input.GetJoystickNames().Length is 2, returning only information about the connected joysticks and no hint of which numbers they correspond to. There doesn't seem to be anything I can query to let my code know which joystick in particular just disconnected.

Does anyone know if it's possible to get this information?

Comment
Add comment · Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bezzy · Apr 08, 2013 at 07:43 PM 0
Share

I have no advice here! Just hitting the same problem. The unity editor seems to know (it tells you if a joystick is RE-CONNECTED, as opposed to just connected!), so it must internalize unique ids for each joystick of the same make?

Would love to know if there's some kinda standard script call on the $$anonymous$$onoBehaviour for this.

avatar image jonagill · Apr 08, 2013 at 07:49 PM 0
Share

I never found an answer. The solution I ended up going with included tracking the maximum value I'd seen for Input.GetJoystickNames().Length, then pausing the game and prompting a reconnect of the controller if that number ever dropped.

avatar image Polinator · Apr 17, 2013 at 04:12 PM 0
Share

I also have this issue, my solution for it was to just track the update if the position of the controllers changed each input, meaning it is plugged in... which isn't a very good solution at all.

avatar image Bezzy · Apr 17, 2013 at 05:06 PM 0
Share

Thanks! I was actually thinking about that. It's not perfect, but it's also not a terrible solution, since if you're getting the RAW axis value (i.e. without deadzone cropping tiny values around the origin), most joysticks are mechanically unstable, and will never return to a perfect 0,0. But if you read the raw axis of an axis which isn't there, I'm going to guess that you do get a perfect zero.

Basically, the chance of a plugged in analogue joystick having a raw axis value of zero on both (or all 10??) axes at once is negligible.

Obviously, it'd be better to have a proper fix with joystick UIDs being sent to monobehaviours when they're connected or disconnected, but it's pretty close.

avatar image jonagill · Apr 17, 2013 at 05:10 PM 0
Share

Perhaps the richest and most efficient solution, then, would be a combination of both — catch that Input.GetJoystickNames().Length has dropped, then check each joystick in turn to find one returning raw 0s.

Show more comments

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

12 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Problems with joystick / controller axes being 1/-1 "way too often" 1 Answer

problems moving game object with the right joystick 1 Answer

Using Input.GetJoystickNames 1 Answer

How do I make the Joystick Analog Stick work like the Mouse Input? 0 Answers

Why does pressing joystick button 0 also trigger joystick button 1? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges