Search Unity

Input.GetJoystickNames() empty on Start()

Discussion in 'Windows' started by ladron, Sep 7, 2017.

  1. ladron

    ladron

    Joined:
    Mar 16, 2012
    Posts:
    47
    I check to see if there are any joysticks connected when my game starts up by using Input.GetJoystickNames(). In the Editor, and in a regular Windows build, Input.GetJoystickNames() is immediately populated.

    in a UWP build running on Windows, though, it is empty when I first check it in a MonoBehavior Start() method. It does later get populated. Is there some reason that this information is not available immediately on startup (assuming that the controller is already connected, of course)?
     
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    What kind of controllers are you using?
     
  3. ladron

    ladron

    Joined:
    Mar 16, 2012
    Posts:
    47
    Xbox 360 controller connected wirelessly. The controller works fine, and is eventually recognized - just not immediately on startup.
     
  4. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    This sounds like a bug. Could we get a bug report?

    I assume it doesn't cause any real issues for you, though? Or does it?
     
  5. ladron

    ladron

    Joined:
    Mar 16, 2012
    Posts:
    47
    It definitely cause me trouble, since I do all of my UI setup on startup (deciding whether to display keyboard or button controls, for example). I was able to work around it by restructuring things so that I don't initialize my game until a few frame updates happen.

    I'll put a bug report in.
     
  6. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    Keep in mind that if you do it like that, your game interface will be buggy if a gamer plugs in a controller mid game. Most games avoid this problem by displaying keyboard controls initially and only switch to controller controls if it detects input from the controller.
     
  7. ladron

    ladron

    Joined:
    Mar 16, 2012
    Posts:
    47
    Definitely - I am being lazy and not adjusting to a controller being added mid-game (the controller will still work, it just isn't represented in the UI).

    Still, I think this is an issue that should be addressed, if possible. I have submitted a bug report.
     
  8. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    Thanks, we'll try to address it.