Search Unity

  1. Get the latest news, tutorials and offers directly to your inbox with our newsletters. Sign up now.
    Dismiss Notice

Rewired - Advanced Input for Unity

Discussion in 'Assets and Asset Store' started by guavaman, Sep 25, 2014.

  1. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,637
    That is one way to go about it.

    No.

    https://guavaman.com/projects/rewired/docs/FAQ.html#touch-gyro-accelerometer
     
  2. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,321
    Ok, new found issue on Xiaomi Note android phones. I wrote a bunch of code that executes differently if you are using a real joystick or gamepad vs if you are just playing with your phone.
    For ages, my way to check if you are using a hardware joystick was simply to check if ReInput.controllers.joystickCount was bigger than zero.

    For some reason, Xiaomi phones, so far tested on Note 9 and 10, will return a joystickCount bigger than zero even if you have nothing connected to it and then messing up all my source code logic. Any ideas how to solve this issue?
     
  3. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,637
    It's not possible to fix because Unity is exposing a joystick to Rewired.

    https://guavaman.com/projects/rewired/docs/Overview.html#tested-platforms

    Rewired on Android is 100% dependent on UnityEngine.Input. If Unity exposes a Joystick, Rewired sees it and exposes it as well. Android must be exposing it to Unity.

    The only option is to come up with a different way to decide whether the user wants to use a joystick or not. One idea would be to wait until they press something on the joystick before switching everything to joystick mode.

    https://guavaman.com/projects/rewir...ml/M_Rewired_Controller_GetLastTimeActive.htm
     
    Last edited: Apr 29, 2021
  4. Darkon_Who

    Darkon_Who

    Joined:
    Jul 22, 2017
    Posts:
    13
    Hey @guavaman I hope you are doing well. Could you please perhaps tell me if its possible and give me some tips on how to achieve the following in Rewired:

    To do my 3rd person character aiming I am using the right half of my screen on mobile with a touchpad control from Rewired, everything is working great besides one small factor - Touch acceleration. I was wondering if its possible currently to implement this in anyway via the control? Basically I am trying to replicate the aiming of popular titles such as Call of duty Mobile and Fortnite, where if you move your finger slowly, based on the speed the sensitivity will be normal, but if you do a flick, the sensitivity increases for that duration.

    Is there something I am missing to achieve this in Rewired? Or would I have to build something custom around this, which listens for the updates from the control and adjusts the sensitivity?

    Thank you in advance for the help, Rewired has been fantastic!
     
  5. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,637
    The only options for touch controls are those shown in the inspector. There are no acceleration options.

    Things people want to do with touch controls vary so much and with such specific functionality, it's impossible to design a system that allows everyone to do everything they want to do. It's better to design your own system if you're looking for something specialized.
     
  6. impbox

    impbox

    Joined:
    Mar 31, 2017
    Posts:
    8
    Hi there, we're having an issue with getting PS4 Dualshock 4 controllers connected via Steam with Steam Playstation Controller Support enabled:

    OS: Windows 10

    Primary Input Source: RawInput
    Use XInput enabled (same behaviour with Use XInput disabled)

    Using Rewired 1.1.39.1

    The controller is detected as:

    Code (csharp):
    1. XInput Gamepad 1 hw: XInput Gamepad hwGUID: d74a350e-fe8b-4e9e-bbcd-efff16d34115
    Code (csharp):
    1.  
    2. <RI> Failed to get input data: The handle is invalid. lrZcGkIEsbKeSxaNzagJBfdagkwJ:qyveISqLLIVRYjzitRkHBjsDOFf(IntPtr, IntPtr, Int32, IntPtr, IntPtr) PwkjmFhqpfGmeHAjKPaPrYHwvpNd:FwULuBhtVenHihEDuWIAJJEsVUm(IntPtr, UInt32, IntPtr, IntPtr) BEdHmkOugVfzDIFtmPbkVbHCzRs:FwULuBhtVenHihEDuWIAJJEsVUm(IntPtr, UInt32, IntPtr, IntPtr) irPZOcUJvFyfGBjnamgTaKYGfeO:xUhastdHtgSYrIrHmMAKzUAQdWH(IntPtr, UInt32, IntPtr, IntPtr)
    3.  
    4. [C:\buildslave\unity\build\PlatformDependent/Win/Input/RawInput.cpp line 1259]
    5. (Filename: C:\buildslave\unity\build\PlatformDependent/Win/Input/RawInput.cpp Line: 1259)
    6.  
    (We are enabling RewiredInputManager after Steam is Initialised as recommended.)

    It appears to occur sometimes when using either the left or right joysticks.

    I haven't been able to find any info about this error elsewhere.

    Any ideas on how we can stop this error from occurring?

    Thanks very much.
     
    Last edited: May 5, 2021
  7. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,637
    The error you are reporting is not from Rewired. Those log entries are from Unity. Every single log entry made by Rewired is prefaced with [Rewired]. I don't see any issues here. Your controller should work without issue through XInput. Steam exposes an XInput device and Rewired reads it. There's nothing more to it.

    And your errors are extremely unusual looking and not what I'm used to seeing from Unity. I can only guess that you are using Unity's new input system which is not compatible with Rewired.

    https://guavaman.com/projects/rewired/docs/KnownIssues.html#not-compatible-unity-new-input-system

    Because I am seeing obfuscated function calls reported in your error coming from Unity, I can only guess that there is some kind of inexplicable interaction happening between Unity's new input system and Rewired's Raw Input code. I have no information about how Unity works internally and cannot explain this.
     
    Last edited: May 5, 2021
  8. impbox

    impbox

    Joined:
    Mar 31, 2017
    Posts:
    8
    Sorry I misinterpreted <RI> as being "RewiredInput" but I guess it's "RawInput", makes sense.

    We're not using the New Input system, but thanks for the info, I'll look further into the Unity side rather than Rewired side.

    Thanks for the quick response!
     
  9. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,637
    It wasn't clear to me -- is the controller not producing input through Rewired? Have you checked the values coming in for the controller using Debug Information? Those Unity RI errors (or very similar) have been around since I started using Unity (2008) and have never caused a problem. There's no way to get rid of them.

    Almost without exception, a Steam-configured controller not working is due to lack of or misconfiguration of Steam settings:
    https://guavaman.com/projects/rewired/docs/Troubleshooting.html#steam-controller
     
  10. RetroVertigo2019

    RetroVertigo2019

    Joined:
    Dec 29, 2020
    Posts:
    6
    Hey everyone
    I got this plugin recently, and I have most of my controls setup and working well, but I am trying to implement a button combo move, Left Left Action, or Right Right Action. the game is a beat em up so left and right facing are the only two sprites used.
    I have my horizontal movement done via an Action: Move Horizontal, Type: Axis, and Positive Move Right and Negative Move Left
    I have double tab registering with Right double tap via: player.GetButtonDoublePressDown("Move Horizontal") But this doesnt work with left double tap.
    Am I doing something wrong here? Should a Left Left button press register with that code as well? I appreciate any help or insight you all might have on this.

    Thanks
     
  11. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,637

    https://guavaman.com/projects/rewired/docs/HowTos.html#button-press-types

    Negative Buttons:

    Each of the methods above also has a corresponding Negative Button method which is named the same except with NegativeButton in place of Button. These serve to allow you to use axes as buttons and will trigger when the negative side of the axis is activated while the standard Button version will trigger only when the positive side of the axis is activated. However, it is usually easier to just map each pole of the axis to a seperate Action (split axis) so that each Action can just be queried with GetButton.

    If you want all GetButton calls to return True when either the positive or negative side of the axis is activated, enable the option "Activate Action Buttons on Negative Values" in the Rewired Editor.
     
  12. RetroVertigo2019

    RetroVertigo2019

    Joined:
    Dec 29, 2020
    Posts:
    6
    Thanks Guavaman
    If only I had kept reading on the manual, it would have saved some time. Still, I really appreciate the support. I enabled Negative Values in the editor and it is working as intended now. Thanks again!
     
  13. ledshok

    ledshok

    Joined:
    Oct 28, 2012
    Posts:
    20
    I'm trying out the demo version of Rewired but am getting the following warning after installing it.

    "The version of Rewired installed (1.1.39.1.U2021) was not designed for Unity 2020. Please install Rewired for Unity 2020".

    I'm on 2020.3.6f1 and downloaded the demo zip called Rewired_U2020_Trial.zip (which contains Rewired1.1.39.1.U2021_Trial.unitypackage). Is there a 2020 version I should be using instead?

    Thanks!
     
    Last edited: May 7, 2021
  14. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,637
    Then that's a bug with the Trial. There is no 2021 version available then. The warning will very likely cause no problems at all.
     
  15. ledshok

    ledshok

    Joined:
    Oct 28, 2012
    Posts:
    20
    Okay, cool. Doesn't appear to be having any negative impacts but just wanted to check I was using the correct version.

    So far Rewired's been really easy to setup (the documentation was very helpful), so I suspect you'll be getting a purchase out of me next payday! :)
     
  16. jason_yak

    jason_yak

    Joined:
    Aug 25, 2016
    Posts:
    381
    Hi there, I was just wondering about the Dual Sense controller support. I had a good look at your dual sense extension docs, but couldn’t spot any methods to do with the adaptive triggers. I could be wrong on this cause I’ve not played with these new controllers much, but I was under the impression they had some new way for devs to mess with the tension or behaviour of the triggers, an example I read about was feeling the tension of say a bow string as you pull back an arrow. Do you know if this is something already covered in your api? Or is that something that’s currently not possible to support? Or have I got the wrong idea about what ‘adaptive triggers’ actually means haha.

    Also just putting in a feature request for dual sense support on iOS. I checked the supported controller docs which currently said No support, but wondered if this might be possible now with iOS 14.5 adding support for dual sense. I was reading iOS manages to now support the full feature set of the dual sense supposedly, thanks.
     
  17. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,637
    Rewired does not support the adaptive trigger API. I don't even know whether that is even doable using the reverse-engineered direct HID report communication required to support any special features on this controller on non-PS5 platforms. I don't even know if the information required to make it work has been discovered and published. From what I've seen of the API, it's more similar to the Direct Input force feedback API than vibration.

    Vibration / adaptive triggers cannot be supported without a full native library to replace dependence on UnityEngine.Input. Rewired on iOS is 100% dependent on UnityEngine.Input:

    https://guavaman.com/projects/rewired/docs/Overview.html#tested-platforms

    The Supported Controller list is not always up to date because of changes made in new versions of the OS. If iOS added support for it, Rewired already supports it because it uses UnityEngine.Input and matches any controller exposed. Unity underneath uses GCController and therefore sees any controller that Apple exposes. If Apple is exposing it, it will work already
     
    Last edited: May 10, 2021 at 6:27 PM
  18. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,637
    Rewired 1.1.39.2 is available on the Unity Asset Store.

    See Updating Rewired before updating.

    1.1.39.2:

    Changes:
    - Missing mouse axis entries in the Unity Input Manager entries no longer cause Rewired to fail initialization, but instead log an error.

    API Changes:
    - Added public setter to InputManager_Base.dataFiles property.

    Bug Fixes:
    - Windows Standalone, Native Mouse Handling: Virtual desktop mouse delta value is no longer ~1/2 size of local mouse delta.
    - Fixd missing stick buttons mappings for Steam Controller (emulated) in Gamepad Template.
     
  19. jason_yak

    jason_yak

    Joined:
    Aug 25, 2016
    Posts:
    381
    No worries, thanks for the detailed explanation! cheers.
     
  20. indie6

    indie6

    Joined:
    Dec 15, 2012
    Posts:
    57
    Hi,

    I am working on an iOS game with controller support. Currently using the generic joystick template. I have mapped 4 buttons to different Actions

    Top Row 1: Slide (Square PS4)
    Top Row 2: Switch Weapon (Triangle PS4)
    Bottom Row 1: Jump (Cross PS4)
    Bottom Row 2: Fire (Circle PS4)

    When I change the mapping on iPad from System Settings -> General -> Customisations
    How do I know in game that the buttons have been swapped? For example assigning (Square to Circle and Circle to Square). Can I figure that out using the Action ID?

    And is there a way to figure out if current controller is Xbox or PS4?
     
    Last edited: May 13, 2021 at 3:40 PM
  21. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,637
    Remapping your controls through the OS is a very new feature of iOS 14. Rewired offers no specific support for this feature.

    Rewired is 100% dependent on UnityEngine.Input on the iOS platform as stated in the documentation:
    https://guavaman.com/projects/rewired/docs/Overview.html#tested-platforms

    Rewired's controller recognition system which is based on the concept of haiving pre-defined, static metadata that can positively identify controller elements by index is fundamentally incompatible with systems that then rebind those elements to different indices underneath it. It only makes sense. How can a controller definition that had always identified Button 0 as X be expected to work with a new system that comes along and suddenly changes the identity of X to what it thinks is Y. This new Apple rebinding control system is and will always be a problem. No controller-definition based system will be able to work well with what amounts to having the hardware change dynamically underneath it.

    Any system like Apple's new controller rebinding at the OS/driver level now requires runtime queries to determine the identity of a controller element every time it is needed. If you look at their API, you're supposed to make a function call to get the glyph or the localized name. This is because of their new OS-level remapping system. So now the OS is required to be in charge of element names and glyphs instead of Rewired. You can suddenly no longer rely on the elements being fixed and cannot use any of the same methods that have worked for this and every other platform for 7 years to get a controller element name, glyph, or even element type. This is a problem. And because Rewired is based on UnityEngine.Input, this information is not available. In order for Rewired to work with this, a totally new native input library and input source would have to be developed for Rewired to replace dependency on UnityEngine.Input.

    I don't know what would happen if you remapped the controls using Apple's control remapper. It depends on whether or not Unity enables support for it. Not all applications support it I believe. If they do, it would change the identity of buttons and axes underneath Rewired. If you remapped X to A, when you press A, Rewired would think you pressed X. If you're reporting some button on the screen to the user, the button they see would be X, not A, and would be wrong.

    See the documentation for determining controller type on iOS:
    https://guavaman.com/projects/rewired/docs/Troubleshooting.html#ios-xbox-ps4-controllers
     
    Last edited: May 12, 2021 at 5:49 PM
  22. jason_yak

    jason_yak

    Joined:
    Aug 25, 2016
    Posts:
    381
    We’re also very interested in the control remapping functionality, but can understand how much of a deviation this is from how your system works. It’s a tough one. All I can think is that we’d be happy to pay for a Rewired Pro, or major version upgrade like AV Pro have done recently where their license expires now after two years. All of this support and feature additions are going to keep mounting as platforms continue to evolve, we love working Rewired, we hope it continues to thrive, but I can totally understand how this amount of support and feature additions like this would make it so hard to add a huge feature like this. So if there was a new model for the plug-in where we could help to subsidise the development costs for these kinds of features, we’d be more than happy to pay for this service whether it was via a major version upgrade, pro plug-in or otherwise. Just a thought, but totally understand it sounds like a very difficult feature to add.
     
    Last edited: May 13, 2021 at 5:32 AM
    flashframe likes this.
  23. greg-harding

    greg-harding

    Joined:
    Apr 11, 2013
    Posts:
    450
    hey @guavaman, just posting to agree with what @jason_yak said. We're also interested in platform-specific features like the remapping on iOS/macOS (and other stuff) and would be happy to support development through an alternative payment model - subscription, pro support payments, etc. We would really appreciate you considering it.
     
    flashframe likes this.
  24. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    459
    +1 We would too!
     
  25. idibil

    idibil

    Joined:
    Oct 10, 2015
    Posts:
    11
    Hello,

    I am trying to create some tutorial msg using rewired. The code works on the controller and keyboard, but it is very sensible and a player can have the controller keys up when it is connected but not used and not touched (he is playing with mouse + Keyboard). Is there any way to better recognize when the player is using the controller or keyboard? and recognize each controller separately (Xbox controller, Playstation controller)

    Code (CSharp):
    1.     public int RewiredPlayerId = 0; // The Rewired player id of this character
    2.     private Rewired.Player Rewiredplayer; // The Rewired Player
    3.     private bool skipDisabledMaps = true;
    4.     private string tempKey = "";
    5.     private string completeText = "";
    6.  
    7.     void Awake() // Rewired
    8.     {
    9.         Rewiredplayer = ReInput.players.GetPlayer(RewiredPlayerId);
    10.         skipDisabledMaps = true;
    11.     }
    12.  
    13.  
    14.     void OnEnable()
    15.     {
    16.         Controller controller = Rewiredplayer.controllers.GetLastActiveController();
    17.         if (controller != null)
    18.         {
    19.             switch (controller.type)
    20.             {
    21.                 case ControllerType.Joystick:
    22.                     tempKey = Rewiredplayer.controllers.maps.GetFirstElementMapWithAction(ControllerType.Joystick, "Toggle Flashlight", skipDisabledMaps).elementIdentifierName;
    23.                     break;
    24.                 default:
    25.                     tempKey = Rewiredplayer.controllers.maps.GetFirstElementMapWithAction("Toggle Flashlight", skipDisabledMaps).elementIdentifierName;
    26.                     break;
    27.             }
    28.         }
    29.         completeText = "<color=#D94524>" + ScriptToggleFlashlight + "</color>\n\n" +
    30.             "[<color=#8BCB16>" + tempKey.ToString() + " </color>]";
    31.     }
     
  26. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,637
    "The code works on the controller and keyboard, but it is very sensible and a player can have the controller keys up when it is connected but not used and not touched (he is playing with mouse + Keyboard). Is there any way to better recognize when the player is using the controller or keyboard?"

    I don't understand what you're asking or what the problem is.

    GetLastActiveController tells you the last controller the user interacted with.

    As for identifying joysticks:
    https://guavaman.com/projects/rewired/docs/HowTos.html#identifying-recognized-controllers
     
  27. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,637
    @jason_yak, @flashframe, @greg-harding

    I understand everyone wants everything to just work with every platform and every new feature they come up with. The question is HOW to fit this square peg in the round hole that it was not designed for and not blow up the whole design of the system. Whether this is hard or not isn't the issue, it's whether it can be done at all. Rewired abstracts and standardizes input across platforms. That's one of it's primary purposes. When a platform breaks the paradigm so completely that it can't be fit in, your only option left is to tack on a totally separate platform-specific API that works completely differently from every other platform and basically just acts as a wrapper for the native API and requires you branch your code for that platform. That's not elegant and not user friendly. Much research and thought has to be put into whether this is doable and/or how to do it in a way that isn't just a big giant cludge if that's even possible. My instinct is that it won't be possible and Apple platforms will require that you jump through special hoops to get the names and glyphs of elements and branch all your code when dealing with any of this information, including help UIs and remapping UIs (including Control Mapper). Control Mapper and any other UI will have to have Apple-specific code added to somehow be made to monitor the current string name of the element and redraw that element in the UI when it changes. (Control Mapper never redraws the UI continuously and only does so when some interaction with it changes something. There is also the issue that Apple treats element names differently from Rewired's standard of displaying a positive, negative, and full-axis name for each element. That information is not available from the Apple API as far as I can tell. Same for glyphs.

    The most basic fundamental building block of a controller recognition system is that the controller's identity and layout can be known beforehand. Now that is no longer the case.
     
    Last edited: May 13, 2021 at 7:30 PM
    flashframe likes this.
  28. idibil

    idibil

    Joined:
    Oct 10, 2015
    Posts:
    11
    Thank you for your reply. Yes, I know how it works, but the player is playing when keyboard mouse and he is getting xbox keys message when he is not using the controller (although it is connected to your USB port). So it is not recognizing the last used controller, is it?
     
  29. CurryKitten

    CurryKitten

    Joined:
    Dec 22, 2016
    Posts:
    23
    I'm getting a slightly weird issue with buttons from unknown controllers in Android. I turned off the support for Unknown Gamepads in the Platform Settings as I'm working with USB connected RC radios.

    RC channels 1-8 usually appear as axis 1-8 as well, although this varies and isn't a big deal. Easy to remap the controls etc. But what I'm seeing is a seemingly occasional triggering of a button (or two) from certain axis. It's not consistant, but did strike me as odd.

    The actual issue I found was that controls that do represent themselves as buttons (and actually should do) essentially RC channel 9-32 don't seem to register as actual button presses when using an Android device.

    To explain further, I show some UI that shows when a button is being pressed.. and which button it is so a user can reallocate this to a function. I'm doing this using the raw GetButton on the joystick

    Code (CSharp):
    1. for (int i = 0; i < displayNumButtons; i++)
    2. {
    3.     buttonToggle[i].isOn = player.controllers.Joysticks[0].GetButton(i);
    4. }
    Actions that get assigned to buttons are then checked in an Update look along the lines to

    Code (CSharp):
    1. if (player.GetButtonDown("Reset"))
    2. {
    3.     //Do stuff
    4. }
    This works in the editor, works on the desktop builds, and works in Android using a known controller - like an Xbox One controller, but as soon as I plug something in that using the unknown controller map on an Android device then the buttons don't seem to register with their actions. I thought the button might be in a weird state so tried printing out debug when any button was pressed

    Code (CSharp):
    1. if (player.GetAnyButtonDown())
    2. {
    3.     Debug.Log("Button has been pressed!");
    4. }
    But I'm getting nothing at all here (using adb logcat to check the debug messages) Android certainly seems to have it's own little weirdness issues, and I'm wondering if this might be one of them. Any idea what might be happening here?
     
  30. jason_yak

    jason_yak

    Joined:
    Aug 25, 2016
    Posts:
    381
    Right, yea this does sound really quite problematic. Thanks for the explanation. Our apps target dozens of platforms and it's far from an elegant solution, but we might need to end up having some kind of split solution where we use a different plugin for Apple platforms, Rewired for everything else. I'm not sure I can think of another solution where we can support the new Apple OS features. Anyway, thanks for the info and get that sounds like a total mismatch. Well, in the unlikely scenario you did end up working on a totally separate plugin for this, we'd be first in line to buy it, cheers.
     
  31. oldManPig

    oldManPig

    Joined:
    Oct 25, 2019
    Posts:
    8
    Hi there, incredible asset.

    I'm upgrading from the New Input System but one thing I'm finding difficult is redesigning my logic for multiplayer UI menus.

    My old logic was: Spawn a canvas menu for each player > use a multiplayerEventSystem and UI Input Module > plug the UI input module into the PlayerInput for each player.
    = each player has their own private menu.

    I was planning on swapping out that last step for just setting the player ID for the RewiredStandaloneInputModule, but I can't seem to find a way to do that at runtime. Am I missing something obvious?
    Many thanks!
     
unityunity