• 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 YeeLuke · Dec 04, 2016 at 12:35 PM · inputcontrollerinputmanagergamepadcontrollers

Mapping multiple controllers

Hello,

My current input manager is set up to read each button on up to four gamepads, as they are mapped 'joystick 3 button 0' as "A_P3", for example.

My goal is to allow up to four players to join in a local game by pressing the 'A' button on their gamepad. The issue I can't seem to work around is that if the players use a USB hub device to extend gameplay up to four players, Unity won't read the joystick as say 'joystick 4'. Also, it doesn't seem that if I try using a global set of buttons for all gamepads would work, as I don't want it to conflict with the players already in game.

If you have any solution to my issue, any feedback would be much appreciated. Thank you.

tl;dr I am trying to map gamepads regardless if a USB hub is used, or use one input manager setting available up to four controllers

Comment
Add comment · Show 1
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 YeeLuke · Dec 04, 2016 at 06:14 PM 0
Share

is there perhaps a way to store a controller that's plugged in as a variable?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by darbotron · Dec 04, 2016 at 07:17 PM


T$$anonymous$$s is fixable using the standard UnityEngine.Input.xxx functions (my own unity based framework does t$$anonymous$$s), but it requires a significant amount of code & is non-trivial to explain in an answer here.

If you want to be able to just get a "controller" as a variable, you need to wrap the Input library in a code interface that behaves the way you want.

Buttons are easy, since you can access the buttons from a specific joystick with either the string name or a value from the keycode enum ( https://docs.unity3d.com/ScriptReference/KeyCode.html).

Axes are a bit more difficult as you have to define them by hand in the InputManager pane in the editor. You need to make axes for each possible controller number and name them in a procedural manner so you can easily use the same interface as for the buttons.

e.g. you might call the up/down axis of the left stick on pad 1 "Pad1_LS_Vertical", on pad 2 "Pad2_LS_Vertical" ...etc. you could then use string.Format( "Pad{0}_LS_Vertical", padNumber ) to generate the string to use with Input.GetAxis( ... ).

If you're after a quick solution might be to get an asset store package w$$anonymous$$ch does t$$anonymous$$s for you. I hear InControl (www.assetstore.unity3d.com/en/#!/content/14695) is a decent one - lots of s$$anonymous$$pped unity games use it...

Comment
Add comment · Share
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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

63 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Can you set a default position for a joystick axis? 0 Answers

Remote user game pads stuck on X axis, locally fine. 1 Answer

How do I standardize my game's input to different types of controllers? 1 Answer

Controller shoulder buttons firing both at the same time. 0 Answers

Dualshock3 Mac L2/R2 Trigger Analog Values? 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