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. 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,500
    One problem with EditorApplication.update is that it may (probably) does not respect ScriptExecutionOrder. That would not cause the problem you describe, but it could be a problem. That's why it's advised you use the input events instead. That still won't fix your problem though.

    Based on what you've said about what it's showing for the mouse in Debug Information, nothing you can do will fix it. I seriously doubt there is anything I could do to fix it, short of concocting some kind of special case hack to clear the axis values just for this scenario, something I hate doing for many reasons.

    Nothing your scripts do can affect Rewired's ability to read and process input from controllers. Your scripts simply consume input after Rewired has processed the input at the beginning of the frame.

    I'm assuming you're verifying the actual axis values in Debug Information -> Controller -> Space Mouse and not the Action.

    Are the 3D mouse's axes returning delta values like a mouse?

    There are only a few things that could cause an element's value to get stuck on, all of which have to do with Raw Input events and/or the processing of those events. This is all very low-level.

    One of the following is probably happening:
    1. Windows is not sending the last event (0 axis value).
    2. Rewired is somehow not receiving the last event.
    3. Something else is consuming and removing the event from the Windows thread queue before Rewired receives it. (Unity most likely.)

    You said when you click one of your primary mouse buttons that it doesn't clear the axes. A real mouse and the Space mouse are different device types send their own input reports individually. It's likely that if you were to click one of the Space Mouse's buttons when you're in this state that it would clear the axis values.

    A CPU slowdown would not cause it to miss a Raw Input event. Raw Input events are delivered through the Windows message queue which can hold thousands of messages.

    What version of Unity is this you're using?

    There are just so many things in play here when you're talking about the Unity editor. There's a whole song and dance that happens just so Rewired can register for Raw Input devices and receive messages from them without breaking Unity's own processing of those same messages. Microsoft designed Raw Input so that only one single message window can receive messages for a device at any time. Unity is designed to register for and receive input from these devices, and it repeatedly changes the window registration as you click around different Windows. Rewired has to override this, so it's constantly fighting Unity for dominance. All of this editor functionality is totally opaque to me and was figured out through trial and error. It was a very large effort to ensure Rewired and Unity both can work at the same time in the editor. This was only an issue for the mouse in the legacy input system, but now the new input system uses Raw Input for both Mouse and Keyboard, so the same applies. I didn't think Unity was registering non-mouse HID devices for Raw Input events, but perhaps this device is in a HID usage that they do register and process events for. If it is, the very act of Unity registering the device again every time you click into a new window would explain it, because if it happened at just the right time, the last event that reports a zero axis value may get consumed by Unity in the interim after claiming the device before Rewired gets a chance to execute in the Editor update and claim the device back. If this is happening, there's no way possible I can fix this. The messages would be delivered to Unity's message window, bypassing Rewired's entirely, so it would never see them. The only possible workaround would be to use Direct Input instead of Raw Input which uses a polling-based API which has no concept of message windows or device registration.

    Another possible suspect: Changes were made in Unity 2021.2 by Unity that totally broke Rewired's ability to read mouse input due to their change to using the GetRawInputBuffer function which retrieves all Raw Input messages at once, clearing them from the message queue, causing Rewired to only be able to get the first message of any queue of events, leading to lost messages at the end of the queue. (That may be happening here, but I doubt it.) Because it was impossible for me to fix this, Unity had to expose a new function that would allow me to manually forward Raw Input events to Unity, so I could receive and consume them all first, then forward them to Unity neither side would lose most of the messages. This scenario does not make as much sense as the previous.
     
    Last edited: Feb 15, 2022
  2. gewl

    gewl

    Joined:
    May 19, 2016
    Posts:
    95
    Yes, that's right.

    I'm not sure what you mean by "like a mouse"—Rewired's debug information shows expected delta values during normal use, and shows no delta when the values get 'stuck'.

    Yeah, I didn't think clicking the primary mouse buttons would clear the axes, I was just using that to demonstrate that Rewired was continually updating other vlaues. Pressing the Space Mouse's buttons does not clear the axis values, though Rewired's debug information does reflect that the button is being pressed.

    2021.2.11.

    Thanks for the help. It doesn't surprise me to hear that there's no obvious culprit or solution for this stuff, given Unity's lack of built-in support for the 3D mouse, the trickiness of having things run in edit mode, etc. Switching to direct input seems to result in Rewired interpreting the spacemouse input in the same 'naive' way that other applications without specific functionality for it do, where Z-axis translation is treated as scrollwheel up/down and no other transforms or rotations have any effect. I'll fiddle with it a bit more tomorrow.

    It's a shame—the space mouse is a great tool, but the old Unity plugin for it doesn't work with il2cpp, the updated one requires the new Unity input system, the new Unity input system doesn't work with Rewired (and seems to introduce a bunch of performance problems disincentivizing me from running both input systems). Might just be between a rock and a hard place on this one.

    Thanks again!
     
    Last edited: Feb 15, 2022
  3. FreedTerror

    FreedTerror

    Joined:
    May 19, 2017
    Posts:
    17
    That worked, Thanks! I'm lovin how easy Rewired was to implement into my UFE 2 project 5/5 stars from me!
     
  4. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,500
    Mice return pixel delta values while joysticks return absolute values. You confirmed it's a delta value.

    That's very odd. The only way that behavior would make sense is if they're sending a separate input report for buttons than axes. It's extremely rare to see devices use multiple different input reports. The only other possibility is that the device is sending everything on one input report, but the device itself is just continuing to report the last value. The only way to know would be to examine the raw HID reports.

    That has changed with Unity 2021.2+:
    https://guavaman.com/projects/rewired/docs/KnownIssues.html#not-compatible-unity-new-input-system

    By "compatible", I mean Rewired can run along-side the New Input System post Unity 2021.2. Rewired cannot use the New Input System as a source of input.
     
  5. gewl

    gewl

    Joined:
    May 19, 2016
    Posts:
    95
    Right, I misspoke. Danger of writing a post too late at night. I saw that Rewired can work alongside the new input system, and that's great, but I've seen enough griping about performance overhead with the new input system that I wouldn't be thrilled to import it in my project just for the sake of this one feature—especially since I'm going to keep using Rewired for everything else.

    FWIW (if anyone else is struggling and comes across this), I'm going back to the TDxInput-based Space Mouse plugin for Unity to handle edit-time scene navigation and am just going to exclude the whole mess from builds, since I don't need it for runtime.

    Hopefully Unity exposes more of this stuff to you/us in the future. 3dconnexion has their own plugins for Unreal, Maya, AutoCAD, etc.—no wonder they haven't done anything with Unity if it's this much of a pain.

    Thanks again for the help.
     
  6. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,500
    Thanks for clarification.

    Their library really is the only way to properly support these devices. (Direct Input and Linux support are 10x the mess Raw Input is for different reasons, requiring a bunch of hackery.) Based on my work in the past implementing Raw Input and Direct Input support, there are known issues with the HID functionality of these devices that cannot be fixed by the user. I don't recall the exact nature of the problem, but I do recall a long discussion on the 3Dconnexion forums about something that was not possible to be made to work right because of incorrect data being returned by the device in the HID descriptor or report. The issues were known by 3Dconnexion but could not be fixed for various reasons including breaking anything that had been written to support it the way it is currently implemented.

    I doubt making a Unity editor plugin using TDxInput would be anywhere near as difficult as a Raw Input one. Unity is not using TDxInput and there would be no concept of the registration battle that happens with Raw Input. I don't know of anything about Unity that would stop them from making a plugin.
     
  7. fallthem000

    fallthem000

    Joined:
    Dec 12, 2015
    Posts:
    5
    Just an update on this, I did send it to Valve and they released today a new Proton version that fixes the issue, it's no longer needed to enable "alwaysUseUnityInput" since there's no crash anymore. However I noticed that now the game constantly prints "Invalid raw input data size: 0 bytes" on the logs, tried setting Rewired Manager logging to off but still happens so I'm guessing this is on the Unity side? I'm using Unity 2021.2.8f1
     
  8. Nefisto

    Nefisto

    Joined:
    Sep 17, 2014
    Posts:
    324
    Does your asset have some kind of built-in way to simplify the process of creating a "Resto default" behavior? I mean, have an unchangeable controller map that can be saved and loaded when the user presses a button to restore to default.
     
  9. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,500
    Glad to know I was correct that this was a Steam issue and that they fixed to so quickly.

    Every single logged message from Rewired is prefixed by "Rewired:". Any message that is not prefixed by that is not a message logged by Rewired. This is Unity logging that when Rewired finishes with the messages and sends them to Unity for processing.

    What version of Rewired are you using?
     
  10. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,500
    https://guavaman.com/projects/rewired/docs/HowTos.html#managing-controller-maps-runtime
    https://guavaman.com/projects/rewired/docs/HowTos.html#loading-controller-maps-runtime
    https://guavaman.com/projects/rewired/docs/HowTos.html#saving-loading-controller-maps


    Loading the Default Controller Maps:

    Default Controller Maps are stored in the Rewired Input Manager. You can load the defaults for a Player by using these methods:

     
  11. fallthem000

    fallthem000

    Joined:
    Dec 12, 2015
    Posts:
    5
    Rewired version: 1.1.41.5.U2021

    Upon further testing it seems like "Invalid raw input data size: 0 bytes" is not printed constantly, but only when pressing any of the triggers, bumpers or joysticks, no matter the behavior set for them. I remember seeing the same line printed before (when the game used to crash) but it'd happen very rarely and only once or twice. Now is consistent when interacting with any of the controls mentioned before, but the number of times printed per each interaction is not consistent, for example pressing a trigger once could print it 3 to 5 times.

    It doesn't hurt performance as much as I thought initially since it's not actually being printed constantly, but still I'd like to get rid of that message if it's just some type of warning, the only possible solution that comes to mind is testing with other Unity versions.
     
  12. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,500
    I doubt changing the Unity version will change anything. The only way the error could be affected by an Update to Unity is if they decided to stop logging an error when receiving a 0-byte Raw Input message.

    The problem is most likely the Raw Input message data being sent in by Proton. While I could "fix" this on Rewired's end by not sending any message along to Unity that has bad data, that really should not be the responsibility of Rewired to handle, cleaning up bad messages from the input library in order to stop a logged error in Unity.

    It's also possible it could be a bug in assembling this data to send to Unity in Rewired that cannot be reproduced under any other scenario, but I very much doubt that. There was already a fix for this issue in Rewired 1.1.41.2:

    Bug Fixes:
    - Unity 2021.2+, Windows Standalone, Raw Input, Direct Input w/ Native Mouse/Keyboard Handling: Fixed bug in processing Raw Input messages on 32-bit builds running on 64-bit Windows resulting in Unity logging "Invalid raw input data size" messages when using certain controllers.

    Please verify you are actually using Rewired 1.1.41.5 by checking in Window -> Rewired -> Help -> About.

    Is this a 32-bit or 64-bit build?

    That is another potential problem vector because of how oddly Windows behaves when running a 32-bit application in a 64-bit version of Windows with regard to the data structure returned by GetRawInputBuffer. If Proton is not duplicating this unusual behavior, a lot of problems will ensue, including getting this error and messages that are not read. More information about this can be found in this thread: https://forum.unity.com/threads/windows-mouse-raw-input-mouse-handling-broken-in-rewired.1172786/

    If the above 32/64-bit issue is the cause, you would see no errors logged in a 64-bit build but would see errors logged in a 32-bit build. Of course, that assumes Proton is correctly reporting whether the OS is 32/64 bits (Kernel32.dll IsWow64Process). There are a lot of vectors for problems when you're dealing with a Windows emulator.
     
    Last edited: Feb 19, 2022
  13. fallthem000

    fallthem000

    Joined:
    Dec 12, 2015
    Posts:
    5
    Can confirm we're using Rewired version 1.1.41.5

    Got same results from testing with a 64-bit build and also from testing with different Proton versions that fixed the crash issue, IsWow64Process returned true in all tests, finally tested without Rewired and the messages disappeared. I'll let Valve know about it, although since it's a Unity message I'm not sure they'll be able to do anything about it.
     
  14. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,500
    I suggest you open Rewired/Internal/Scripts/Platforms/Windows/Functions.cs and replace it with this:

    Code (csharp):
    1. // Copyright (c) 2021 Augie R. Maddox, Guavaman Enterprises. All rights reserved.
    2.  
    3. #if (UNITY_STANDALONE_WIN && !UNITY_EDITOR) || (UNITY_EDITOR_WIN)
    4.  
    5. namespace Rewired.Internal.Windows {
    6.  
    7.     public static class Functions {
    8.  
    9. #if UNITY_2021_2_OR_NEWER
    10.         public static void ForwardRawInput(System.IntPtr rawInputHeaderIndices, System.IntPtr rawInputDataIndices, uint indicesCount, System.IntPtr rawInputData, uint rawInputDataSize) {
    11.             unsafe {
    12.                 string s = "ForwardRawInput: indicesCount: " + indicesCount + ", rawInputDataSize: " + rawInputDataSize + ", Frame: " + UnityEngine.Time.frameCount + "\n";
    13.                 for (int i = 0; i < indicesCount; i++) {
    14.                     uint headerIndex = *((uint*)rawInputHeaderIndices + i);
    15.                     RawInputHeader* header = (RawInputHeader*)((byte*)rawInputData + headerIndex);
    16.                     s += "[" + i + "] Device Type: " + header->Type + "\n";
    17.                     s += "[" + i + "] Size: " + header->Size + "\n";
    18.                     s += "[" + i + "] Device: " + header->Device + "\n";
    19.                     s += "[" + i + "] Param: " + header->Param + "\n";
    20.                 }
    21.                 UnityEngine.Debug.Log(s);
    22.                 UnityEngine.Windows.Input.ForwardRawInput((uint*)rawInputHeaderIndices, (uint*)rawInputDataIndices, indicesCount, (byte*)rawInputData, rawInputDataSize);
    23.             }
    24.         }
    25.  
    26.         [System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential, Pack = 0)]
    27.         internal partial struct RawInputHeader {
    28.             public DeviceType Type;
    29.             public int Size;
    30.             public System.IntPtr Device;
    31.             public System.IntPtr Param;
    32.         }
    33.  
    34.         internal enum DeviceType : int {
    35.             Mouse = unchecked((int)0),
    36.             Keyboard = unchecked((int)1),
    37.             HumanInputDevice = unchecked((int)2),
    38.         }
    39.  
    40. #endif
    41.  
    42.     }
    43. }
    44.  
    45. #endif
    This will log all the Raw Input Header data being sent to Unity. Based on the error Unity is reporting, RawInputHeader.Size should be zero.
     
  15. fallthem000

    fallthem000

    Joined:
    Dec 12, 2015
    Posts:
    5
    Here is the log
     

    Attached Files:

  16. montyjack

    montyjack

    Joined:
    Jan 10, 2014
    Posts:
    43
    Heya, I'm having a weird problem that is likely due to a settings oversight on my part, but I'm stuck so I thought I'd ask for your input - I have a number of controller and keyboard maps defined and some of them are disappearing when the game starts. They're not disabled, they're not there AT ALL. I've checked and they should at least be visible and disabled but it seems they just don't get loaded. The two maps in question were the "Alternative" and "Mouse/Kbd" maps- see below.

    Maps exist in editor (image 1) but not during runtime (image 2)

    Thanks!
     

    Attached Files:

  17. Pourya-MDP

    Pourya-MDP

    Joined:
    May 18, 2017
    Posts:
    143
    hey everyone i have a error while trying to importrewired in unity 2021.2
    im using latest rewired version
    heres my error:

    Assets\Rewired\Internal\Scripts\Misc\ExternalTools.cs(84,34): error CS0535: 'ExternalTools' does not implement interface member 'IExternalTools.WindowsStandalone_ForwardRawInput(IntPtr, IntPtr, uint, IntPtr, uint)'

    any help will greatly appreciated
     
  18. Toficor

    Toficor

    Joined:
    May 6, 2015
    Posts:
    33
    Hi. I have question about connection of native Unity InputManager to the Rewired Input Manager, is there any? I started thinking about it when I was reworking my player controller from Unity input to the Rewired one.

    When I changed my code in controller from
    Code (CSharp):
    1. Input.GetButtonDown("Jump")
    to
    Code (CSharp):
    1. _player.GetButton("Jump")
    my players jump button changed to G instead of SPACE (default Unity). Then I noticed that my player started to jump lower than before.


    Space button jump with Unity default input


    G button jump with Rewired


    Next while I started searching reason for that behaviour I stumbled upon the Unity Input Manager settings in Project settings and noticed that space button is on Axes list (under Jump name) and g button isn't.


    upload_2022-2-22_18-38-6.png

    To sum up: Is there any hard connection between unity InputManager maps and Rewired maps? Why my controller is working differently according to used input manager?

    Any ideas appreciated.
    Thanks.
     
  19. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,500
    None whatsoever. The two are things are completely unrelated. Whatever you're seeing in the Unity Input Manager has nothing to do with Rewired or the value of its input.

    If changing the value of Jump in the Unity Input Manager affects what your player is doing in any way, that is proof you are not using Rewired to get input in your script and are instead using Unity's input system.

    Do you realize you have not only changed the source of input but have changed functionality? GetButton and GetButtonDown are not the same thing. You're using GetButtonDown in the Unity version and GetButton in the Rewired version.

    If you are the same user who emailed me the almost identical issue last week and had me download your project to find your GetButton/GetButtonDown error, the problem is because you have multiple scripts affecting the jump height and you've only changed one of your scripts to use Rewired, leaving the old one using Unity's input system, and now that you're pressing G, the script that is using Unity's input system still is getting no input because Jump is still assigned to Space in Unity's system so it's receiving no additional input from that script.
     
  20. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,500
    Look at your console in the Unity Editor. Do you see warnings being logged about loading saved XML data?

    https://guavaman.com/projects/rewired/docs/UserDataStore.html#saved-xml-not-synced

    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.
     
  21. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,500
    ExternalTools is a script included with Rewired. It is part of the package. Every version of Rewired that is released contains both the DLL and all the scripts required to match to that DLL. What you are showing me can only be possible if ExternalTools.cs was not updated but Rewired_Core.dll was. This should not be possible. They are both simply inside the Unitypackage that is distributed by the Asset Store.

    If you have moved Rewired to some other folder and then updated it from the asset store, or you have multiple copies of Rewired in your project somehow, it would be possible to get this error. Delete all copies of Rewired and any possibly lingering partial directories of files installed from the Unitypackage if the Rewired folder was moved and Unity extracted new files into the root Rewired folder, then reinstall it.

    https://guavaman.com/projects/rewired/docs/Troubleshooting.html#clean-reinstall
     
  22. Pourya-MDP

    Pourya-MDP

    Joined:
    May 18, 2017
    Posts:
    143
    hey man,ok will do a clean install and report
    thanks
     
  23. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,500
    Every single time mouse input events are received, some kind of corrupt event is being processed first. Then all subsequent mouse events are therefore invalid in that frame. If you were using mouse input in your game, you would see that it doesn't work at all.

    Device type is 256. This is an illegal value and does not represent a Raw Input device type.
    Size is 8145: This is clearly a bad value as an 8K input report for a mouse is absurd.

    This bad event of 8K size is causing the subsequent read of events to fail, likely because it's causing it to attempt to read these events from some place in memory far beyond where the actual event is stored.

    The size of the data in the event is taken from the data provided by the Raw Input header. dwSize is the field that contains this information:
    https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-rawinputheader

    The first read of Raw Input data every frame happens through two calls to GetRawInputData, one to get the size and one to get the message. Additional events are read using GetRawInputBuffer. It appears to me that the call to GetRawInputData is returning invalid data or an invalid header. It's possible this data is somehow aligned improperly causing it to read the wrong bytes for the device type and size fields.

    ForwardRawInput: indicesCount: 2, rawInputDataSize: 8177, Frame: 223
    [0] Device Type: 256
    [0] Size: 8145
    [0] Device: 0
    [0] Param: 0

    [1] Device Type: Mouse
    [1] Size: 0
    [1] Device: 0
    [1] Param: 0
    Invalid raw input data size: 0 bytes
    ForwardRawInput: indicesCount: 4, rawInputDataSize: 64, Frame: 223
    [0] Device Type: Mouse
    [0] Size: 0
    [0] Device: 0
    [0] Param: 0
    [1] Device Type: Mouse
    [1] Size: 0
    [1] Device: 0
    [1] Param: 0
    [2] Device Type: Mouse
    [2] Size: 0
    [2] Device: 0
    [2] Param: 0
    [3] Device Type: Mouse
    [3] Size: 0
    [3] Device: 0
    [3] Param: 0
    Invalid raw input data size: 0 bytes
    Invalid raw input data size: 0 bytes
    Invalid raw input data size: 0 bytes
    Invalid raw input data size: 0 bytes
     
    Last edited: Feb 23, 2022
  24. montyjack

    montyjack

    Joined:
    Jan 10, 2014
    Posts:
    43
    No- there is a warning that I need to upgrade to a version compatible with unity 2020, but I've been using Unity 2020 for about a year now and this has never been a problem before.
     
  25. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,500
    If you are not using saved data, then there are only 3 other possible causes:

    1. You have not assigned these Controller Maps to be loaded in your Player on start on the Players page.
    2. You have some script unloading or loading controller maps in your Player, overriding what is being loaded by the Rewired Input Manager on Start.
    3. The Rewired Input Manager being used in testing is not the same one you are looking at and editing. If you are using a prefab, you may have local overrides in the prefab instance that conflict with the prefab parent and are not aware of the mismatch.
     
  26. montyjack

    montyjack

    Joined:
    Jan 10, 2014
    Posts:
    43
    Ah, it was #1... thanks for your help! I knew it must be a simple settings issue I was missing.
     
  27. Derakon

    Derakon

    Joined:
    Jul 3, 2019
    Posts:
    20
    I'm having an issue where my game thinks there is no active controller (i.e. GetLastActiveController returns null), when the player is using the mouse. This persists until the player either uses the keyboard or touches a button on the gamepad. As a consequence, players are getting weird behavior on my title screen.

    Is there some appropriate way to get Rewired to say "mouse movement counts as using the mouse controller"?
     
  28. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,500
    It already works like that. It's not going to return null if there is a last active controller that is still connected and has received input. Until a controller is considered active, it will always return null. If you don't want null values, don't use GetlastActiveController, use GetLastActiveControllerType.

    What you haven't said is which GetLastActiveController you are using. You're probably using the Player version, haven't assigned any Action to the mouse axes in a Controller Map, and therefore are getting no last active controller set from the mouse axes. This is because of how the Player version works. Read the documentation on this topic to understand how it works.

    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.
     
  29. Derakon

    Derakon

    Joined:
    Jul 3, 2019
    Posts:
    20
    Ahh, you're right, I've been using the player version. Thanks for the correction!
     
  30. chris_ngale

    chris_ngale

    Joined:
    Nov 4, 2019
    Posts:
    6
    Hi, I have a question before purchase.

    My game is a driving game, and I want to support Fanatec wheels. Each wheel shows up as two identically named devices ("FANATEC Wheel") in order to support the vast number of button and axis bindings any wheel can have.

    I cannot distinguish between these devices using Unity's (old) input manager, which only lists different devices by name. This means if they are picked up by Unity in a different order to when the bindings were set, the bindings will apply to the wrong device.

    Can Rewired distinguish between identically named devices, and pick up the correct device consistently?
     
  31. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,548
    (1) You can download a free trial of Rewired and test it out before purchase.

    https://guavaman.com/projects/rewired/trial.html

    A quick way to see what Rewired sees would be running the control mapper examples.

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

    NOTE: examples are found under this directory Rewired/Extras/ControlMapper folder.

    (2) I am not familiar with Fanatec wheels can you indicate the specific product version and URL to the website with more info on each wheel you are working with?

    (3) What version of Unity are you using?

    (4) What platform are you using? I am guessing windows but you did not specifically mention what operating system and version of the operating system?
     
    Last edited: Feb 25, 2022
    guavaman likes this.
  32. chris_ngale

    chris_ngale

    Joined:
    Nov 4, 2019
    Posts:
    6
    Thanks for the reply, I'm downloading the trial now.

    The specific wheelbase I am using is this: https://fanatec.com/eu-en/bundles/csl-dd-8-nm

    It's available as low and high torque versions with and without Playstation support. As the first affordable direct-drive sim wheel, it's rapidly becoming the mid-tier wheel of choice for driving simulators, and as such, aside from owning one myself, I really want to support it. I've been using the UnityFFB library (https://github.com/skaughtx0r/unity-ffb) to control the force feedback with great success, but the naming issue I mentioned above means I have to reassign the axes pretty much every time I launch Unity.

    As far as I'm aware all modern Fanatec wheels behave in the same manner. The pedals, steering axis, and buttons/paddles/any other controls on the detachable wheel rims are combined into two virtual devices.
     
  33. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,548
    That sounds really exciting since you have FFB working already.

    The docs are located here:

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

    And this will be useful also for debugging ...

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

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,500
    It depends entirely on the identifying information provided by the device.

    If both devices use exactly the same Product Name and Product Id, no, Rewired will not be able to distinguish. If they used a different Product Id for each device, it will.

    All of the advice @longroadhwy gave is very helpful and accurate.
     
  35. BeforeTheLight

    BeforeTheLight

    Joined:
    Jan 7, 2011
    Posts:
    168
    Hey I am sure this has been answered in here somewhere but I cannot find it. I have created the required actions and a joystick layout based on this page for Controller based UI interaction. I have replaced the Standalone Input Module with the Rewired one. It works but I am fighting with the standard Unity navigation system. Later in that setup guide there is this blurb "Make sure you disable UI navigation Actions in all Players that control a software pointer." but I cannot figure out from that hyperlink how to disable UI navigation actions. Is it in the Rewired Editor? If so where?

    I popped open the Example project PlayerMouseUnityUI and it works flawlessly. I then removed the Input manager from that scene and placed my input manager in there and everything works except that the UI navigation is fighting me again.

    I tried to give all the info I could compile so I can resolve this issue quickly. Thanks in advance.

    Mac
    Unity 2021.1.28f
     
  36. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,500
    Disabling UI Actions is not some kind of global switch somewhere in the Rewired configuration.

    This sentence is referring to Actions you've set up in Controller Maps for the purpose of UI navigation. There is no one way to do this. What exactly this looks like is up to your implementation.

    The documentation gives an example of setting special UI navigation Actions. These are Actions such as UIHorizontal, UIVertical, UISubmit, etc. It then shows creating a UI controller map category so UI controls can be isolated to that UI-specific Controller Map so it can be enabled and disabled easily. That sentence is telling you that if you're trying to use PlayerMouse at the same time as the UI navigation system, it will fail, and the solution is to disable the UI navigation controls when using PlayerMouse for that Player. Assuming you've set things up as the example shows, you would disable the Controller Maps in the UI map category.

    The reason the Player Mouse example works is there are no UI navigation maps set up for any of the Players and all are simply using Player Mouse for navigating the UI. The Keyboard/Controller navigation system of Unity UI is not even being used.
     
  37. BeforeTheLight

    BeforeTheLight

    Joined:
    Jan 7, 2011
    Posts:
    168
    So in the example scene what is the difference in how your guide is setup and how that manager and mouse are setup? They have UIHorizontal, UIVertical, UISubmit, etc. and from what I can tell no script is changing the controller map from default to UI or back.

    And can you define what this means? "UI navigation maps set up for any of the Players". There are navigations on the UI elements, this is evident by my input manager causing the navigation to grab the next item.

    If I do not want navigation is the simplest way to disable navigation on the event system?

    Thanks for the quick reply.
     
  38. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,500
    I think it would be helpful for you to review how the Controller Map system works in Rewired:
    https://guavaman.com/projects/rewired/docs/ControllerMaps.html

    Assigning/Loading Controller Maps:

    When you create a Controller Map (Joystick Map, Keyboard Map, etc.) in the Rewired Input Manager, you are defining a default Map that can be used by any Player. In order for a Player to make use of a Controller Map, it must first be assigned to that Player and enabled. You can assign the Controller Map in the Rewired Input Manager under the Players page, and when the game starts and Rewired initializes, it will load the map into the Player. You can also assign/load Controller Maps at runtime through scripting. See How To's - Loading Controller Maps at runtime for more information.



    Take a look at the Rewired Input Manager in the example scene. You will see, while there are UI Actions defined, 1) There are no Controller Maps defined that actually map those Actions to anything. (1st image) 2) But more importantly, there are no Controller Maps that map any elements to those UI Actions set to be loaded on start in any Player. (2nd image)

    fewafeaw2.PNG

    fewafeaw.PNG

    There are 4 things that go into determining value of an Action in Player:
    1. The Controller(s) assigned to the Player.
    2. The Controller Map(s) that binds Controller elements to Actions.
    3. If the Controller is a Joystick, the Calibration Map for that Joystick.
    4. The Input Behavior assigned to the Action.
    You can see what Controller Maps exist in the Player at runtime using Debug Information:
    https://guavaman.com/projects/rewired/docs/Troubleshooting.html#debug-information

    The Untiy Event System inspector has the toggle "Send Navigation Events". The Rewired Event System which isn't really any different than Unity's Event System also has the same option.

    Otherwise, disable the Controller Maps in the Players that map the UI Actions.

    If you plan on controlling the UI exclusively with mouse pointers, don't bother even creating UI maps. The UI Actions exist for no purpose other than Unity's UI navigation system.
     
    Last edited: Feb 26, 2022
  39. shotoutgames

    shotoutgames

    Joined:
    Dec 29, 2013
    Posts:
    283
    Any walkthrough or resource for properly using rewired with the pixel crushers dialogue system asset? Am I supposed to change or add bindings. I already have separate maps for ui and gameplay working mostly well together before installing this asset. Thanks as always!
     
  40. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,548
    I think this is what you need to look at.

    https://www.pixelcrushers.com/dialogue_system/manual2x/html/rewired.html

    @TonyLi will have more insight into this.
     
    guavaman, shotoutgames and TonyLi like this.
  41. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,531
    Thanks, @longroadhwy!

    @shotoutgames - To recap that link, import Plugins ► Pixel Crushers ► Common ► Third Party Support ► Rewired Support.unitypackage. Then add an Input Device Manager Rewired component to your Dialogue Manager GameObject. This will change all Dialogue System-specific input, such as UI Button Key Trigger components and the Selector's Use Button, to read from Rewired instead of Unity's built-in input manager.

    Note that dialogue UIs and quest log windows just use plain old Unity UI, so you should be using a Rewired Standalone Input Module just like with any other Unity UI.
     
    guavaman and shotoutgames like this.
  42. tasclew

    tasclew

    Joined:
    May 24, 2020
    Posts:
    2
    Hello! I'm trying to use a custom controller to train an ml-agent on an object which usually has player input. I managed to set it up for a single game object and it works fine.

    When I try to use it on multiple game objects however, they all share the same custom controller and move at the same time. I am initializing the custom controllers on each game object as follows:
    Code (CSharp):
    1. void Start(){
    2.         ...
    3.         _customController = ReInput.controllers.CreateCustomController(1, "TestController"+ controllerNumber);
    4.         controllerNumber++;
    5.         ...
    6. }
    It seems that changing the tag with controllerNumber doesn't actually create a different instance of the custom controller.

    So my question is, is there a way to create multiple instances of custom controllers having only defined one in the Rewire editor via code so that they work independently? Thanks!
     
  43. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,548
    @chris_ngale

    Does Rewired work for this use case with your Fanatec wheel?

    @Steve-Tack this wheel looks very interesting.
     
  44. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,500
    It already works exactly that way. Creating a new Custom Controller instance can never return the same instance as created previously using the same function. What you're describing can only be due to a problem in your code.

    1. How are you assigning these Custom Controllers to Players? Are you assigning each Controller to a different Player?
    2. How are you assigning input values to these Custom Controllers? Are you populating each controller with different values?
    3. Do not attempt to re-use the same Controller Map instance in different Players in code This can lead to a lot of problems.
     
  45. tasclew

    tasclew

    Joined:
    May 24, 2020
    Posts:
    2
    I found that it is related to point 1., that all the game objects use the same player. Thank you for pointing it out.

    Is there a way to create players on the fly instead of having to go to the Rewire editor? That would be super useful as I only want to use these for specific circumstances (train a ml-agent) and then remove them.
     
  46. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,500
    No. The system is designed around on static Actions, Players, Input Behaviors, etc., etc. that have been defined before runtime and created at start by Rewired. The entire system would have to be redesigned from the ground up to support runtime modification of that data.
     
  47. HWIvan

    HWIvan

    Joined:
    Jan 21, 2019
    Posts:
    12
    I've got a Xbox Elite Wireless Controller on macOS and I can't seem to get the D-Pad to work.

    Left stick comes through as axis 0 and 1 as expected.
    Right stick comes through as axis 10 and 11, a bit weird but at least they show up.
    But D-Pad just doesn't come through as an axis or buttons.

    The whole controller shows up as an "Unknown Controller", but even if I try to remap I just can't find the inputs for the D-Pad. I've got a debug screen showing the values of every button, axis, axis 2D and hat but the D-Pad doesn't seem to get anywhere.

    Anyone else seen this?
     
  48. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,500
    https://guavaman.com/projects/rewired/docs/SupportedControllers.html

    Xbox controllers connected via USB require a specific driver. This driver may not work anymore with current versions of MacOS.

    The only way the controller can be supported without this driver is via Bluetooth.

    If controller elements do not work through Unknown Controller, they don't exist and are not being exposed through the HID device through I/O Kit and cannot be used.
     
  49. Przemyslaw_Zaworski

    Przemyslaw_Zaworski

    Joined:
    Jun 9, 2017
    Posts:
    314
    Does Rewired fully support Steam Deck controller ? I use the newest version, Rewired 1.1.41.5.

    For Steam Deck I use PS4 layout, and it works almost good. But Steam Deck also has additional buttons on the back (L4, L5, R4, R5). And these additional buttons aren't detected in game. What should I do to enable support for buttons (L4, L5, R4, R5) ?
     
    CrowbarSka likes this.
  50. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,500
    Steam Deck is not explicitly supported.

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

    Supported Controllers:
    https://guavaman.com/projects/rewired/docs/SupportedControllers.html
    • Steam Deck is a Linux device and therefore should work like any other Linux device using the native Linux support in Rewired and the Steam Controller definition.
    • Windows games run on it use Proton, Steam's Wine fork. Any issues with Windows games on Steam Deck are due to problems with Proton as has been discussed recently in this thread.
    • Any missing buttons likely indicates those buttons are not exposed by Steam in the virtual HID device they create for the controller and likely can only be used through native Steam API function calls. Rewired does not support Steam natively through the native Steam API.
    • The PS4 Controller doesn't have these back buttons and therefore there's no reason they would be exposing these buttons for a PS4 layout. It wouldn't make sense to do so because they have no equivalent buttons on the PS4 controller and any game written to support the PS4 controller wouldn't know anything about them.
     
    Last edited: Mar 6, 2022