Search Unity

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,627
    That is one way to go about it.

    No.

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

    creat327

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

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

    guavaman

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

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

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

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

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

    Darkon_Who

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

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

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

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

    guavaman

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

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

    impbox

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

    OS: Windows 10

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

    Using Rewired 1.1.39.1

    The controller is detected as:

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

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

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

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

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

    guavaman

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

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

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

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

    impbox

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

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

    Thanks for the quick response!
     
  9. guavaman

    guavaman

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

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

    RetroVertigo2019

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

    Thanks
     
  11. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627

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

    Negative Buttons:

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

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

    RetroVertigo2019

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

    ledshok

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

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

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

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

    guavaman

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

    ledshok

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

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

    jason_yak

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

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

    guavaman

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

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

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

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

    guavaman

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

    See Updating Rewired before updating.

    1.1.39.2:

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

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

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

    jason_yak

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

    indie6

    Joined:
    Dec 15, 2012
    Posts:
    101
    Hi,

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

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

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

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

    guavaman

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

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

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

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

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

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

    jason_yak

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

    greg-harding

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

    flashframe

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

    idibil

    Joined:
    Oct 10, 2015
    Posts:
    24
    Hello,

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

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

    guavaman

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

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

    GetLastActiveController tells you the last controller the user interacted with.

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

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    @jason_yak, @flashframe, @greg-harding

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

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

    idibil

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

    CurryKitten

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

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

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

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

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

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

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

    jason_yak

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

    oldManPig

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

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

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

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

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    That wasn't clear to me from your last message that it is reporting the Xbox controller being the last controller when it is not being used. The only way I know of that this could happen is if the axes are poorly calibrated and they're producing input noise of a value greater than the dead zone. Have the user calibrate the joystick axes and set a larger dead zone. If you don't have a way for the user to calibrate joysticks, Control Mapper has this feature built in.
     
  33. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    Player.GetButtonDown is checking an Action value. The Input Behavior assigned to that Action determines the underlying axis value threshold required to trigger a button event. Button Dead Zone. If the axis value returned by this element is less than that value, player.GetButtonDown will never return true. In addition, the Unknown Controller has a dead zone of 0.1 on every axis.

    Rewired on Android is completely dependent on UnityEngine.Input for all input:
    https://guavaman.com/projects/rewired/docs/Overview.html#tested-platforms

    Therefore, Rewired is subject to how both Android and Unity chose to handle reading and exposing input values. Rewired exposes 20 axes and 20 buttons (Unity's max) mapped from the axes and buttons Unity exposes. If an element presents itself as an axis or button is out of Rewired's control.
     
  34. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    Yes. The Players that are designated control the UI are displayed in the inspector and are accessible through the property of the exact same name in the class.
    • Use All Rewired Game Players
    • Use Rewired System Player
    • Rewired Player Ids



    Code (csharp):
    1. /// <summary>
    2.         /// Allow all Rewired game Players to control the UI. This does not include the System Player. If enabled, this setting overrides individual Player Ids set in Rewired Player Ids.
    3.         /// </summary>
    4.         public bool UseAllRewiredGamePlayers {
    5.             get { return useAllRewiredGamePlayers; }
    6.             set {
    7.                 bool changed = value != useAllRewiredGamePlayers;
    8.                 useAllRewiredGamePlayers = value;
    9.                 if (changed) SetupRewiredVars();
    10.             }
    11.         }
    12.  
    13.         /// <summary>
    14.         /// Allow the Rewired System Player to control the UI.
    15.         /// </summary>
    16.         public bool UseRewiredSystemPlayer {
    17.             get { return useRewiredSystemPlayer; }
    18.             set {
    19.                 bool changed = value != useRewiredSystemPlayer;
    20.                 useRewiredSystemPlayer = value;
    21.                 if (changed) SetupRewiredVars();
    22.             }
    23.         }
    24.         /// <summary>
    25.         /// A list of Player Ids that are allowed to control the UI. If Use All Rewired Game Players = True, this list will be ignored.
    26.         /// Returns a clone of the array.
    27.         /// </summary>
    28.         public int[] RewiredPlayerIds {
    29.             get { return (int[])rewiredPlayerIds.Clone(); }
    30.             set {
    31.                 rewiredPlayerIds = (value != null ? (int[])value.Clone() : new int[0]);
    32.                 SetupRewiredVars();
    33.             }
    34.         }
    35.  
     
    oldManPig likes this.
  35. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    Branching the glyph, help text, and remapping UI code is certainly far less trouble than branching the entire input system for a platform. Anyway, I will think about this issue more and perhaps come up with something.
     
  36. idibil

    idibil

    Joined:
    Oct 10, 2015
    Posts:
    24
    Hi guavaman,
    I am using Control Mapper :)
    If the code I wrote above is correct, then I have not idea where the problem is.
    A player with Xbox Controller connected to his PC, but using Keyboard+Mouse to play the game, get messages for Xbox controller on tutorial Messages displayed by the code above.
     
  37. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    The problem is in your code.

    Code (csharp):
    1. default:
    2.     tempKey = Rewiredplayer.controllers.maps.GetFirstElementMapWithAction("Toggle Flashlight", skipDisabledMaps).elementIdentifierName;
    You are not supplying a controller type to the function, therefore it gets the first ActionElementMap that matches the query regardless of what controller it belongs to. This can also match to a Joystick Map. This code path is ignoring the result of GetLastActiveController.

    You don't need the switch statement.

    Code (csharp):
    1. tempKey = Rewiredplayer.controllers.maps.GetFirstElementMapWithAction(controller, "Toggle Flashlight", skipDisabledMaps).elementIdentifierName;
     
    Last edited: May 14, 2021
  38. oldManPig

    oldManPig

    Joined:
    Oct 25, 2019
    Posts:
    13
    That's great, and I can certainly find a workaround using that, but to clarify I was wondering if there is a way to strictly assign a newly created input module to a player at runtime?

    eg: inputModule.RewiredPlayerId = 2;

    No worries if not as I can just premake a bespoke module for each through the editor, and only activate the gameobject when needed.

     
  39. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    That's exactly the purpose of all the information I sent you. It's not a workaround. It's the only way you can do it.

    Each RewiredStandaloneInputModule has settings that determine which Players are in control of that module. Those are the settings above.

    Use All Rewired Game Players
    Use Rewired System Player
    Rewired Player Ids

    There is no one-line piece of code that will set all of this.

    1. Get the RewiredStandaloneInputModule instance in a script.
    2. Set rewiredStandaloneInputModule.UseAllRewiredGamePlayers to false.
    3. Set rewiredStandaloneInputModule.UseRewiredSystemPlayer to false.
    4. Set rewiredStandaloneInputModule.rewiredPlayerIds to an array containing the Player Ids that should control this input module. new int[] { 0 } will make Player 0 control this module.
     
    Last edited: May 15, 2021
  40. oldManPig

    oldManPig

    Joined:
    Oct 25, 2019
    Posts:
    13
    Ah Apologies Guavaman, thank you for your patience! I feel very silly that I had missed that rewiredPlayerIds could be set as simply as that.
     
  41. ohbado

    ohbado

    Joined:
    Aug 13, 2014
    Posts:
    37
    Hi.
    When using Rewired, there is a problem that the performance drops significantly when the mouse pointer is moved heavily.
    This does not happen in projects that do not have Rewired installed.
    I have captured a video, have a look.
    The video is running in the Unity editor, but the same problem occurs in Windows Standalone builds.

    https://www.dropbox.com/s/1qjrxnv7zre9ind/RewiredMouseMove.mp4?dl=0

    Unity 2020.3.8f1
    Active Input Handling: Input Manager(Old)
    OS: Windows10
    Mouse: Razer Viper Ultimate (2400dpi)

    Do you know of a good solution?
    Thank you.
     
  42. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    There is no solution because this is an unknown issue that nobody has ever reported before and I cannot reproduce it. Testing in Unity 2020 and 2021, with a Rewired Input Manager in the scene and nothing else, the CPU usage doesn't change a single bit when moving the mouse. It probably has something to do with your mouse driver, because Rewired simply receives Raw Input mouse messages from the Windows message queue and combines their values for the frame. Rewired isn't doing anything that would cause the frame rate to drop through the floor when using a mouse.

    Unity's legacy input system does not use Raw Input for the mouse and therefore would not exhibit the same problem if it is coming from some conflict between Raw Input and the mouse driver.

    If you don't want to use Raw Input, disable Native Mouse Handling:
    https://guavaman.com/projects/rewired/docs/RewiredEditor.html#Settings
     
    Last edited: May 17, 2021
    ohbado likes this.
  43. ohbado

    ohbado

    Joined:
    Aug 13, 2014
    Posts:
    37
    Thanks for the reply.
    You are right, the cause seems to be in the mouse driver.
    When I lowered the Polling Rate in the mouse driver from 1000 to 100, all the problems went away.
    Thanks.
     
  44. joanpescador

    joanpescador

    Joined:
    Dec 21, 2016
    Posts:
    122
    Hi guavaman.
    I've been looking around and haven't found any clues as to what's happening to me. Perhaps you can help me.
    I have a Logitech G29 integrated in with Rewired and it works great, but as I improve debugging the game and improve the fps, I start to losing some gears shift. From 100 fps I lose one gear shift of every 6 (more or less), and from 140 fps, the whole device continues to work perfectly but it is not possible to engage gears. I suppose it has something to do with the timing of the input system but I have not been able to find a way to adjust it better.
    Can do you bring any idea about it?
    Thanks,
    Joan
     
  45. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    There is no setting you can adjust that would affect that. That could only be caused by a very low level problem. Rewired already implements many measures to ensure button down events are cached and not missed. What platform is this and what is the primary input source chosen for this platform? Gear shifting is no different from any other button press. If it is possible to miss a shift, it would be possible to miss a rapid button press. This is not a known issue on any platform and great care has always been taken to specifically ensure button misses don't happen.

    The only scenario that I can imagine where this would be possible is if you are using Direct Input. Direct Input has no way to guarantee capture of every single button press, because Direct Input is a polling API and does not deliver an event queue. The API is polled at the rate specified in the settings. If a button press has a duration short enough where is can start and end between polling samples, it will be missed.
     
    Last edited: May 17, 2021
  46. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    Thanks for the information. I will get a high refresh rate mouse and see if I can reproduce the issue.
     
  47. jason_yak

    jason_yak

    Joined:
    Aug 25, 2016
    Posts:
    531
    Good point, yes could be some half way measure where I can swizzle things to work. But will keep an eye out to see if you do end up coming up with some sort of solution for this down the line. Thanks!
     
  48. idibil

    idibil

    Joined:
    Oct 10, 2015
    Posts:
    24
    Thanks guavaman. I will check that out!
     
  49. joanpescador

    joanpescador

    Joined:
    Dec 21, 2016
    Posts:
    122
    Many thanks for the reply.
    Checking the type of input I use, I have seen the "rewired loop" option in the "rewired editor". I have enabled the "fixed update" option and the problem has been solved. No single one missing shift in any fps range.
    Thanks for the clue.
     
  50. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    Then you are calling GetButtonDown in the Fixed Update loop? You cannot use Rewired in Fixed Update without it being told to calculate frame data for Fixed Update which is what enabling it in the Update Loop setting does. Otherwise, frame data is only calculated for Update.