Jump to content
  • Advertisement
NDraskovic

C# Detect which controller pressed a certain button

Recommended Posts

Hey guys,

I'm working on a local multiplayer game that uses multiple controllers (joysticks) on the same computer/console. I downloaded the InControl asset that should help with the input, but I can't find a way to detect which of the connected controllers was used to perform some action (i.e. on which controller was the button pressed). The application detects the actions properly, but it doesn't make any difference if joystick 1 or 2 "sent" the action.

The only way I could accomplish this is to define specific axis (or more precisely, 20 axes for each controller) in Unity's input manager, but that seems too crude, and very unpractical to use within code.

Is there another way to know which joystick performed the given action?

Thanks

Share this post


Link to post
Share on other sites
Advertisement

Since you're using InControl to do it, you'll need to check with InControl's documentation or possibly their source.

If it is the same InControl that is the top hit on Google, it looks like their calls pass an InputDevice as a parameter if you're using their API rather than Unity's input calls. That device would map to the specific controller.

Share this post


Link to post
Share on other sites
3 minutes ago, frob said:

Since you're using InControl to do it, you'll need to check with InControl's documentation or possibly their source.

If it is the same InControl that is the top hit on Google, it looks like their calls pass an InputDevice as a parameter if you're using their API rather than Unity's input calls. That device would map to the specific controller.

I tried with InControl, but couldn't find a way, so I'm asking for any suggestion, not only InControl, but built in Unity or some third party plug in.

Share this post


Link to post
Share on other sites

If you're using Unity's built in input handler for mapped axis values, you'll need to create them all and change the settings to only detect specific joysticks in the "Joy Num" field rather than the default for all joysticks.  

Be aware that the OS can assign a controller to any joystick number.  For example, an xbox controller may be joystick 1, but unplugging it and reattaching it might assign the same controller to joystick 3.  

In one Unity game I worked with they had something like 300 or 400 entries on the input mapping.  All of them were handled by an input mapping class in the code.

Share this post


Link to post
Share on other sites
13 hours ago, frob said:

If you're using Unity's built in input handler for mapped axis values, you'll need to create them all and change the settings to only detect specific joysticks in the "Joy Num" field rather than the default for all joysticks.  

Be aware that the OS can assign a controller to any joystick number.  For example, an xbox controller may be joystick 1, but unplugging it and reattaching it might assign the same controller to joystick 3.  

In one Unity game I worked with they had something like 300 or 400 entries on the input mapping.  All of them were handled by an input mapping class in the code.

Yeah that is the approach I'm using at the moment, I was just wandering if there is a "smarter" way. Thanks anyway.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!