Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Supporting 16 gamepads

Discussion in 'Editor & General Support' started by bfoddy, Jan 9, 2013.

  1. bfoddy

    bfoddy

    Joined:
    Mar 27, 2012
    Posts:
    85
    Hey everyone

    So I'm trying to write a game for 16 USB gamepads using Unity, but obviously the built-in input manager only supports 11 (and the face buttons don't work after the first 4).

    It's ok if the build has to be exclusive to either Windows or Mac, because it's for an installation.

    I know DirectInput can handle 16 concurrent devices. I know XInput can't. I don't know about the mac subsystem.

    I can't spoof keyboard input using Joy2Key, because each pad has 10 digital inputs, which would add up to 160 keys (too many).

    What I've tried so far is to use a C# wrapper for DirectInput in Windows (SlimDX, SharpDX) but this doesn't work because Unity can't load in Windows.System.Forms which is required by DirectInput.

    I'd appreciate any other suggestions!
     
  2. Manolo75

    Manolo75

    Joined:
    Nov 6, 2013
    Posts:
    1

    Did you find any solution?
     
  3. bfoddy

    bfoddy

    Joined:
    Mar 27, 2012
    Posts:
    85
    Yes, I made a DLL to wrap DirectInput to a Unity script. Works pretty well.
     
  4. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    Could you by any chance share your wrapper? There are a ton of issues with Input that could be solved with this (hot plugging for one). I'm trying to figure out how to get SharpDX working in Unity so I can get access to DirectInput from within Unity.

    I was able to get SharpDX working by copying C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\ Profile\Client\System.Windows.Forms.dll into the project/Assets/Plugins when doing testing in the editor. (Its just a reference assembly and doesn't contain any method bodies, but it works anyway to shut up the compiler.) It runs fine. It won't allow you to make a build with that DLL in there, but when you build, just delete the DLL. The build also runs fine.

    However, I am running into a show stopper trying to create the Device (Joystick). I'm not knowledgeable enough about DirectX to write the wrapper myself without wasting a ton of time. So far I've been able to get the DirectInput object and enumerate the devices, get device ids, names, guids, etc., but creating the Device throws an exception.

    EDIT: NM. I got SharpDX working. It was a bug in the SharpDX code. I also stripped all references to System.Windows.Forms and System.Windows.Drawing from SharpDX and rebuilt it.

    Here's a thread about joystick support in Unity that's we've been discussing and working on this.

    Any help you can provide would be greatly appreciated by a whole bunch of Unity users who need decent joystick support!
     
    Last edited: Jun 1, 2014
  5. shkar-noori

    shkar-noori

    Joined:
    Jun 10, 2013
    Posts:
    833
    Could anyone by any chance share any of your wrappers?