Search Unity

  1. Unity 2017.2 beta is now available for download.
    Dismiss Notice
  2. Unity 2017.1 is now released.
    Dismiss Notice
  3. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  4. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  5. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice

Unity Bug/Issue - Joystick buttons default to false

Discussion in 'Editor & General Support' started by danieldownes, Mar 17, 2015.

  1. danieldownes

    danieldownes

    Joined:
    Apr 20, 2013
    Posts:
    9
    In a Unity game build, the Unity game always defaults joystick buttons to false, and I suspect doesn't attempt to read in the state on load.

    This is a problem if say the controller is upside-down when a game is started.

    Even worse, some buttons on joysticks are bound to toggle switches. In such cases, we have to toggle the switch off then on again before a Unity game can correctly see the switches state.

    Is there a workaround?

    Tested in both Unity 4.6 and Unity 5 on Windows 7/8/XP.
     
  2. danieldownes

    danieldownes

    Joined:
    Apr 20, 2013
    Posts:
    9
    I am considering exploring a work around, by attaching a custom DLL which is configured to read RawInput WinAPI functions. Another option would involve routing the joystick button states via websockets. Again not ideal as software firewalls could get in the way.

    Ideally this really needs looking at within Unity.

    Anyone have any more ideas?

    Thank you.
     
  3. Aurore

    Aurore

    Producer Unity Technologies

    Joined:
    Aug 1, 2012
    Posts:
    3,081
    Have you submitted a bug, I had a similar issue with a 360 pad yesterday.
     
  4. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,195
    Rewired - in the asset store already has native input on Windows already (it supports raw input and direct input) so it should handle just about everything controller wise on Windows. It also gets around the 20 button Unity limit so you can use flight simulation controllers. My main interest is flight simulation so it is the only solution that I can use to support all of the features of flight simulation controllers (30+ buttons for many of them).

    You can get a free trial and see if that works for you.

    https://www.assetstore.unity3d.com/en/#!/content/21676
     
    guavaman likes this.
  5. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    2,620
    Having worked with many (many) joysticks in Raw Input while developing Rewired, I can say this is not a common issue, but it may not be related to a bug in Unity depending on the device or scenario. It could be related to how the device communicates. Most devices send data continually and will always return current data to Raw Input. But some devices do not send any button/axis states until an axis or button is activated/deactivated. These devices show the issue you describe. One example would be some of the flight simulator equipment which may have a 3-state mode knob. On a few of them, the button states that should be returned by that knob are all blank until that knob is turned to a new position for the first time after connecting the device to the system. Other devices, it may only require pressing any button or axis on the device to get it to register the initial state. I have also seen this on toggles on one flight device. As far as I am aware, there is no workaround possible for these devices.

    What devices are you having trouble with?

    I've never seen this issue on the 360 pad. If you're seeing this issue on many devices or common gamepads, etc. then it's probably a bug that could be fixed.

    The case with the pad being upside down would indicate a bug. None of the devices I've tested show this behavior.
     
    Last edited: Mar 18, 2015
  6. danieldownes

    danieldownes

    Joined:
    Apr 20, 2013
    Posts:
    9
    Thank you for your replies people.

    I tried Rewired, and this solved the problem.

    However the Unity in bug remains, and I can now validate this claim with the following project:
    https://bitbucket.org/danieldownes/unitybuttonproblem

    I tested it on a Xbox 360 controller & my own custom controller, with both the same results. Unity's input shows 'false' as expected, and RawInput shows 'true', if for example you hold 'x' on Xbox 360 controller before running the project (from the editor or from the compiled binary).

    If you test with a different controller, then you probably need to add the mapping in Rewired's settings.

    And yes I submitted a bug with reference to this post.
     
  7. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    2,620
    Awesome! I'm glad that solves the problem.

    Then it's likely due to the fact that Unity clears the input buffer on start or when you click out and back into the main game window. This is an even bigger issue on OSX than Windows and causes a lot of problems with triggers and hats.

    If you make your joystick map in the Dual Analog Gamepad Template instead of the Xbox 360 controller directly it will work for the 30+ gamepads Rewired recognizes.