Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

InControl - input and cross platform controller support for Unity, made easy!

Discussion in 'Assets and Asset Store' started by pbhogan, Jul 18, 2014.

  1. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    274
    Yes, sorry, I was thinking of ResetInternal which is called by Reload. There used to be a Reset that called it too, but that was deprecated a while ago and removed recently.

    InControlManager calls SetupInternal in OnEnable and ResetInternal on OnDisable. So going through a scene change without DontDestroyOnLoad would cause the same effect as calling Reload.
     
  2. Alloc

    Alloc

    Joined:
    Jun 5, 2013
    Posts:
    240
    Added log outputs. SetupInternal is called once at the point we set up InControl, ResetInternal once on quit, both as expected I suppose. The crash doesn't happen synchronously to the ResetInternal execution, if that's a difference.

    So, anything we could do?
     
  3. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    274
    Hmm. Looking at the stack trace again, the crash is happening in Unity's update loop, while Unity itself is querying XInput. I wonder whether what's happening is an unfortunate sequence of events. Is there some way the InControl manager hits OnDisable, and then there is another Unity update tick happening afterwards? Unfortunately, there's no way to tell Unity to stop it's input updates, or to stop it using XInput too.

    Assuming the InControl game object is still in the scene as the application quits, what happens if you move the ResetInternal call from OnDisable to the end of OnApplicationQuit in InControlManager.cs?
     
  4. Alloc

    Alloc

    Joined:
    Jun 5, 2013
    Posts:
    240
    Looks like that's already happening, InControlManager.OnApplicationQuit calls InputManager.OnApplicationQuit which in turn calls ResetInternal.

    Actually I'm not sure how Unity destructs the scene in this situation, we deny the first application quit request in order to cleanly shut down some systems. Might be that this shifts InControl's destruction or something to another frame.
     
  5. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    274
    Maybe try commenting out the ResetInternal in OnDisable then so it actually does the work in OnApplicationQuit rather than before.

    But if you're denying that first request, it's probably would cause InControl to destruct anyway and then there's another update tick happening before or after you shut down your systems and then the actual quit. Is there some way you can wrangle that ResetInternal to happen right at the end during the final application quit?
     
  6. Alloc

    Alloc

    Joined:
    Jun 5, 2013
    Posts:
    240
    Thanks Patrick, your tips seemed to lead to the proper solution :)
    OnApplicationQuit can be called multiple times and it's hard to track down the proper point to do that XInput cleanup. But disabling the call to ResetInternal from OnApplicationQuit, resulting in the only call left being in OnDisable, seems to work, as OnDisable is really only called once when the game is actually clearing up. So, in the current stable build removing line 173 from InControlManager it is ;)
     
  7. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    274
    Great! It might actually be worth removing officially since it's always going to get called in OnDisable anyway. ¯\_(ツ)_/¯

    By the way, since you mentioned you're using 1.8.0, you should make sure you upgrade to 1.8.2 (beta here: http://www.gallantgames.com/downloads) before you push out an update to users as 1.8.0 and 1.8.1 suffer from a bug in detecting some devices correctly.

    I should be submitting 1.8.2 to Unity later today.
     
  8. Alloc

    Alloc

    Joined:
    Jun 5, 2013
    Posts:
    240
    Yeah, might do that. There's still a bit of time before next release :)
    Was just taking 1.8.0 because 1.8.2 was marked as beta on your downloads page.
     
  9. kingbreedicus

    kingbreedicus

    Joined:
    May 16, 2013
    Posts:
    13
    Hi Patrick...
    My gamepad input being ignored, when steam is initalised.
    For example my gamepad input in the Bindings example scene, which shipped with inControl v1.8.2, works fine.
    However after I call SteamClient.Init(), the gamepad can no longer moves the cube, and wont, until I restart Unity.
    Have you had any experience of this?
    Cheers
    I'm using Editor v2019.1.12f1
     
    Last edited: Jun 20, 2020
  10. dadamsj1

    dadamsj1

    Joined:
    Jul 25, 2017
    Posts:
    19
    Is your Steam client overriding control settings? I never had any issues with controllers in the Editor but when I published to Steam I had to change the default controller settings (via Steam Dashboard) to Gamepad.
     
  11. kingbreedicus

    kingbreedicus

    Joined:
    May 16, 2013
    Posts:
    13
    Mad... I turned off the Xbox Configuration Support and that fixed it? Even madder I can turn it back on again and it continues to work.
    Thanks!
     
  12. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    274
    Yes, unfortunately Steam does really weird things with controller support. It injects itself into the system and it seems to change things. Sometimes things break and start working again in the course of a couple of Steam client updates. o_O

    I've been looking at creating a Steam-specific input module that uses the Steamworks controller API, which should (haha) be more reliable, but unfortunately that is also... weird. There doesn't seem to be a good way to just query inputs without going through setting up a custom profile for each game which is kind of a non-starter probably. Anyway, I'll keeping looking at finding a better solution for Steam, but for the moment it seems the best way is to set your game to use the standard Gamepad controller settings.

    Lots of Steam games use InControl, though, so it seems to work decently for the most part.
     
  13. manurocker95

    manurocker95

    Joined:
    Jun 14, 2016
    Posts:
    19
    Hi! I wonder if is there any way to overlay the buttons with the touch manager, because I cannot use any screen overlay UI behind the buttons in the current configuration :/
     
  14. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    274
    You weren't very specific, but I assume you mean you have a canvas with UI elements on it and it's showing up over the InControl touch controls and you want it underneath instead? To do that you need to add another camera for your UI and use the "Screen Space - Camera" render mode on your canvas and target that camera. Then place that camera between the main game camera and InControl's touch camera either using depth, or if you're using URP, using camera stacking.
     
  15. dadamsj1

    dadamsj1

    Joined:
    Jul 25, 2017
    Posts:
    19
    @pbhogan I'm having issues signing the bundle and notarizing for MacOS standalone. I'm having difficulty identifying the issue. I'm using Unity Cloud Build with Fastlane for notarization. Is there a post process build step that I need to take? Any tips?
     
  16. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    274
    I've not done it myself, but a few macOS developers have run into issues along this line, and Apple's continuously changing requirements have introduced new wrinkles along the way. It generally seems to revolve around signing the plugin InControlNative.bundle

    The latest tips I've heard, which may help, are:
    • Plugins/InControlNative.bundle, that’s copied over to the App package, contains three .meta files. These are "unsecure" and need to be manually deleted. I cannot delete them because they are recreated by Unity as I package to submit to the Asset Store, and would be regenerated in your project anyway. So this needs to be handled in an Xcode post-build step.
    • The —deep flag, to codesign seems to skip signing the plugin. This might be because of the meta files, but it fails silently. Manually codesigning the bundle something like this seems to work:
      • codesign -f -s 'CERT ID' --entitlements "GAMENAME.entitlements" ./GAMENAME.app/Contents/Plugins/InControlNative.bundle/Contents/MacOS/InControlNative
    • You probably also need a USB entitlement on your app:
     
  17. benthroop

    benthroop

    Joined:
    Jan 5, 2007
    Posts:
    168
    Hey Patrick there's an outdated page on the InControl site about keyboard/mouse mappings. Is there documentation that's more current on how to map keyboard and/or mouse properly using ActionSets (or something)? Thanks!
     
  18. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    274
    It's pretty much just the same as adding controller bindings to action sets (http://www.gallantgames.com/pages/incontrol-binding-actions-to-controls). You'll see a few snippets in there where keys are bound. Mouse is similar. You could also look at PlayerActions.cs in the bindings example.

    playerActions.Fire.AddDefaultBinding( Key.A );
    playerActions.Fire.AddDefaultBinding( Mouse.LeftButton );
    playerActions.Fire.AddDefaultBinding( InputControlType.Action1 );
     
    benthroop likes this.
  19. mike_ludoko

    mike_ludoko

    Joined:
    Feb 4, 2015
    Posts:
    4
    Thanks for all the support @pbhogan with this plugin! Two questions (and we'll try to follow up on this).

    1. We are updating our app on tvOS and running into issues with previous Siri remote support. For whatever reason, the previous profile (which I think used to mapped to the Unity/native 360 gamepad profile?) no longer recognizes gestures on the Siri remote touchpad, specifically the left/right/up/down swipes. I've been playing around with trying to manually force a different profile on top of it, but I'm not having much luck right now unfortunately. There does seem to be a native Remote profile in the default controller setups, but it doesn't seem to recognize that when the game launches. Any thoughts on this or potential solutions (let me know if you need more detail and I can share it here or via email).

    2. Are there any plans to update once iOS 14/tvOS 14/Big Sur are out with supporting the new GameController framework Apple is pushing (https://www.theverge.com/2020/6/25/...-keyboard-mouse-support-ipados-14-tvos-ios-14)? The biggest area of concern there
     
  20. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    274
    I'm going to go in reverse as it'll be simpler. :)

    2. Yes. InControl already uses the GameController framework on iOS/tvOS as of the last few updates if the native input module is enabled. I'll need to do some modification to support some of the additional features like haptics and controller specific inputs like touchpad or gyro, but for basic controls it works already.

    1. When native input is disabled, InControl uses Unity input and remote behavior is controller through various settings (https://docs.unity3d.com/Manual/tvOS.html). If you have native input enabled, you might disabling it to try this mode and see if it changes anything for you.

    If native input is enabled, the native input plugin is using the GameController framework, but I don't yet support the reportsAbsoluteDpadValues or allowsRotation toggles for the remote (https://developer.apple.com/documentation/gamecontroller/gcmicrogamepad), although that shouldn't affect the swipes, which are supposed to come in as dpad input.

    Have you tried commenting out the remote profiles (Unity/DeviceProfiles/AppleTV/AppleTVRemoteUnityProfile.cs for Unity input, and Native/DeviceProfiles/MFi/AppleMFiMicroGamepadNativeProfile.cs for native input), and running the TestInputManager scene on device to see what kind of inputs are coming in?

    Probably easier to take this to email with your responses.
     
    mike_ludoko likes this.
  21. mike_ludoko

    mike_ludoko

    Joined:
    Feb 4, 2015
    Posts:
    4
    Thanks @pbhogan for the super prompt response! I'll follow up via email on this and play around with your suggestions (and report back on any progress). Thanks!
     
  22. AppBite

    AppBite

    Joined:
    Jul 5, 2012
    Posts:
    74
    Are Nintendo Joy-cons supported on Windows?

    I see a 2017 post of someone getting them both working, I see a Wii Remote photo in the InControl description video on the Asset Store (I understand JoyconLib grew out of Unity-Wiimote), but I'm not seeing Joy-Con or Wii mentioned on the website supported controllers page.

    Thanks,
    Scott
     
  23. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    274
    No, not unless you are doing Switch development with the official Nintendo Switch versions of Unity and the Switch add-on for InControl, in which case Switch controllers work in the Unity Editor for testing. But Switch controllers do not work for end-users on Windows in general at this time. Nintendo doesn't really intend them to work in Windows. There is probably some third-party software out there that makes them emulate as XInput devices which might work.
     
  24. renardmf

    renardmf

    Joined:
    Jun 29, 2012
    Posts:
    47
    Hello,

    I was having issues with the Native Input support for AppleTV in regards to certain controllers that I need to support. Like for example the SteelSeries Nimbus controller only has one Menu button which I was trying to use to support pausing in my game game as well. Right now it does have the functionality where holding it down bring you back to the Apple TV home screen but tapping the button doesn't seem to register any of the default bindings in the TestInputManager. Any help with being able to bind this button correctly would be much appreciated.

    Thanks!
    Andrew
     
  25. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    274
    Hey Andrew,

    Please shoot me an e-mail (patrick at gallantgames dot com) and I'll send you an updated plugin to try. I think there's something we can try.
     
  26. EDarkness

    EDarkness

    Joined:
    Feb 1, 2013
    Posts:
    464
    Hello! I've been using InControl for a long time. However, in Unity 2019.4.4, I'm starting to have a problem where the controller keeps getting detached. It says:

    Code (csharp):
    1. Detached native device with handle 3:
    2. UnityEngine.Debug:Log(Object)
    At first it was only sometimes. Now it happens constantly. Is this an issue with the controller or is there something else that would cause this? I'm using MacOS.
     
  27. Grhyll

    Grhyll

    Joined:
    Oct 15, 2012
    Posts:
    98
    Hi, I realized only recently that Xbox360 and XboxOne gamepads have a very different output for the same vibration settings (especially at low values), and I have been trying to find a way to identify which of the two devices is plugged to the PC, with no success so far.
    I have "Enable Native Input" checked, and in this section "Enable XInput Support".
    The question was raised almost a year ago, and the answer was that XInput doesn't provide any information about that. What's frustrating is that Input.GetJoystickNames() does make a difference in the devices' names, but I can't find any way to link the indexes of this array to the devices of InputManager.Devices. Is there really no way to do this?
     
  28. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    274
    Nope. Many have tried. All have failed. In fact, it has been the historic source of bugs in Unity's own input system due to them trying to do it at one point. The order of devices in other APIs (such as DirectInput, low level HID or USB) is not related to the order they are enumerated by XInput. I have no idea why Microsoft made XInput so opaque, but it is clearly their intention.

    If you're going to pick one, design for Xbox One controllers. Although, honestly, I've even felt differences between Xbox One controllers. Those haptic motors aren't super consistent, I suspect.
     
    Grhyll likes this.
  29. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    274
    You didn't mention what controller you're using, but if it's wireless, they do tend to disconnect after a while, or occasionally glitch out for a while with laggy input. In particular, PS4 controllers seem to have a very tenuous connection on macOS. It's almost like Macs don't have a very powerful bluetooth receiver.

    If it's a wired controller, I have no idea. I test with dozens of controller and they never disconnect while wired. Could be a loose connector or defective cable even.
     
  30. EDarkness

    EDarkness

    Joined:
    Feb 1, 2013
    Posts:
    464
    Oh, I thought I put that in, but it's the PS4 controller. Used to work perfectly, but these days it's disconnecting a lot and I'm just not sure if it's the controller or the program. My first thought is the controller, but I figured I'd check here since I was already posting on the forums.
     
  31. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    3,419
    I'm running into a frustrating problem, which seems to be ultimately caused by Unity's input system, but I'd like to confirm what I can do about this.

    The specific issue I'm having is that held inputs are not preserved when using LoadScene() to change scenes. I'm trying to set up some relatively seamless transitions between scenes. But upon arriving in the new scene, the character immediately comes to a halt, because the held binding associated with movement no longer registers as being held. I can release the input and press it again, and it then it works, but having to release the input between scene loads is clumsy.

    In investigating this, it seems this may simply be a limitation of Unity's Input.GetKey() method, and it's possible InControl can't do anything about this. However, in testing this, I tried switching InControl between using Native Input, just XCode, or neither, and the behavior doesn't seem any different.

    To be specific, I'm using "W" for forward movement. After a scene load, "W" no longer registers as being held, so InControl's PlayerAction values flip to a value of 0. The InControlManager is on a gameobject with DontDestroyOnLoad, so it survives the scene load. I've also tried this with LoadSceneAdditive, and unfortunately the results are the same.

    Is there a way to ensure that held inputs continue to function between scene loads?

    *Edit: This has been confirmed to be a bug with the existing Input Manager, and unlikely ever to be fixed given their new focus on the new Input System Package. I did experiment with that, and found that the behavior works as expected in the Input System Package. Whereas the old
    Input.GetKey(KeyCode.W)
    will return false immediately following a scene load, even if held down the whole time,
    Keyboard.current.wKey.isPressed
    will return true after the scene load, as long as the key was held down. Does InControl support any option to use the Input System Package instead of the Input Manager?
     
    Last edited: Sep 21, 2020
  32. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    274
    I've done some experimenting on my own, and yes it's a bug in the existing Input Manager. The bug is actually extremely weird. If you use an OnGUI button to change scenes, or even a random interval timer, you'll notice input is zeroed for a single frame but then resumes normally. Even the zero frame is a bug, but workable. But the funny thing is if you so much as press an release another random key before a scene switch (unrelated to any triggers or events), it will reset keyboard input completely on the next scene change. It's bizarre.

    However, in all my tests, additive scene loading does work correctly, so I'm not sure what you're running into there with your tests. I suspect that's the route to go anyway where possible.

    No, I currently have no plans to support the new input system as it's extremely non-trivial to switch that in as a whole.

    But possibly I could make a shim just for the new input system keyboard input as long as "Both" is selected in the player settings. I'll look into it. Although it's got its own bugs and it would add processing overhead. I'm planning to add keyboard and mouse support to the native plugin for Windows, Mac (and probably iOS 14+) at some point though.
     
  33. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    3,419
    Thanks. I must have jumped the gun on the statement about Additive scene loading not working, because I can confirm that does work fine, and it's what I ended up doing. It does make things a little more cumbersome (in my case, having both the Old and New scenes loaded at the same time is problematic, so I actually need to transition through an otherwise empty scene first), but as long as I keep using Additive loading, the held input is maintained throughout.
     
  34. XxPleYxX

    XxPleYxX

    Joined:
    Jul 26, 2011
    Posts:
    28
    Hi, I think I have the same problem with native input, in my case Dpad return 2 values (always with a value of 0.7), horizontal (right or left) and vertical (up or down). I need to detect only one of those values at the same time.
     
  35. mike_ludoko

    mike_ludoko

    Joined:
    Feb 4, 2015
    Posts:
    4
    Thanks @pbhogan for the assistance! As it turned out, the previous Siri remote issues were because of outdated native controller profiles still being included accidentally so removing them from the system helped resolve that issue.

    I'm encountering a new issue with tvOS using the latest version of InControl (1.8.3). When I attempt to start the game with a controller (PS4 Dualshock, Xbox One, or MFi controller like the Nimbus+) I get the following crash immediately on startup.

    Code (CSharp):
    1. *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_GCXboxOneSControllerProfile buttonHome]: unrecognized selector sent to instance 0x283810d00'
    2. *** First throw call stack:
    3. (0x19e4d5a04 0x19dde6bcc 0x19e3db14c 0x19e4d9adc 0x19e4dba0c 0x10543eb68 0x10543d38c 0x10543d7f4 0x10543ce84 0x19e0d9614 0x19e0e17f8)
    4. libc++abi.dylib: terminating with uncaught exception of type NSException
    Replace _GCXboxOneSControllerProfile with DualShock, MFi, etc. as the crash occurs with all three devices. We had previously been using 1.8.2 and didn't experience these crashes and controllers on iOS and MacOS. Thanks!
     
  36. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    274
    What version of tvOS are you using?

    Technically, that call should only happen on tvOS 14, but I had to compile the native plugin with the Xcode beta, so maybe there's some mismatch in there and I need to rebuild with the latest version. It did work on tvOS 14 when I tested it though.

    Shoot me an email and maybe I can send you a fresh rebuild of the plugin to test.
     
  37. mike_ludoko

    mike_ludoko

    Joined:
    Feb 4, 2015
    Posts:
    4
    Thanks Patrick, I emailed the support email to follow up! The AppleTV I was testing on was using tvOS 13.4.8, but testing it out on another AppleTV with tvOS 14 didn't cause any of the crash issues (so it might be the latest version trying to call a tvOS 14 method?).
     
  38. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    274
    Hey Mike—thanks for the email. I've been looking into it and I think I found the issue. It seems the platform version check I was doing gets "optimized" by the Objective-C compiler if you don't specify your build might get run on older deployment targets in Xcode. Pretty unintuitive behavior, but ¯\_(ツ)_/¯

    I'll send you a new build to try out.
     
  39. eareis_eareis

    eareis_eareis

    Joined:
    Jan 24, 2017
    Posts:
    1
    Hi!

    First congratulations for the plugin, it worked well for us on mobile and PC.
    But now we are developing for the XBox One console and a problem has arisen.
    I didn't find the script in the package:
    Assets/InControl/Source/XboxOne/XboxOneInputDeviceManager.cs

    I didn't actually find the XboxOne folder on this path.

    Could you help me, please?

    Thanks
     
  40. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    274
    I've replied to your email, but for others who may have a question about this:

    Due to NDA constraints we cannot distribute most console add-ons through the Asset Store, but there are add-ons available for Xbox One (XDK), Game Core (Xbox One and Xbox Series X), Nintendo Switch and Stadia. For details on how to get access to these, please contact us by email.
     
unityunity