Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Unity 2022.2 is now available as the latest Tech release.
    Dismiss Notice
  3. We are making some changes to the DOTS forums.
    Dismiss Notice
  4. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    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:
    5,279
    FYI that was listed in the first link I sent you in response to your original post:

    https://guavaman.com/projects/rewired/docs/HowTos.html#last-used-controller

    Determining which Controller was last used
    You can determine which Controller or what type of Controller was last used system-wide or by an individual Player. One common use of this technique is to switch on-screen glyphs depending on whether the user is using a mouse/keyboard or a Joystick.

    Use the following methods:

    The ReInput methods will get the last active controller of all controllers regardless of whether or not it is assigned to a Player or any of the elements have been mapped. This is most useful for one-player games.

    The Player.controllers.GetLastActiveController method will get the last active controller used by that Player. Be aware that only mapped elements determine whether a Controller just became active. For example, if you're testing to see if the mouse is the last active controller, if nothing is mapped to the left mouse button and it is clicked, it will not be considered the last active controller in the Player.

    Then you can get the Controller type from Controller.type.

    Code (csharp):
    1. // Get last controller from a Player and the determine the type of controller being used
    2. Controller controller = player.controllers.GetLastActiveController();
    3. if(controller != null) {
    4.   switch(controller.type) {
    5.    case ControllerType.Keyboard:
    6.      // Do something for keyboard
    7.      break;
    8.    case ControllerType.Joystick:
    9.      // Do something for joystick
    10.      break;
    11.    case ControllerType.Mouse:
    12.      // Do something for mouse
    13.      break;
    14.    case ControllerType.Custom:
    15.      // Do something custom controller
    16.      break;
    17.   }
    18. }

    You can also subscribe to events instead of polling:

    .
     
  2. joelgb2194

    joelgb2194

    Joined:
    May 6, 2015
    Posts:
    1
    I'm experiencing the same Invalid raw input data size: 0 bytes error when using joysticks and triggers that was posted in this forum a while ago. It seems I'm only getting this issue on my steam deck and was wondering if you have any newly updated solution for muting this error seeing that it's coming from unity's side.

    The only solution I found was the disable native input in rewired but I would really rather not have to do that.

    This is the error I'm getting:
    Invalid raw input data size: 0 bytes
    UnityEngine.StackTraceUtility:ExtractStackTrace ()
    UnityEngine.Windows.Input:ForwardRawInput (uint,uint,uint,byte*,uint)
    Rewired.Internal.Windows.Functions:ForwardRawInput (intptr,intptr,uint,intptr,uint)
    Rewired.Utils.ExternalTools:WindowsStandalone_ForwardRawInput (intptr,intptr,uint,intptr,uint)
    UcebnovMRXUhXfmXMDfqLrJTnmob:vGsaLotBEBzTjxjsYvGTiifBrHxS (byte[],uint[],uint[],uint&,uint&)
    UcebnovMRXUhXfmXMDfqLrJTnmob:xJdaUztzVbxGebwbpDiMEhSaiuhb (intptr,double)
    UcebnovMRXUhXfmXMDfqLrJTnmob:ApmsWFfFKjsRSWSTRtneYlzBIRtR (intptr,uint,intptr,intptr)
    QglpTFQNvvBySbsAmUHYGDvvRXDF:ApmsWFfFKjsRSWSTRtneYlzBIRtR (intptr,uint,intptr,intptr)
    trBISPOPmjmOLqJgkcJCgvuhcjXhb:mFnFhEfXOCCoufQGgFbeAwstwzaOA (intptr,uint,intptr,intptr)
     
  3. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,279
    This is a Steam issue caused by their Proton Wine fork sending invalid Raw Input events. I cannot fix it in Rewired. Further, the error being logged is being logged by Unity, not Rewired. Rewired is just forwarding the Raw Input event data to Unity for processing because both Rewired and Unity need the event and Microsoft's Raw Input API design makes this impossible without forwarding.

    I have spent a great deal of time on this issue. You can see the last discussion about it in this thread here:

    https://forum.unity.com/threads/rewired-advanced-input-for-unity.270693/page-158#post-7868194
    https://forum.unity.com/threads/rewired-advanced-input-for-unity.270693/page-158#post-7868854
    https://forum.unity.com/threads/rewired-advanced-input-for-unity.270693/page-159#post-7904563
    https://forum.unity.com/threads/rewired-advanced-input-for-unity.270693/page-159#post-7905445
    https://forum.unity.com/threads/rewired-advanced-input-for-unity.270693/page-159#post-7908430
    https://forum.unity.com/threads/rewired-advanced-input-for-unity.270693/page-159#post-7908586
    https://forum.unity.com/threads/rewired-advanced-input-for-unity.270693/page-159#post-7915336
    https://forum.unity.com/threads/rewired-advanced-input-for-unity.270693/page-159#post-7915741
    https://forum.unity.com/threads/rewired-advanced-input-for-unity.270693/page-159#post-7917079
    https://forum.unity.com/threads/rewired-advanced-input-for-unity.270693/page-159#post-7918357

    TLDR: Steam has to fix the bug in their software.
     
  4. joelsinbarba

    joelsinbarba

    Joined:
    Dec 21, 2016
    Posts:
    16
    Coming back to this with more feedback.
    It does look like the issues are only present on m1 macs.
    I just tested everything with an intel macbook and Rewired's GameController works with gyro and vibration included.

    However,
    - Light is not changing on the DualSense controller
    - There is still an issue present with gyro, where it either stops at some point or "jumps" to the next value. I may be able to share a recording of this happening.

    Also, is GameController support for iOS and tvOS planned?

    Btw, thank you for the awesome support for Rewired
     
  5. joelsinbarba

    joelsinbarba

    Joined:
    Dec 21, 2016
    Posts:
    16
    More updates:
    https://developer.apple.com/documentation/macos-release-notes/macos-13-release-notes

    Resolved in macOS 13 Ventura beta 4
    • Fixed: Motion controls for the DualShock 4 and DualSense wireless controllers can not function correctly. (93671115)
    Hopefully the fixes come with macOS Ventura which should be coming this or next month. It may/may not be a good idea to prepare Rewired for the release?
    Also, oh no... looks like they're adding a bunch of other controllers: :confused:

    Game Controller
    New Features in macOS 13 Ventura Beta
    • Many additional Bluetooth and USB game controllers are supported by the Game Controller framework on macOS 13, iOS 16, and tvOS 16 and later. (82409809)
     
  6. AubreyH

    AubreyH

    Joined:
    May 17, 2018
    Posts:
    18
    I'm having loads of fun with the PS5 gyro, but I am noticing a fair amount of smoothing on the implementation.

    I'm assuming it's a low pass filter, but could be wrong. Will the smoothing value be exposed so that we can effectively turn it off, and come up with our own filtering? I personally like it really raw, but when using IDualShock4Extension::GetGyroscopeValueRaw it felt like I was getting basically the same filter treatment as IDualShock4Extension::GetOrientation ? I could be wrong? Something weird and wonderful happening where it snaps to the horizon over time? Noticeable right after calling IDualShock4Extension::ResetOrientation(). Hard to tell exactly what's going on?

    Really excited to use this in some prototypes!
     
  7. deab

    deab

    Joined:
    Aug 11, 2013
    Posts:
    87
    I've upgraded Unity to 2022.1.15f, having already installed Rewired 1.1.43.0.U2021. When launching unity I get the warning about not designed for 2022. I've removed and reinstalled Rewired (with a Editor restart along the way). How do I access the 2022 stream?

    Thanks!
     
  8. Japi

    Japi

    Joined:
    Jan 13, 2010
    Posts:
    14
    I'm currently porting my game to Linux. But I noticed that I can't get Rewired to work at all, when I have selected the input source in Linux to be Native in Rewired's settings. I have tried different game controllers (Xbox One, Xbox Series S/X, Switch Pro Controller), but it doesn't to work (like nothings happens from game controller buttons or from joysticks in editor or in build). But when I select the input source to be Unity, then some controllers work (but some controllers are wrongly mapped).

    In Windows and Mac, everything works in editor and in builds. In Windows I'm using RawInput as input source (XInput enabled). In Mac, I'm using Native as input source. In Windows and Mac, I have been making builds for long time already (probably over 40 builds already). So I'm bit puzzled, if I'm missing some basic setting in Rewired (or I need to install some additional package to Linux) to get the Linux support to work? I'm still not that familiar developing to Linux, so maybe I could be missing something? I would want to get the Native input source to work under Linux (rather than the Unity input source).

    I'm running Pop OS 20.04 LTS, Unity 2019.4 and Rewired 1.1.43.0.
     
  9. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,541
    Not familiar with your Linux distro.

    (1) Have you tried building any of the Rewired examples and see if that works? Then at least you can narrow down the issue some more.

    (2) Have you followed the steps in the Rewired documentation?

    https://guavaman.com/projects/rewired/docs/Troubleshooting.html#debug-information

    (3) Do you have any other Linux distros you can try? Do you have an official Unity supported Linux distro that you can test with and see if your game works on that?
     
  10. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,541
    Have you followed these steps listed in the Rewired documentation?

    https://guavaman.com/projects/rewired/docs/Updating.html
     
  11. TinyTitanDave

    TinyTitanDave

    Joined:
    Jan 9, 2017
    Posts:
    8
    Hi. We are having an issue with adding New Actions into a user assignable Map Category. We are on Unity 2020.3.22f1 and Rewired 1.1.41.1.U2020.

    It seems when we add a new action to a user assignable map category, that new action doesn't properly get added/enabled. We are saving the the mappings for that category into our own save file and then on game load clearing out the user assignable maps from the controllers. So we initially thought it was our code that was messing up.

    We then tried using the UserDataStore_PlayerPrefs that comes with Rewired, and same thing was happening. After we added a new action to a user assignable map category, and running the game, that new action wasn't assigned/present.

    Is this the intended behavior? Or is this a bug?

    The one way we got that new action to work is when we restored the defaults with the function RewiredPlayer.controllers.maps.LoadDefaultMaps(). After calling that, new the action that was added works, however it reverts all the other user assigned map.

    Currently our game is live and if we ever want to add new user assignable actions, we would have to tell our players to restore their controls to the defaults, which is not ideal.

    We also tried getting all the actions that exist in the map category but couldn't really find anything in the APIs. Our intention was to get the actions that exist from the settings or defaults or something like that, and compare it against what is saved, and then if there was something in the defaults that ISN'T in the save file, manually add it and resave so that mapping exists.

    Is there an API function like that?

    Any other suggestions would be appreciated.
     
  12. Japi

    Japi

    Joined:
    Jan 13, 2010
    Posts:
    14
    The Pop OS distro is based on Ubuntu. Now I have tested bit more of the game controllers (Rewired with Native input source). Xbox One controller (connected to an USB dongle) works correctly. But if I connect the Xbox One controller (or Xbox Series S/X controller) with Bluetooth, the Rewired debug shows that the controller isn't recognized, even though Rewired debug shows the name to be "Xbox Wireless Controller" (with both Xbox One and Series S/X controllers).

    If I connect the Xbox Series S/X controller with an USB dongle, then Rewired debug doesn't recognize it, although it says the name of the controller is "XBOX ACC".

    Is there a way to add these controllers that aren't recognized, to the same profile that the Xbox One controller with USB dongle uses (the "Xbox One Controller" joystick map)? For example by adding these controller's hardware identifiers to somewhere? I really dont want to use the "Unknown Controller" joystick maps for these controllers.
     
  13. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,279
    I did not release the update with light support. Releasing an update takes hours and this change is not enough to warrant an update.

    Rewired is doing nothing but recording the data Game Controller Framework is sending. Rewired does not apply filters to this data on any platform.
     
    Last edited: Sep 10, 2022
    joelsinbarba likes this.
  14. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,279
    I'm glad someone already reported these problems to them.

    There's nothing to do. It will just work.

    One of the big reasons I didn't release GCController support months ago was the constant state of upheaval this API is always in. Every single OS release changes something, deprecates something, or adds new API. What a mess. Why can't they properly develop their API before release instead of piecemealing things in every update? That's a nightmare for developers.
     
    Last edited: Sep 10, 2022
    joelsinbarba likes this.
  15. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,279
    You don't say what platform you're talking about. This is required information to answer a question like this. Things work very differently on Windows/Mac and PS4/PS5.

    No filters whatsoever are applied to gyro or accelerometer values by Rewired. There is nothing to expose.

    If you're talking about Windows/Mac, IDualShock4Extension.GetOrientation is completely different and is my own sensor fusion algorithm. I won't be exposing anything for that because it's only used on two platforms. I should never have created the GetOrientation function because it cannot possibly work right. The combination of a gyro and accelerometer can never give you a stable up axis rotation because that's simply unknown. It WILL drift, and does so very quickly, and there is no additional sensor (magnetometer, etc.) to use to correct that drift. I don't suggest using GetOrientation for anything.

    On Windows/Mac, ResetOrientation does not affect anything but GetOrientation. Accelerometer and gyro values are not affected.
     
    Last edited: Sep 10, 2022
  16. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,279
    deab likes this.
  17. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,279
    Linux distro fragmentation. Every distro (or even an update) may customize controller information and sometimes even mappings. Without a system like XInput that can universally identify XInput-compatible controllers, every single combination of identifiers, element counts, and mappings they choose to create have to be explicitly recognized. That's one of the reasons Rewired only supports Ubuntu.
     
    Last edited: Sep 10, 2022
  18. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,279
    This is explained in the User Data Store documentation:

    https://guavaman.com/projects/rewired/docs/UserDataStore.html
    -
    IMPORTANT: Saved XML data is not updated when you make changes to the Rewired Input Manager

    UserDataStore does not manage changes between the Rewired Input Manager and data that is already saved to XML. If you make changes to the Rewired Input Manager settings such as adding new controls to a Joystick Map, these new changes will not be preserved when loading saved XML data. The only automated solutions would be to either clear the save data by clearing Player Prefs so that the Rewired Input Manager defaults are used instead or load the default maps in the Player for the any controllers that changed and save those to XML overwriting the existing saved mappings.

    Management of saved user data is up to the developer. If you have special needs beyond the basic use cases, you should extend and replace the UserDataStore_PlayerPrefs component with a new UserDataStore component that meets your specific needs.

    IMPORTANT:

    During development, you may run into a situation where your controls don't seem to make sense. This may happen when you make some runtime control changes, save them, and then proceed to change your mappings in the Rewired Input Manager. Because UserDataStore_PlayerPrefs is configured to save controller data on disconnect and load controller data on start and controller connect, the loaded settings will override new changes you make to the default mappings in the Rewired Input Manager.

    During development, it may be useful to disable or remove the UserDataStore_PlayerPrefs component. If you've already saved controller settings and want to remove them, you can use the Clear All Player Prefs button in the Debug Options foldout on the UserDataStore_PlayerPrefs inspector. WARNING: This will clear ALL PlayerPrefs data for the current project. This is due to the limitation that there is no way to look up what keys exist in PlayerPrefs.

    ---------------------------------------------

    Rewired does not manage your saved user data. It can't do that. It doesn't know how the data is saved. The Rewired Input Manager data doesn't have any connection to saved user data. Making changes to the Rewired Input Manager does nothing but make changes to the serialized data in the Rewired Input Manager Game Object, which consists of nothing but developer-defined defaults. When Rewired initializes, it creates all the Players and assigns them the Controller Maps defined by the developer and designated to be loaded in that Player on start. When you load saved data using UserDataStore, that saved data overwrites everything in the Player at runtime. Whatever old data you saved is loaded and any changes you made to the developer-defined defaults is wiped from the Player. At the point you load saved user data, that saved user data becomes the source of truth, not the Rewired Input Manager developer-defined data.

    What you are trying to do would require a system that can analyze the saved user data before it's loaded and compare that to the developer-defined defaults and make intelligent decisions about how to merge new developer-defined defaults into already saved user-defined data. This is not a simple process, and the implementation may be different depending on how that user data is stored. This is the reason UserDataStore was implemented as an interface -- so the developer can create whatever kind of exotic data management system they want and have Rewired able to simply Load and Save from that system. UserDataStore_PlayerPrefs was provided as a then-universally-platform-compatible basic implementation.
     
    Last edited: Sep 10, 2022
  19. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,279
    Thanks Unity forum for not sending me email notifications again for 4 days.
     
  20. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,279
    This shows the process of creating a new controller definition. Modifying one is similar.

    https://guavaman.com/projects/rewired/docs/HowTos.html#new-controller-definitions

    NOTE: Your changes will be overwritten the next time you update Rewired.
    1. Open Rewired/DevTools/JoystickElementIdentifier scene and press Play.
    2. Select Rewired/Internal/Data/Controllers/HardwareMaps/Joysticks/MicrosoftXboxOne in the project.
    3. Click Launch Hardware Joystick Map Editor in the inspector.
    4. Click Linux Native.
    5. Use the information from the Joystick Element Identifier scene to determine the Matching Criteria for the controller. If the element counts match the "Default" variant, add the identifying information to that variant. If they do not match, you will have to make a new variant.
    6. Enter the Product Name, System Name, and/or Identifier information.
     
    Last edited: Sep 10, 2022
  21. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,279
    Not at this time.
     
  22. joelsinbarba

    joelsinbarba

    Joined:
    Dec 21, 2016
    Posts:
    16
    Please take this as a formal request :)

    Thank you~
     
  23. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,541
    Thanks again for the reminder!
     
  24. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,541
    Thanks again for taking up all of the hard challenges to support us on so many different platforms.

    Happily enjoying Rewired since 2014. :)
     
  25. TinyTitanDave

    TinyTitanDave

    Joined:
    Jan 9, 2017
    Posts:
    8
    Thanks for the response.

    Is there something in the API that returns the action element maps that are setup through the Rewired editor? That way we can just compare that data with what is saved and add any missing action mappings to our saved data.
     
  26. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,279
    Functions to access the Rewired Input Manager data are in ReInput.mapping:
    https://guavaman.com/projects/rewir...l/Methods_T_Rewired_ReInput_MappingHelper.htm

    GetControllerMapInstance
    GetJoystickMapInstance
    GetKeyboardMapInstance
    GetMouseMapInstance
    GetCustomControllerMapInstance
     
  27. RedVonix

    RedVonix

    Joined:
    Dec 13, 2011
    Posts:
    405
    I have an existing project that I'm replacing Unity Input System with Rewired (we're taking it to consoles and Rewired is just much more tried and true for console ports). I've added Rewired via the Package Manager, removed the Unity Input System, and ran the Rewired install script. However every time I start the game with the Rewired Input Manager in the scene, I get the following 2 errors back to back:

    I've uninstalled and reinstalled Rewired a number of times, and I've tested this by creating a new scene, placing nothing at all in the scene except the Rewired Input Manager in a scene and pressing play, but the above still happens. Any tips or advice on what could be causing this issue?

    Thank you!
     
  28. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,279
    See this:
    https://guavaman.com/projects/rewired/docs/KnownIssues.html#not-compatible-unity-new-input-system

    You have to enable the legacy "Input Manager" input system.

    Rewired: Rewired: An exception occurred during initialization. Input will not function.
    Exception:
    System.InvalidOperationException: You are trying to read Input using the UnityEngine.Input class, but you have switched active Input handling to Input System package in Player Settings.
    at (wrapper managed-to-native) UnityEngine.Input.get_mouseScrollDelta_Injected(UnityEngine.Vector2&)
     
  29. RedVonix

    RedVonix

    Joined:
    Dec 13, 2011
    Posts:
    405
    Ahhh that's what I was missing! Thanks again!
     
  30. Cellenseres

    Cellenseres

    Joined:
    Mar 30, 2015
    Posts:
    55
    Heya!
    Currently we're working on a Game that should support a handful of Steering wheels that currently aren't supported by Rewired.
    When I connect one that is compatible (like the Logitech G29), the hardwareTypeGuid gets shown in the Rewired Input Manager (which is 57379f00-0b2b-4f01-8bc5-5e9bef307350).

    We have some different ones some of our players suggested to add (Speedlink Trailblazer, VID: 0079, PID: 1864) which are always shown as XInput Controller (or RawInput Controller, depending on the Mode the Steering Wheel is in) which only shows the HardwareTypeGuid as 00000000-0000-0000-0000-000000000000.
    Is there a way to add support for this devices ourselves?

    @guavaman if you have a suggestion, please let me know!
    That'd help us a lot!
    We'd love to add support to new steering wheels by ourselves!
     
  31. Misscelan

    Misscelan

    Joined:
    Mar 8, 2013
    Posts:
    167
    Hi,

    I have a Control Mapper that is working fine in the editor, but when creating a standalone build and try to open the Mapper I get "Rewired Control Mapper: All prefabs must be assigned in the inspector!"

    I did not see that issue mentioned in these forums before, however I saw a similar error "All references" instead of "All prefabs" and the fix seemed to be deleting the Control Mapper and creating a new one.

    I did, but I got the "all references" error instead, and this time in the editor. So I reverted all the changes back.

    I'm not using Text Mesh Pro and I created my onw Language scriptable object, for the rest I'm using default prefabs.


    EDIT: Marking all the prefabs used by the canvas as addressables made it work. Not sure why.
     
    Last edited: Sep 16, 2022
  32. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,279
    See these in the docs:

    https://guavaman.com/projects/rewired/docs/HowTos.html#new-controller-definitions
    https://guavaman.com/projects/rewir...dd-controller-to-existing-controller-template

    All XInput devices are always supported on Windows Standalone if Use XInput is enabled.
     
  33. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,279
    All errors like this are caused by Unity serialization issues.
     
  34. RedVonix

    RedVonix

    Joined:
    Dec 13, 2011
    Posts:
    405
    I'm getting some projects up and running with Steam Deck, and want to clarify the correct intended setup for Rewired. I'm finding that when I make a build for Steam Deck (doing native Linux builds and installing them via the SteamOS Devkit Client), Rewired detects 3 controllers:
    • Keyboard
    • Mouse
    • Xbox 360 Controller
    I would have thought it would detect the Steam controller (as the layout for that is closer than Xbox 360), but I know this is also based on what the Steam Deck tells Rewired. So my real question here is - what is the intended controller to use for Steam Deck and Rewired? Should we use an Xbox 360 Controller layout, or is there a different layout that either exists (or is coming in the future) that we should load up in its place? I know we can manually detect if we're on a Steam Deck or not via Steamworks and could do manual adjustments from there as needed.

    Thanks!
     
  35. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,279
    Rewired offers no explicit support for Steam Deck, and I have never tested Rewired on Steam Deck. Anything I tell you is just based on my best guess without having ever tested to figure out Steam Deck works with regard to controllers. Rewired is just an application that consumes input from the standard OS APIs on a particular platform. Steam is responsible for creating and hiding the devices so the application sees what they want it to see.

    If you are making a Linux build and the controller is showing up as an Xbox 360 Controller, that means Steam is exposing a device that provides all the exact same identifying information as an Xbox 360 Controller. Rewired cannot detect a Steam Controller unless Steam is explicitly exposing a controller with the identifying information Rewired expects for a Steam Controller on Linux native. That would be a device with a Product/Vendor id of 11fc28de, 6 axes, 11 buttons, and 1 hat. Because it's showing up as Xbox 360 controller, Steam created a controller with identifying information with a Microsoft-specific Product/Vendor Id and/or Product Name.

    If Rewired is detecting Keyboard and Mouse as Joysticks, that means SteamOS is exposing those devices through UDEV as joysticks. That would be bad.

    As for what layout to use, the Gamepad Template covers all possible devices.

    If you are referring to what device to use to show glyphs to the user, if SteamOS is exposing an Xbox 360 controller, that's all the information Rewired knows about it. If you want to show some other glyphs for a different controller, you're going to have to make a special case exception for Steam Deck when choosing the glyphs. Based on what you've told me, there is no way to tell what controller is actually attached without getting this information through the Steam API.
     
    RedVonix likes this.
  36. phdhamster

    phdhamster

    Joined:
    Jun 16, 2020
    Posts:
    9
    First of all, I just wanted to say that Rewired has been super helpful for running my game's control system the way I want it to run. It's out now on Steam: https://store.steampowered.com/app/1492750/Mega_Knockdown/. I'm really grateful to you for making this plugin and I can't recommend it enough.

    Second of all, a quick question: I've recently made some changes to my game's default bindings. I'm currently using the built in PlayerPrefs script to automatically save custom bindings, so these changes don't seem to 'stick' unless the player resets everything to default. Should I just change the name of my PlayerPrefs Key Prefix to something else, so that everyone's bindings get reset to default? That wouldn't be likely to break anything, would it?
     
  37. wagenheimer

    wagenheimer

    Joined:
    Jun 1, 2018
    Posts:
    292
    Hi, I need help! I do have a problem and don't know why it did happen.

    RewiredHelper.instance.Player.GetAxis("CameraY")

    Why do I receive value from this Axis even when it is not being used? Most of the time it gets 0 as expected. But sometimes the value increases until it reaches 0.61, even though it is not pressed.

    Edit.: I checked Rewired Input Manager inspector and the bug also happens there. I'm using it to check the Right Stick. The value must be 0, not pressed at all, but out of nowhere, it starts to increase and goes up to 0.61. Then it slows down again and then stops.

    It's an Xbox One Controller plugged into USB. I do not have problems playing any games.

    Edit2: The same problem happens on GamepadTemplateUI sample - The right stick (Aim) is not pressed at all.
    upload_2022-9-22_16-15-20.png
     
    Last edited: Sep 22, 2022
  38. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,279
    This is explained in the User Data Store documentation:

    https://guavaman.com/projects/rewired/docs/UserDataStore.html
    -
    IMPORTANT: Saved XML data is not updated when you make changes to the Rewired Input Manager

    UserDataStore does not manage changes between the Rewired Input Manager and data that is already saved to XML. If you make changes to the Rewired Input Manager settings such as adding new controls to a Joystick Map, these new changes will not be preserved when loading saved XML data. The only automated solutions would be to either clear the save data by clearing Player Prefs so that the Rewired Input Manager defaults are used instead or load the default maps in the Player for the any controllers that changed and save those to XML overwriting the existing saved mappings.

    Management of saved user data is up to the developer. If you have special needs beyond the basic use cases, you should extend and replace the UserDataStore_PlayerPrefs component with a new UserDataStore component that meets your specific needs.

    IMPORTANT:

    During development, you may run into a situation where your controls don't seem to make sense. This may happen when you make some runtime control changes, save them, and then proceed to change your mappings in the Rewired Input Manager. Because UserDataStore_PlayerPrefs is configured to save controller data on disconnect and load controller data on start and controller connect, the loaded settings will override new changes you make to the default mappings in the Rewired Input Manager.

    During development, it may be useful to disable or remove the UserDataStore_PlayerPrefs component. If you've already saved controller settings and want to remove them, you can use the Clear All Player Prefs button in the Debug Options foldout on the UserDataStore_PlayerPrefs inspector. WARNING: This will clear ALL PlayerPrefs data for the current project. This is due to the limitation that there is no way to look up what keys exist in PlayerPrefs.

    ---------------------------------------------

    Your Controller Map changes in the Rewired Input Manager are not "sticking" is because Rewired does not manage your saved user data. The Rewired Input Manager data doesn't have any connection to saved user data. Making changes to the Rewired Input Manager does nothing but make changes to the serialized data in the Rewired Input Manager Game Object, which consists of nothing but developer-defined defaults. When Rewired initializes, it creates all the Players and assigns them the Controller Maps defined by the developer and designated to be loaded in that Player on start. When you load saved data using UserDataStore, that saved data overwrites everything in the Player at runtime. Whatever old data you saved is loaded and any changes you made to the developer-defined defaults is wiped from the Player. At the point you load saved user data, that saved user data becomes the source of truth, not the Rewired Input Manager developer-defined data.

    If you want to change mappings from the developer side after users have already saved their own mappings, you have to clear the saved data and load the defaults. Changing the Player Prefs key prefix would work, but all the old data would be in the registry still. If you don't care about that, that's fine. It would prevent you from having to clear Player Prefs entirely in the case you have other save data.

    You could also just let the players keep their old bindings and they could reset them manually for each controller. Control Mapper has a button to reset the currently connected controllers mappings to their defaults. This calls player.controllers.maps.LoadDefaultMaps.
     
    Last edited: Sep 23, 2022
  39. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,279
    What you're describing is massive drift on the right stick of the controller you're using. This would be caused by hardware problems. Very old controllers or controllers that have been heavily used very often have a lot of drift. This is why games should always provide a means for the user to set their own dead zone values for axes. Both Control Mapper and Control Remapping 1 example show this.

    There is no way you can set a new global default dead zone for the controller without that change being overwritten the next time you update Rewired. But that is not the recommended way to deal with an issue like this anyway because the dead zone for a device with bad drift is very specific to that individual device anyway.
     
    wagenheimer likes this.
  40. marchall_box

    marchall_box

    Joined:
    Mar 28, 2013
    Posts:
    127
    Hello,

    I am having below crash/log from Rewired in the build.
    I've never had this issue but one of the playtester got this.
    Should I manually make an exception for this? Please suggest better way to do it!

     
  41. RedVonix

    RedVonix

    Joined:
    Dec 13, 2011
    Posts:
    405
    Very odd problem I'm finding. I have a custom mapper screen, and in the code I'm able to properly rebind input. However, if the input utilizes an Action that is of type Axis, and I have rebound the Negative portion of the Axis, then it actually changes the Negative Element map to match the Positive Element Map

    Here is the Actions layout for the ScrollItems Action type. Note that the Positive Name is NextItem, and Negative is PreviousItem:
    upload_2022-9-26_17-59-13.png

    And here you can see how the Action is setup for the D-Pad on the Xbox 360 Controller (same layout is used however on all other controllers):
    upload_2022-9-26_17-59-58.png

    Here is the binding code:

    Code (CSharp):
    1.  
    2. public async void RebindAction(string inActionName)
    3.         {
    4.             if(activeControlState == ControlState.Binding)
    5.             {
    6.                 return;
    7.             }
    8.  
    9.             SetActiveControlState(ControlState.Binding);
    10.  
    11.             // Disable the Controller Maps while listening to prevent UI control and submissions.
    12.             SetMapEnableState(false);
    13.  
    14.             await Task.Delay(5);
    15.  
    16.             ActionElementMap elementMap = GetElementMapForAction(inActionName);
    17.             if(elementMap == null)
    18.             {
    19.                 EndButtonChanging();
    20.                 return;
    21.             }
    22.  
    23.             InputMapper.Context context = new InputMapper.Context()
    24.             {
    25.                 actionId = elementMap.actionId,
    26.                 controllerMap = rewiredControllerMap,
    27.                 actionElementMapToReplace = elementMap,
    28.                 actionRange = elementMap.axisRange,
    29.             };
    30.  
    31.             UnityEngine.Debug.Log("REBINDING: " + elementMap.elementIdentifierName);
    32.  
    33.             // Start listening
    34.             InputMapper.Default.InputMappedEvent += OnInputMapped;
    35.             InputMapper.Default.ConflictFoundEvent += OnConflictFound;
    36.             InputMapper.Default.Start(context);
    37.         }
    And this is my code that gets the element maps:
    Code (csharp):
    1.  
    2.         private ActionElementMap GetElementMapForAction(string inActionName)
    3.         {
    4.             string allMaps = "";
    5.             // DEBUGGING!
    6.             foreach (ActionElementMap elementMap in rewiredControllerMap.AllMaps)
    7.             {
    8.                 allMaps += elementMap.actionDescriptiveName + " / ";
    9.             }
    10.             Debug.Log(allMaps);
    11.             //DEBUGGING!
    12.  
    13.             foreach (ActionElementMap elementMap in rewiredControllerMap.AllMaps)
    14.             {
    15.                 if (elementMap.actionDescriptiveName == inActionName)
    16.                 {
    17.                     return elementMap;
    18.                 }
    19.             }
    20.  
    21.             Debug.LogError("--- No ActionElementMap was found for ActionName " + inActionName + ". Available maps are: " + allMaps + " / " + rewiredControllerMap.AllMaps.Count);
    22.             return null;
    23.         }
    24.  
    The log output there in the Debugging shows that the PreviousItem entry exists BEFORE binding, but after binding it actually turns into the NextItem action!

    BEFORE BINDING:
    Interact / UISubmit / UICancel / Reload / Fire / Pause / NextItem / Up / Right / PreviousItem / Down / Left / MoveHorizontal / UIHorizontal / MoveVertical / UIVertical / LookHorizontal / LookVertical / Zoom / Sprint

    AFTER BINDING:
    Interact / UISubmit / UICancel / Reload / Fire / Pause / NextItem / Up / Right / NextItem / Down / Left / MoveHorizontal / UIHorizontal / MoveVertical / UIVertical / LookHorizontal / LookVertical / Zoom / Sprint

    I'm pretty stumped on what I'm doing wrong to cause the ElementMap to get replaced with the Positive one and could use some help. Thanks in advance!
     
  42. DimeStudios_Dan

    DimeStudios_Dan

    Joined:
    May 4, 2015
    Posts:
    5
    Hi, question about gamepad templates.

    Is there a way to go back and forth between the hardware mapping of connected Joystick elements and the Gamepad Template elements without going through actions or action maps? So for example, get the pairings for a controller element from a gamepad template element, and then again for a gamepad template element from the controller element.

    Thanks

    edit: Hit a brick wall with this very VERY useful information in the Entry and ElementIdentifierMap data in Rewired.Data.Mapping.HardwareJoystickTemplateMap seeming to not be exposed for access at runtime. But being able to check the hardware mapping in the List<Entry> Joysticks at runtime (or a read only copy) would go a long way to solving this hardware element to template element mapping issue...

    edit edit: Got a work around working by creating an invisible, unused action category for the Template "actions" for mapping the gamepad template to all the elements. Not ideal but at least creates somewhat of a bridge between the connected hardware element ids and the template element ids that I can store in dictionaries on init / controller connect events.

    If someone has a better solution for a comprehensive hardware to template element mapping, all ears. <3
     
    Last edited: Sep 27, 2022
  43. Misscelan

    Misscelan

    Joined:
    Mar 8, 2013
    Posts:
    167
    Hi,

    I have this discrepancy when calling player.GetAxis for a gamepad, values for the horizontal and vertical axis return 1/-1 nearly all the time, except when really close to one of the main directions (up, down, left, right)

    So if the stick is pointing right up, I will get vertical = 1, horizontal = 0. But as soon as move the stick slightly to the right the horizontal value will increase rapidly towards 1 but vertical will still be 1.

    However this values, differ from what I see in Rewired's Debug, so a stick in a upper-right diagonal position will return 1,1 when using player.GetAxis but on the debug it will return approx 0.75/0.75.

    What setting can modify the output so it doesn't match the debug? Or, how could I prevent the values to be so aggressive?

    Thanks!
     
  44. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,279
    There is nothing you or I can do to make this work. The error means the Windows API function used to open the HID device is failing. It can't be opened for whatever reason. This reason could be anything including the device being opened in exclusive mode by another application. This is not a crash. This is an exception. It is logged and the game continues.
     
  45. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,279
    I see multiple issues.

    1. GetElementMapForAction is searching on the descriptive name. It would be better to search on the Action Id + Axis Range + Axis Contribution (for split axes) for Axis element types and Action Id + Axis Contribution for button element types. But this is kind of moot anyway as this function is not useful anymore based on the information below.

    2. You are getting your InputMapper.Context.actionRange value by grabbing it from the existing Action Element Map you're trying to replace. This is the problem. All 4 remapping examples that come with Rewired show the Axis Range that is passed into InputMapper.Context coming from the UI input field itself. The examples always have 3 fields: Full axis, positive, and negative, and the InputMapper.Context.actionRange is chosen depending on which one the user clicks on.

    The property in InputMapper.Context you are setting is called actionRange. This is not equal to ActionElementMap.axisRange. From the docs:

    "The range of the Action's value to map input to. For example, for an axis-type Action, should user input be mapped to the full range of the Action or just one side of the Action (+/-)?"

    It was probably an unfortunate optimization to re-use the AxisRange enum here to describe something different (the Action) than ActionElementMap.axisRange describes (the element).

    Axis Actions bound to button elements do not use the Axis Range value. This value could be anything, but defaults to either Full or Positive (I can't remember which).

    ActionElementMap.axisRange describes whether the Action is binding to the full, positive, or negative portion of the axis element. It is describing the element, not the Action. This does not apply when the Action is bound to a button element because buttons do not have a range of values or +/- poles.

    ActionElementMap.axisContribution describes how the binding contributes value to the Action when that Action is queried as an Axis. (GetAxis(...). It is describing the Action, not the element. Axis Contribution is used to determine how button elements and split-axis element (one pole of an axis element) bindings contribute value to the Action's value when queried as an axis.

    By grabbing this value from the existing Action Element Map you find for the Action and passing the ActionElementMap.axisRange in for InputMapper.Context.actionRange, all bindings to buttons will result in AxisRange.Positive being passed to the InputMapper.Context, resulting in all button bindings having a positive Axis Contribution which is exactly what you're seeing.

    The remapping examples show passing AxisRange.Positive to InputMapper.Context.actionRange for button-type Actions, and for axis-type actions, 3 fields are shown: Full, Positive, and Negative, to allow the user to determine whether they want to bind to "ScrollItems", "Next Item", "Previous Item". These correspond to actionRanges of AxisRange.Full, Positive, Negative. If you don't want to allow users to bind a full axis to show "ScrollItems" and require split axis/button bindings, you will have to instead draw two input fields, one that sets positive and one that sets with negative actionRange in InputMapper.Context and do not define any full-axis bindings to this Action in the Rewired Input Manager developer default bindings.
     
    RedVonix likes this.
  46. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,279
    You should not need to access anything from a Hardware Joystick Map. Everything you need is in the Controller Template itself.

    https://guavaman.com/projects/rewired/docs/ControllerTemplates.html#scripting

    Controller Template to Controller Elements:

    Controller Template Element Sources:

    Each Controller Template Element points back to a Controller Element where input values are actually drawn from. This information can be found in the IControllerTemplateElement.source property. The source type can be determined using the IControllerTemplateElementSource.type property and then cast to the appropriate IControllerTemplateAxisSource or IControllerTemplateButtonSource.

    Controller Template Elements from Controller Elements:

    Getting a Controller Template Element from a Controller Action mapping:

    If you want to determine the Controller Template Element that corresponds to a Player-Action mapping in a Controller Map, it can be converted to a Controller Template Element Target by using the method IControllerTemplate.GetElementTargets.

    Note: This shows passing an Action Element Map to the function. The function actually takes a ControllerElementTarget structure. Action Element Map is implicitly converted to a Controller Element Target.

    https://guavaman.com/projects/rewir...red_IControllerTemplate_GetElementTargets.htm

    Create a ControllerElementTarget by setting all the relevant settable properties in the structure:
    https://guavaman.com/projects/rewired/docs/api-reference/html/T_Rewired_ControllerElementTarget.htm
     
  47. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,279
    This would not happen automatically.. This most likely means you have set a giant Joystick Axis sensitivity in the Input Behavior. Change it to 1.

    The only other possible cause would be if you were to have calibrated these axes badly using Control Mapper, or if you built your own calibration system. This data would be loaded from XML. Clear Player Prefs if you using Control Mapper.
     
  48. marchall_box

    marchall_box

    Joined:
    Mar 28, 2013
    Posts:
    127
    Ah I see. It was coming out as a red console text so I though it would be a crash in an actual build (Not the development mode build)
     
  49. leocastanhob

    leocastanhob

    Joined:
    Sep 19, 2018
    Posts:
    6
    Hi guavaman!
    First of all thanks so much for this awesome asset <3 super useful.

    I have a question about the RewiredStandaloneInputModule. (I didnt find my specific case on the documentation, but sorry in advance if it is there ><)

    My game is a dice based game and Im trying to add joystick control to it. But I stumbled with that Repeat Delay problem. (If you have many objects to navigate, when you press the axis to the right, for instance, it jumps to the last object in the right and vice-versa). The thing is that RewiredStandaloneInputModule solves this issue for Unity UI. But Im trying to do it with a custom object, not an UI. Is there a way to make RewiredStandaloneInputModule work with it or do I need to create my own repeat delay system?
    I read through this link and didnt find anything: https://guavaman.com/projects/rewired/docs/RewiredStandaloneInputModule.html#inspector-options

    Basically what Im asking, is there a Repeat delay for Axis? Cuz I just found it for buttons.

    Cheers.
     
  50. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,279
    An Action is both an Axis and a Button. You are trying to get the repeating value of the Action. It doesn't matter what the underlying element is that is bound to that Action.

    https://guavaman.com/projects/rewired/docs/InputBehaviors.html

    Button Repeating

    If you need to detect a button press that repeats on a regular interval, set the repeat rate and optional delay for these events and call one of the the button repeating method listed here.

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

    Repeating:

    • Player.GetButtonRepeating: Gets the repeating button state of an Action. This will return TRUE when immediately pressed, then FALSE until the Input Behaviour button repeat delay has elapsed, then TRUE for a 1-frame duration repeating at the interval specified in the Input Behavior assigned to the Action. This also applies to axes being used as buttons.

    No, you can't use Rewired Standalone Input Module for anything other than controlling Unity UI.
     
    leocastanhob likes this.