Search Unity

Game Controller that works with Unity.

Discussion in 'Editor & General Support' started by Calixto, Sep 16, 2012.

  1. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    I see. So you would just interface with it like in the WinMM example using System.Runtime.InteropServices and DLLImport. If you still have your DirectInput test project, you could try doing that. I'll try it myself a little later on (hopefully today).
     
  2. aitchest-of-dees

    aitchest-of-dees

    Joined:
    Dec 28, 2013
    Posts:
    73
    I'm not sure if this is helpful or not, but I found a test project for a library called AC.Input that works pretty well with 4 controllers (a couple of mine seem unreliable but that may be hardware). I modified it to support 6 controllers easily enough. I don't get any scary errors or crashes yet. The usual Xbox 360 weirdness applies, but I do find replugging twice or switching USB ports twice can trigger the controller to show back up. Could this be adapted for Unity? I'm not sure what's involved in making a Unity-friendly DLL for Windows.

    EDIT: Hmm I attempted an attachment, let me try again.
     

    Attached Files:

  3. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    Nice! I looked through and it also uses winmm.dll, but at least they have the flags issue figured out. So that might be a good starting point. It looks like it has some kind of Linux support too. I still haven't had time to do anything myself (work getting in the way). Thanks for doing the research.

    As for the attachment, it saves as attachment.php for some reason but if you rename it to .7z it works.

    Thanks!
     
  4. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    I'm currently testing with SharpDX which is basically a managed wrapper for DirectX. So far I've just barely scratched the surface (getting a list of devices), but DirectInput seems to work better than winmm when it comes to recognizing hot-plugged devices. I'm not seeing the weird issue with the X360 controller where you have to plug it in twice for it to reappear.
     
  5. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    So my tests with SharpDX turned out very promising. I see no issues with hot plugging at all with any of the controllers I tested including an Xbox 360 wireless and a legacy Saitek P880. I had no issues with getting all the axes and buttons on the Xbox controllers either. My method for detecting the plug/unplug is quite improper (it would be much better to subscribe to the events as described here or the source of that here), but it works to prove the concept.

    The Joystick ID remains consistent no matter what port I put the joystick in it seems even with 3 controllers attached and switching around at will.

    So it seems DirectInput would be the solution to this on Windows. Now the issue becomes figuring it out if its possible to interface with it from within Unity. (And hopefully Unity doesn't take exclusive control of the inputs when its in focus.)

    I've attached the project. If you want to try it, you'll have to download SharpDX and include the SharpDX and SharpDX.DirectInput. You might have to install the DirectX SDK June 2010 as well.

    Incidentally, the Unity devs should take a look at this old tutorial from 2008. Apparently it's not so hard to do hot plugging on windows. :mad:

    Edit: File removed...
     
    Last edited: Sep 26, 2014
    shkar-noori likes this.
  6. aitchest-of-dees

    aitchest-of-dees

    Joined:
    Dec 28, 2013
    Posts:
    73
    Nice! I'll check it out, thanks!

    Edit: Well this looks like bad news
    http://forum.unity3d.com/threads/165467-Supporting-16-gamepads
     
    Last edited: May 31, 2014
  7. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    Actually I've already gotten past this. Just copy C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\Profile\Client\System.Windows.Forms.dll into your 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.

    I've been able to get the joystick information (id, name, guid, etc.) from within Unity using SharpDX. (Put the .net20 dlls in Assets/Plugins: SharpDX.dll and SharpDX.DirectInput.dll). Hot plugging seems to work flawlessly as well in the editor and in a build.

    I've hit one major snag though. At the point that I need to create the Device object (Joystick), I get an exception:

    Looking at the SharpDX source, its failing on SetDataFormat on the creation of the Device. I'm not sure why this would happen when run from within Unity and not in a form app. It had no trouble creating the DirectInput object and I'm able to get plenty of information from it... Not sure what's happening.

    EDIT: I read your link again and it seems bfoddy wrote a wrapper for DirectInput and he said it works. That means this is the right direction even if SharpDX turns out to be a bust. I'm sure with enough hacking the System.Windows.Forms dependency could be removed from the source. I imagine that would be a lot easier than writing a whole new wrapper. I asked in his thread if he'd be willing to share his wrapper. From everything I've seen so far from my own testing, DirectInput is easily able to support hot plugging.

    EDIT 2: Actually it was super easy to strip out the System.Windows.Forms and System.Windows.Drawing dependencies from SharpDX. Since I'm only interested in the DirectInput (and maybe Xinput) parts, it was just a matter of deleting files and commenting out a few methods.
     
    Last edited: Jun 1, 2014
  8. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    It works!

    It was a problem with SharpDX. I had to workaround some strange issue with Mono and it works now.

    I haven't done much beyond show the button presses, axes, joy ids, etc. and do hot plugging, but I'm happy to say it just plain works. Tested Xbox 360 wired, Xbox 360 wireless, and Saitek P880 legacy wired. Joysticks appear and disappear, IDs stay fixed regardless of the USB port used, etc. Since I stripped the dependencies on System.Windows.Forms it also builds with no problems. Why Unity ever switched from DirectInput to RawInput I'll never know.

    I've attached a sample project if you want to test it or start modifying it for your use. I also included a rebuilt version of SharpDX.XInput which isn't used in the project, but you might as well have it in case you want to do something with it.

    Here's a good read about joystick issues on PCs. Looks like XInput is required too if you need to be able to detect both trigger buttons on the X360 pad. We need a better way to detect connect/disconnect too. According to that article, detecting by polling the devices is very slow.

    Edit: File removed... will post a link to new file location soon.
     
    Last edited: Jun 10, 2014
  9. aitchest-of-dees

    aitchest-of-dees

    Joined:
    Dec 28, 2013
    Posts:
    73
    Wow, I had actually planned on trying this today but checked the thread and saw you already did it! It looks like it's working great! I dropped it into my game with no errors and it's (sorta) working :) Question: is the -5000,5000 range of stick directions I'm seeing defined somewhere or is it a "magic number" that Windows will always report for analog controls?
     
  10. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    I've updated the project to include device attach and detach. Hot-plugging in the editor and in a build works absolutely flawlessly (well almost, see note at end). So now it will only rebuild the list of joysticks when a device is connected or disconnected. I've tested with 6 different controllers connected at once and everything seems pretty solid, including wireless.

    This is how Unity should be out of the box! And to my great surprise, this works perfectly in Unity free as well! I guess Unity free can access native code as long as the native DLLs aren't actually included in the project.

    As for the 5000, 5000 question, it's in the code. It was part of some example on MS's website and I just left it in there. DXInput.JoyInput.GetJoysticks() has the axis range change. I haven't started messing with input mapping, dead zones, sensitivity, and all the other stuff that's required to get this useable yet, but its a start.

    Note: However, I did notice in certain situations it is possible for the joystick ID to change. For example, after plugging in only 5 of 6 controllers, then disconnecting them, then restarting the game, then put a new controller which has never been plugged in by itself, it will receive ID 0. The next time you plug in one of your previous controller that used to be 0, it will push the other controller to 1. Put the old one that was 1 in and it will push it to 2. It seems when it pushes it out of its JoyID its instance GUID changes as well. The product GUID doesn't change, so you can still easily compensate for this as long as multiple of the same joystick with the same product GUID aren't connected. If they are, I suppose it would be possible for two players to have their controls swapped. Not great, but not earth shattering either.

    Edit: File removed... will post a link to new file location soon.
     
    Last edited: Jun 14, 2014
  11. aitchest-of-dees

    aitchest-of-dees

    Joined:
    Dec 28, 2013
    Posts:
    73
    Update received! I'm super happy with this as is, so thanks a ton for getting this working! As it stands, I think I can do my own button mapping, dead zone, etc, but it would be great if we could develop this to the point of it being a robust solution for the community. Do you want to start a new thread for the development of the library? I'm happy to help out!

    Edit: One more thing! The "bad" controllers that were giving me trouble before (one of the Xbox 360 controllers and my USB Sega Genesis adapter) are now working perfectly!
     
  12. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    Great! I'm glad to hear it!

    I think it would be a great thing if we could develop it more fully to support the 3 neglected platforms. (I hope some knowledgeable Mac or Linux developer stumbles across this.) I imagine it could be put on the asset store as a free asset at some point (because Unity SHOULD have this out-of-box... nobody should have to pay extra for functional joysticks). I worry Mac/Linux support may end up requiring Pro because of the native code issue, but for Windows it looks like free will work.

    This needs to have XInput integrated too. Currently, the SharpDX.XInput is included, but its not doing anything. It needs to detect the XInput controllers and such so the triggers work properly on X360 controllers. Probably something special will have to happen for Windows 8 store apps too and web players (fallback on Unity?)

    Probably opening a new thread is a good idea. Also, I don't know if doing something on github would be helpful for developing it. I've never done that before so it will be a learning experience. I'll open a new thread and post the link back here.
     
    Last edited: Jun 14, 2014
  13. tamberlain

    tamberlain

    Joined:
    Jun 16, 2013
    Posts:
    20
    Nice work, guys! If any of these solutions supported Mac/Linux then I'd be in heaven. But it's a huge step in the right direction and will make Windows-only game producers happy. I look forward to the day when there's a true cross platform solution. Right now if it's not cross platform then I'm still back at square one.

    If there was a cross platform solution I'd pay money for it! There's no shame in selling on the Asset store a solution that you spent your own blood sweat and tears figuring out and packaging up nicely for us to use, especially when it's something so immensely important and desperately needed by anyone thinking of simply using a joystick in a Unity game.

    This is really something the Unity team should be fixing, not something that should be left to the customers. And it's something they should have fixed 3+ years ago when we first started complaining about the joystick issues. This is basic core input stuff here, not an obscure rarely used feature!
     
  14. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    Hi Tamberlain,

    I've spent the last week getting the Mac version working. Right now I've got Windows (now both DirectInput and XInput support), Windows 8 Store, and OSX (10.5+) working for both free and pro. (OSX free requires moving a dylib into the project folder and adding a bundle manually to your builds, but I'm happy to say it works.) Hot plugging works *near perfectly as do connect and disconnect events. Even the Xbox 360 controller works perfectly as long as you have the right driver on OSX. (I can't remember which one I used, probably this one.) I guess Android and Linux would be the remaining ones to address (iOS supports gamepads too, but I have no iOS device to test with). I've still got to make an input wrapper for it so you can access controls seamlessly on all the platforms, come up with a way to define joystick profiles, come up with a way to customize the controls (assignment, deadzone, sensitivity), possibly a way to calibrate axes, etc. I'm not sure how complete I'd want to make it, but I probably won't go to the point of having a user control configuration GUI, but I'd like to have that capacity to let you do that yourself in the API at least.

    Because of how much time I've been spending on this, I've been thinking I may put it on the asset store for $5 or $10, not sure yet.

    *Near = there is no unique device id guaranteed to be available for a HID device in OSX it seems, so if multiple identical controllers that don't provide their serial numbers are connected, some unwanted joystick position swapping during hot-swap is a possibility. FYI, 360 controllers do have a serial, but not all do.

    Been 5 years for me. :p Seriously, this has been utterly broken since day 1. Unity's very nearly 10 years old now.
     
    Last edited: Jun 10, 2014
  15. tamberlain

    tamberlain

    Joined:
    Jun 16, 2013
    Posts:
    20
    The more it "just works" straight out of the box as an asset store package, the more popular it will be. :p $5 - $10 sounds very reasonable to me. I'd even pay more, as without something like this my game is dead in the water (or I'll have to ditch Unity and try out a whole new system such as Unreal, but I've already put a year of work into our game using the Unity engine).

    There's no other cross platform solution like this for Unity and certainly none that are in a form that is easy to just install and use without lots of fiddling around. So if it's simple enough to install and use then I think this will become a best seller!
     
  16. tamberlain

    tamberlain

    Joined:
    Jun 16, 2013
    Posts:
    20
    One thing I forgot to mention, which I'm sure you've considered, is what the licensing terms are for the libraries you are pulling in. Be sure that anything you are using in your package is okay to resell and is okay for others to use in their commercial for-profit games.
     
  17. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    True, but Making it "just work" for any use case will involve a huge amount of work I think because of what would be expected. Essentially, its reinventing Unity's input system, which is rather rotten in the first place. I think to achieve that would involve a system that handles not only functioning hot-plugging and connect events. It would need a slew of pre-defined controller layouts for all available controllers and a way to add more, a GUI on the backend for the developer to define custom layouts per-device per-player, a series of GUIs on the front end to handle user-defined layouts, a record system to save user customizations per-device, user-configurable calibration per axis and per device, a player-based framework to make managing player to controller associations easier and to avoid control assignment conflicts, a GUI for the developer to define their "Actions" (like Unity's poorly labeled "axis" in the InputManager) where they can assign multiple buttons/keys/axes to each action so they can simply poll for actions (Fire) instead of polling individual devices (or another way of abstracting all possible controller types and layouts into simple calls). It should probably include keyboard, mouse, and touch control as well so they don't have to switch to using Unity's system for those, etc. Ideally it should include support for exotic controllers such as wheels, guitars, dance pads, etc.

    At that point, $5 or $10 is not going to cut it as we're talking probably months of time investment including documentation. Actually I'm not sure even at $5 or $10 this would sell well anyway, considering how only a handful of people seem even aware of the problems with Unity's input system even though its been out there for a decade and I've been talking about it for years.

    There are other issues that come up as well. Webplayer will only work with Unity's built-in system as native APIs don't work. If you want to make the input system transparently compatible with Unity's, the system has to ultimately work like Unity's, which is inadequate in a lot of ways. For example, the whole idea that you define actions like "Horizontal" or "Fire" for a single player assigned to a single absolute joystick id, and a single absolute axis is just plain bad. But to keep it compatible with that system for the sake of Webplayer means it inherits all the problems. Additionally, if not all other platforms like WP8, iOS, Android, Xbox, PS3, etc. were accounted for, any game that was targeting those platforms too would have to implement multiple different input systems, so it would probably have to account for all targets.

    Yes, I have. What I've used is free to use and sell in any way. Here's the license:

     
    Last edited: Jun 11, 2014
  18. aitchest-of-dees

    aitchest-of-dees

    Joined:
    Dec 28, 2013
    Posts:
    73
    The large number of concerns, and potentially low number of sales is why I think a collaborative open source approach would be good here. But you've done a lot of great work so I wish you the best if you decide to press ahead on your own.

    I personally wouldn't worry if it only works on pc/mac/linux. That alone would be a huge win.
     
  19. pentacle703

    pentacle703

    Joined:
    Mar 17, 2014
    Posts:
    6
    @guavaman Hi!
    I've been working around with unity to get better input and tried SharpDX too (with a lot of other solutions),
    And SharpDX was exactly what I needed but I've got the same issue than you : "SharpDXException: HRESULT: [0x80070057], Module: [General], ApiCode: [E_INVALIDARG/Invalid Arguments], Message: The parameter is incorrect."
    Then you said that you make it work,
    So I would like to know what you've done to make it work, It would help me a lot (Else I'd have to configure 5 controller with their 32 buttons and 6 axis)

    thanks for all the info given so far
     
  20. Arcanafex

    Arcanafex

    Joined:
    Nov 6, 2013
    Posts:
    2
    I'm getting the "SharpDXException: HRESULT: [0x80070057], Module: [General], ApiCode: [E_INVALIDARG/Invalid Arguments], Message: The parameter is incorrect." error as well.

    Everything else builds and runs fine, and I'm able to identify the correct name and Guid of my device from the DeviceInstance, but then when I try to use 'new Joystick(...)', I get this error every time.

    Any advice on resolving this would be a HUGE help!
     
  21. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    I am new to Unity so this is a very interesting topic. Thanks for posting. My main interest is Windows PC based controllers. I am guessing we are only discussing USB based devices? In some of your posts you mentioned an attached project but I only see reference to link in a future message. Has this been posted yet? Are you using Visual Studio 2012 or 2013 to build it?

    Based on what little I have read it seems that Xinput is the new standard and DirectInput is going away. Based on this URL.

    http://msdn.microsoft.com/en-us/library/windows/desktop/ee417014(v=vs.85).aspx

    I did notice in Microsoft IE blog included a discussion of using the Xbox 360 a new "future" gamepad API in W3C.

    http://blogs.msdn.com/b/ie/archive/2014/06/16/announcing-internet-explorer-developer-channel.aspx

    This one in particular could help least when thinking about assigning numeric values to buttons etc. This is under section 8, Remapping section.

    http://www.w3.org/TR/gamepad/

    Other than Xbox360 controllers what other controllers are you currently working with?
     
  22. pentacle703

    pentacle703

    Joined:
    Mar 17, 2014
    Posts:
    6
    I Use special joystick which have the same input than a classical controller, but up to 32 buttons.
    The problem is that Xinput seems to be limited to 4 devices, tell me if I'm wrong.

    I'm currently trying to use JoyGetPos
    (http://msdn.microsoft.com/en-us/library/windows/desktop/dd757107(v=vs.85).aspx)
    which work fine in C & C++. but under Unity, using P-Invoke, I can't get the Joystick with JoyGetPosEx (only with JoyGetPos), when in C it work fine. So I'm trying to make a wrapper to make it work better with unity.
     
    Last edited: Jun 23, 2014
  23. shkar-noori

    shkar-noori

    Joined:
    Jun 10, 2013
    Posts:
    833
    where the hell is the Unity team?
     
  24. bibbinator

    bibbinator

    Joined:
    Nov 20, 2009
    Posts:
    507
  25. shkar-noori

    shkar-noori

    Joined:
    Jun 10, 2013
    Posts:
    833
  26. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    Oi! I just spent all this month working on making a cross-platform system to handle everything and NOW you guys decide to fix it after all the complaining I've been doing over the last 5 years? (Maybe complaining to the CEO the other day actually worked.) This just isn't my lucky life... I released my Sprite system last year and 2 weeks later you guys announced your 2D system... Deja vu! Such a freaking waste of time and resources.

    Why the heck isn't the new forum system sending my notification emails. I didn't know about any of these messages here until I logged on today and saw the alerts.

    It's a problem with the old version of Mono that Unity's stuck on. SharpDX calls sizeof(T) and Mono chokes on that. You have to change those references in the SizeOf generated functions in SharpDX it to System.Runtime.InteropServices.Marshal.SizeOf. It will require your recompile SharpDX.
     
    Last edited: Jun 24, 2014
  27. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    I decided to take the links down because it really was nothing more that a test project with a lot of problems. I've worked out a ton of issues since then.

    XInput is not a replacement for DirectInput or RawInput. It's a very limited system that only supports Xbox 360 devices, and only 4 at that. "Legacy" devices are not supported. So, no, XInput is not the future of PC controllers as stated in that article.

    I'm working with any HID compatible USB controller. I'm currently testing with 6 different pads on Windows, Windows Store, and OSX. I was also planning on adding Linux support and have fallbacks for all other platforms and webplayer. I'm very far along in the project (nearly done), but I'm not sure if there's any point in finishing it now that Unity's FINALLY decided to notice.
     
  28. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    Thanks for the clarification on DirectInput and Xinput. I would be interested in seeing what you have even if it just a test project. The Unity input thread says that input changes will be for Unity 5.x only which makes perfect sense. I think your project would be useful for the Unity 4.x world.
     
  29. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    Well I'll be trying to get it completed and release it to the asset store for a small price. Support on Unity 4.x, will be for a small minority of users once 5.x is in full swing. Anyway, I spent all this time on it already I might as well finish it.
     
  30. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    Sounds good. Will there be a source code option?
     
  31. Arcanafex

    Arcanafex

    Joined:
    Nov 6, 2013
    Posts:
    2
    Thanks, guavaman! I've been pretty much stuck with the rather unhelpful SharpDX error message and your message here was literally the only message I've found that offered any hope of a solution. Due to time constraints I was leary of diving into the SharpDX source as you have. But, now that I know where to look... :)

    Incidentally, I've gotten an almost identical error thrown by SlimDX and even MS's last C# version of DX9. I wonder if it's all this same SizeOf(T) bug in Mono...

    Maybe Unity might like to find a fix for that...
     
  32. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    Probably not. But I'm planning to expose enough that you should be able to do pretty much whatever you want with it.

    I don't think Unity is going to change the Mono version. It's been at this same version for years. The official Mono was patched a long, long time ago to fix this issue.
     
  33. pentacle703

    pentacle703

    Joined:
    Mar 17, 2014
    Posts:
    6
    After some research, I've been able to find some solutions.
    I don't know if every solution work on every system, and if you need the pro version or not, but at least it work correctly on windows 8.1

    the first solution is SFML.net (http://www.sfml-dev.org/download/sfml.net/) which is the binding of the c++ library for .net.
    you just need to put the good dll in your plugin or asset folder (for the input, its sfmlnet-window-2.dll, and the dll from the "extlibs" folder) and then you can use easily input by doing
    Code (CSharp):
    1. using SFML.Window;
    2. void update()
    3. {
    4. Joystick.Update();
    5. for(int i = 0 ; i < Joystick.Count ; i++)
    6. {
    7. if(Joystick.IsConnected(i))
    8. {
    9.   Debug.Log(Joystick.GetAxisPosition(Joystick.Axis.X));
    10. }
    11. }
    12. }
    it's easy, but sometimes, some device are not well recognized, and you don't have acces to all the axis and buttons.
    the other problem is that you cannot have more than 8 joystick.


    So I've created a plugin which use the JoyGetPos (like SFML do) to get data from the joystick. I cannot use P-Invoke because the library has a different behavior between the call in C and C#.
    The problem that is encountered with JoyGetPos is that it handle two type of joystick : the simple one(only 3 axis and 4 buttons) and the extended one(6 axis and 32 buttons). Sometimes the Joystick is recognized as a simple one, but you can handle it like an extended one, and it will work. So in this plugin, you can choose to handle every joystick like a simple or an extended joystick. (by calling the Ex function or not)

    put the dll in your plugin folder (or recompile it if needed) and add the InputManager.cs to one of youre object.

    You can choose to call UpdateAll() or UpdateAllEx() to handle every joystick like a simple or a Extended one. (do not do the both) and then, to get the AxisZ of the Joystick n°5, call respectively getPosZpos(5) or getPosExZpos(5).

    the function getJoystickType(int i) tell you if the joystick i is a simple joystick(1), an extended joystick(2) or not a joystick(0). (but you can force a simple one to be handled like a extended one)
    Last point : the axis are between 0 and 255;

    The code is not perfect, but I was only needed to get the input from the joystick. Be carefull, the dll is in 32 bits, so build in unity for 32 system (or rebuild the dll)

    so have fun ^^

    ps : documentation to JoyGetPos :
    http://msdn.microsoft.com/en-us/library/windows/desktop/dd757107(v=vs.85).aspx
    http://msdn.microsoft.com/en-us/library/windows/desktop/dd757108(v=vs.85).aspx
     

    Attached Files:

  34. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    Do you have an expected release date?
     
  35. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    I tried this also but ran into some serious problems with it. Can't remember exactly what right now. Also didn't like the 8 joystick limit. I think there were some other button limits too.

    As for GetJoyPos, etc. we ran into many problems with hot-plugging using that system which is why I ended up using DirectInput instead.

    It's not set in stone but I'm hoping to have it done within a week. I'm working on the mapping editor currently. On the first release, it will fully support the 7 controllers I have for testing and all others will fall back to a generic layout (which you can define or have the user define). You will be able to create multiple predefined layouts for each recognized device or define generic layouts using all possible elements (20 axes, 128 buttons, 5 hats, but actual supported number may depend on platform). I'll probably need others here to create profiles for other joysticks I don't have so I can include those. Maybe I'll give out some free copies / betas for those wanting to help create hardware maps.

    BTW, the 7 controllers I have are:
    Microsoft Xbox 360 wired
    Microsoft Xbox 360 wireless
    Saitek P880
    Saitek P990
    Logitech Dual Action
    Nyko AirFlo EX
    Game Elements Recoil
     
    Last edited: Jun 26, 2014
  36. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    Really looking forward to it.

    Have you seen Xarcade's tankstick?

    http://www.xgaming.com/store/arcade...oduct/x-arcade-tankstick-includes-usb-cables/
     
  37. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
  38. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    No, I do not have one but I have been looking at it for a while. Most of my information I have found is from reading their website and reading the reviews(and questions and answers) on amazon.com's website (since they also sell it via amazon).

    Generally everything is mapped to keyboard and the trackball is mapped to a mouse. So no drivers required to work on windows/mac/Linux. It is programmable so you can remap the up to 3 different modes.

    Xarcade also sells the individual parts (buttons/trackballs/joysticks) so you can make your own game controller.

    http://www.xgaming.com/store/category/arcade-parts-and-accessories

    This one gets into the specifics that you are interested in with regards to what mapping is used.

    http://www.xgaming.com/store/arcade.../two-player-build-your-own-arcade-bundle-pcb/

    With regards to your question about keyboard mapping you can find details in their byo (build your own) manual which is a link off the previously mentioned URL. Here is the current direct URL for the PDF.

    . http://www.xgaming.com/service/ServiceFiles/X-Arcade BYO Manual USA.pdf

    This blog post (found via Xarcade's twitter feed) on how someone integrated tankstick with USB on rasberry pie (with linux distro)is really interesting. He intercepts the trankstick USB messages and converts into two virtual gamepads while keeping the keyboard messages separate. He gives a good overview on this page.

    http://blog.petrockblock.com/2014/06/01/xarcade2jstick/

    NOTE: There is source code available but it is GPL3 license which does make it usable in our context.

    Since you are working at USB level you might this information interesting for detecting the xarcade controllers. Someone has a Xarcade dual stick (which is the same as tankstick without a trackball) and was having some issues. They did post some of their USB messages to try to determine the cause of the issue.

    http://blog.petrockblock.com/forums/topic/retropie-not-recognizing-xarcade-dual-tank-stick/


    With regards to USB game controllers there is also this site that has some other things like joysticks, spinners, and arcade light guns. Based on the website it does look like you do have some control over ID that is assigned to it.

    .http://www.ultimarc.com/index.php

    Suzo-Happ services the commercial/industrial/arcade industry for just about everything. It is good site to look at too.

    http://na.suzohapp.com/
     
    Last edited: Jun 29, 2014
  39. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    guavaman,

    Any updates on when you will be releasing your tool?
     
  40. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    Hi longroadhwy,

    Yes, I will be uploading it to the asset store within a few days. It will take them probably about a week before they will get it online after that. Sorry about the long delay. I ran into a number of issues with Linux and Windows Store that had to be addressed, but they're all sorted out now. (Windows 8 store builds pass WACK certification on 8.0 and 8.1.) If you'd like to try it sooner, I'll be happy to send you a beta for testing.
     
  41. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
  42. shkar-noori

    shkar-noori

    Joined:
    Jun 10, 2013
    Posts:
    833
    I have made something like this, an InputManager, the main class is a wrapped xInput, and implemented a silent tool to map all the joysticks to the main xInput wrapper. (That's how I do it because i dont want to use all the wrappers out there in the same project and re-write alot of code.) , it support Keyboard & Mouse, Dualshock3, Dualshock4, XBox 360, XBox One, Normal PC Joysticks, vibration support, runtime binding, Save & Load, and Input simulation, Axis as Button, events callback, 5 Different players at the same time, Hot-plug support, deadzone & smoothness & sensitivity, I have n't used UnityEngine.Input for years, what are the present bugs of Unity's default Input class?
     
    Last edited: Aug 8, 2014
  43. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    Interesting. You are wrapping XInput, yet you support normal PC joysticks? By what means are PC joysticks supported, because XInput does not support anything but controllers designed for XInput (X360, Logitech 310, F710, and generally newer controllers). Legacy controllers are not even detected. And XInput's max joystick limit is 4.

    Scroll up in this thread and you'll see my list of some of the Unity input bugs. Let me try to enumerate some as they relate to joysticks:

    • No hot-plugging support in game builds at all except partial but still broken support on OSX.
    • Impossible to map a controller to a player without polling for a button press and asking the user to identify the joystick because GetJoystickNames is completely unrealiable. (Makes creating in-game mapping screens a problem.) This also makes it impossible to make pre-defined map layouts for players.
    • Existing joystick IDs can change when another controller is pulled on some platforms.
    • Some axes are mapped totally differently on Windows, OSX, and Linux for many controllers.
    • D-Pads (hats) in OSX are completely broken on many controllers and essentially unusable. (VERY odd hat to axis mapping going on for these.)
    • OSX and Linux report different zero state values for axes depending on whether the axis has been pressed in this session or not. Zero may be 0 at first, then -1 after the initial press.
    • Keyboards show up in the Joystick names list in Linux.
    • Linux axes randomly calibrate zero as 0, -0.5, or 0.5 and persist for the session. Sometimes this is a single axis on a controller, sometimes multiple. Quitting and restarting may reset these axes, but others may calibrate wrongly instead. Essentially, without manual calibration by the user, joystick axes are totally unreliable on Linux.
    Other things that are not really bugs but more like missing features:

    • No frame-rate independent input.
    • No connect/disconnect events.
    • No support for GetButtonDown in FixedUpdate or OnGUI.
     
    Last edited: Aug 8, 2014
  44. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    That is great news. I know you made the right decision by fixing those type of issues before the first release. I will be happy to beta test. I am using 4.5.2 currently
     
  45. shkar-noori

    shkar-noori

    Joined:
    Jun 10, 2013
    Posts:
    833
    thank you for the list, its a shame those stuff were/are there for nearly 5 years..
    I'm Wrapping XInput to recieve the joysticks information, but in another tool, I wrap the joystick around xInput even if not generally supported, I receive the original joystick data and send that data to xInput using a driver, and for the 5 joysticks, I meant:
    Player 1 = Keyboard & Mouse
    Player (2, 3, 4, 5) = Joysticks.

    and I'm checking for the inputs in one main component, and everything that needs a data, will get the data, so if 2 scripts call for GetAxis it doesn't happen twice in one Update, it only happens one in the main component and the data will only be received if required. I would really like to beta test your tool to see how things are working on your side.

    the other tool that I wrap the joysticks with is an exe. application, runs with the game silently.
     
  46. yeagz7

    yeagz7

    Joined:
    Sep 4, 2012
    Posts:
    2
    Sorry to hijack this thread but I have the same "The parameter is incorrect" error with trying to create a new Joystick. I am now trying to edit the source code updating all of the calls to sizeof but am having issues even getting the source code to compile. I downloaded the latest version from GitHub and when I open it up I immediately have a bunch of errors for missing methods. I know I am probably doing something ridiculously simple wrong but I would appreciate any help.
     
  47. yeagz7

    yeagz7

    Joined:
    Sep 4, 2012
    Posts:
    2
    Ok so I can now build the dlls but am still getting the "parameter is incorrect" error. I have replaced sizeof with Marshal.SizeOf everywhere in the SharpDX and SharpDX.DirectInput projects. Does it need to be changed in more places or am is there something else I'm missing?
     
  48. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
  49. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    Hi, sorry longroad. So many steps apart from programming to get a product out... If you PM me your email, I'll send you a copy.

    Got the website up here:
    Rewired Website
    Documentation site
    Rewired API Reference

    I'm going to be adding things here and there to the site and docs, so its not all finalized yet. I'm going to be working on videos today.
     
  50. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    @Shkarface Noori

    Also, can you send me your email too so I can send you a copy? Also, please let me know what version of Unity you're currently on.