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,624
    How would this aggregator class handle saving controller mappings for potentially unlimited different controllers that might be connected to the system at different times? The reason the PlayerPrefs implementation saves everything by key is so the user can connect any device they want and save/load information about it without overwriting data saved for other devices. It's more akin to a database of all user configuration than a snapshot of the current state of the Player and controllers.
     
    Last edited: Jan 28, 2022
  2. InvincibleCat

    InvincibleCat

    Joined:
    Dec 23, 2014
    Posts:
    83
    Hi there, It might already have been asked but there are like 158 pages haha.

    I am creating a PC game and I am currently working on rebinding controls.
    The idea is that I would like all the joysticks to have the same map.
    Basically I would only create the Gamepad template.

    So for example, if I rebind the Jump action to the Circle button on the PlayStation controller I would like the Xbox One controller to also be impacted by it and therefor use the B button to Jump.
    Is that possible? I couldn't find a way to do so.
    When I get the controller, even if I didn't specified a specific map for it, it automatically create a PlayStation or Xbox One specific map but I would like to only have the Gamepad Template one (same when it comes to recognize the buttons glyph btw).

    Thanks in advance.
    Cheers!
    -Tim
     
  3. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,624
    It's in the documentation:
    https://guavaman.com/projects/rewir...ving-and-loading-controller-template-mappings
     
  4. InvincibleCat

    InvincibleCat

    Joined:
    Dec 23, 2014
    Posts:
    83
    Thanks for the very quick reply and sorry I missed that from the documentation :(

    I have another question... I have a CheckElement method on the gamepad. Basically what I wanted to is to check if the binding would have a sprite I could show or not. If it doesn't I don't want to allow the element.
    I have the ControllerPollingInfo pInfo and I have the elementId but it is the element Id from the controller specific hardware and not the template. Is there a way to convert that as well so I could get the proper elementId.

    I know there is a method to display the controller template glyphs and that works but from the Check method I can find a good way to do so. If not I guess I can always use a sort of hacky way by binding the buttons I don't want to support to a map that will be protected.
     
  5. Nefisto

    Nefisto

    Joined:
    Sep 17, 2014
    Posts:
    333
    Hi, I'm working on a rebinding system and using a gamepad template to assign actions to buttons. When I try to remap things I'm doing this

    Code (CSharp):
    1. var currentMap = input.controllers.maps.GetMap(controllerType, controllerID, 0, 0);
    The problem is, every time that I connect a different joystick (or the same joystick with a different connection type, e.g. cable and then Bluetooth), rewired returns a different controller ID that makes sense, but this makes the code above return a new map. How can I solve this? The auto-assign is enabled at moment
     
  6. AHAKuo

    AHAKuo

    Joined:
    Apr 15, 2019
    Posts:
    5
    Hello there! I'm facing a weird problem that I'm trying to fix

    This is a single-player game by the way.

    My game works fine using a joystick, and when a joystick is connected, it automatically implements the first template which contains three map categories (Gameplay, UI, Pause), and they work fine. However, when I connect another controller, it doesn't seem to implement the Gameplay category. I don't know why. It simply implements the UI and Pause only.

    And when I disconnect the first controller and leave the second plugged in, it still does not implement Gameplay.

    This makes it impossible to change the active controller mid-gameplay.

    Here's an image to explain what I mean better:

    upload_2022-2-4_0-13-13.png

    When the first joystick is disconnected:

    upload_2022-2-4_0-14-6.png

    It doesn't have "Gameplay" like the first controller. This happens vice versa as well. If the sony dualshock controller was connected first, it will have all 3 categories. But the Xinput will have only UI and Pause.

    This seems to only happen to the second controller that is connected.

    P.S.:

    The only difference between the Gameplay, UI and Pause is that Gameplay is user-assignable. But I'm not sure if that is the problem.

    Thank you in advance. Any help on this would be appreciated.
     

    Attached Files:

  7. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,624
    What are you hoping to solve? It has to return a different Controller Map when a new controller is connected. There is no way possible for you to keep a static Controller Map that will work with and apply to any controller that is connected. Controller Maps are created when they are loaded in the Player. Controller Maps are loaded in the Player at the time the Controller is assigned to the Player. When a Controller Map is "loaded", it is nothing more than the Controller Map object being instantiated with specific data defined in the Rewired Input Manager. When you instantiate an object, a new instance is created. This instance is the Controller Map returned by player.controllers.maps.GetMap.
     
  8. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,624
    I'm not understanding what you are trying to do. You're trying to prevent the user from binding any controller elements that don't have a Gamepad Template element sprite? That sounds like a very odd thing to do in my opinion. I don't see any purpose. If you are limiting everything to Gamepad Templates only, by definition, you cannot support any controller that isn't recognized by Rewired and mapped to the Gamepad Template. Your users will be unable to use a huge variety of controllers out there, including probably hundreds of off-brand gamepads, including nearly all of the vintage console style gamepads. See this:
    https://guavaman.com/projects/rewired/docs/FAQ.html#addding-controller-definitions

    If that's what you're doing, then you might as well just simply prevent the users from even assigning and using non Gamepad Template controllers. Write a script to unassign them if assigned to Players if they don't implement IGamepadTemplate.

    The code you are referring to that shows you how to show glyphs for the Template instead of the Controller contains all the function calls required to get the Template element information from the Controller element information. If you want to implement something of your own that requires the same functionality, look at the example and get the function calls you need to display the information you want.

    https://guavaman.com/projects/rewired/docs/HowTos.html#display-glyph-for-action-template-specific

    There is also a complete working UI example included with Rewired:

    https://guavaman.com/projects/rewired/docs/Examples.html#gamepad-template-ui

    If what you are asking is how to get the Controller Template element without having an Action Element Map to pass to it, the function used to get this information in all the examples actually takes a Controller Element Target, which is dynamically created from the Action Element Map when you pass it instead:

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

    Controller Element Target is a struct. Without having an Action Element Map to create it, you have to set the Element and the Axis Range:
    https://guavaman.com/projects/rewired/docs/api-reference/html/T_Rewired_ControllerElementTarget.htm
     
    Last edited: Feb 4, 2022
  9. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,624
    Inexplicable problems like this are nearly always caused by one of the following:
    1. You have some script modifying what Controller Maps are being loaded and are not aware of what it is doing. (This could also apply to bugs in usage of Layout Manager.)
    2. You are loading outdated saved data because you are using UserDataStore_PlayerPrefs:
      https://guavaman.com/projects/rewired/docs/UserDataStore.html#saved-xml-not-synced
    #2 is by far the most common and likely reason.
    There is nothing else I can think of at the moment that could cause what you are describing.
     
  10. Nefisto

    Nefisto

    Joined:
    Sep 17, 2014
    Posts:
    333
    My problem atm is that when I connect a new controller the rebinding made on previous controller assigned to the same player is lost, what makes sense as each one is a unique instance.

    Im initially thinking that I could create a common map to use between joysticks, but I think that I misundertood things here. So if I want to share the same configuration should I save and load configurations between controller map instances?
     
  11. AHAKuo

    AHAKuo

    Joined:
    Apr 15, 2019
    Posts:
    5

    You were right! Thank you.

    It turned out that my control re-binding screen was only assigning the loaded maps to controller index 0. I had to make it a for loop that runs through the current count of joysticks to make sure they are added to every connected joystick.

    Thanks a lot for the hint :D
     
  12. fallthem000

    fallthem000

    Joined:
    Dec 12, 2015
    Posts:
    5
    So was trying different controller configuration layouts when testing my game on the steam deck and found that if any of the joysticks or touchpads had a Mouse/Mouse Region behavior and I used them while also pressing/moving anything else (regardless of the button behavior) the game would crash, it was pretty consistent (sometimes it took more input interaction before crashing but it always did).

    Managed to fix it by checking by code rewired manager "Disable Native Input" (or bool called alwaysUseUnityInput), not sure if it's related to how we're handling input in my game but thought I'll leave it here in case it helps anyone.
     

    Attached Files:

  13. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,624
    You should report this to Valve.

    Fixing this issue by using "Disable Native Input" isn't really a fix. That makes Rewired fall completely back to UnityEngine.Input for all input. This has massive implications on device support, device feature support, and robustness.

    It cannot be ruled in that this is a problem in Rewired just by your symptoms. Unity and Rewired use different input APIs. It could easily be a problem in Steam's implementation of one API vs the other causing this.

    I see from your stack trace that Wine is also involved here which is a whole other layer of complexity that Steam is responsible for. That means it's a Windows application running in Linux and all of the Windows input functionality is being emulated by Wine. Steam has their own version of Wine which supports more features such as Raw Input (which I helped them debug when they implemented it to support Rewired). This could easily be where the problem lies. This crash has never been reported outside your specific case of using the Steam Deck, so I would very strongly suspect the cause of issue is on Steam's side rather than Rewired's.

    From the stack trace:

    0x6ED79C4F (user32) EnumPropsW
    0x6ED7A7CC (user32) GetRawInputBuffer

    The crash happened in the Windows API EnumPropsW function which was apparently called by the Windows API GetRawInputBuffer function. Rewired calls GetRawInputBuffer to get the Raw Input events from the Windows event queue. The implementation of GetRawInputBuffer in this case is in the Wine code emulating windows. At the time Valve modified their Wine fork to include support for Raw Input, Rewired used only the GetRawInput function, not GetRawInputBuffer, so I have no idea if they ever tested or implemented GetRawInputBuffer. Rewired was forced to change from using GetRawInput to GetRawInputBuffer when Unity switched to using GetRawInputBuffer for mouse input in Unity 2021.2 in order to stop massive frame rate drops caused by using an 8 KHz mouse. (An 8 KHz mouse can generate hundreds of input events per frame, and because GetRawInput causes a mutex lock, it's incredibly slow when called hundreds of times per frame. GetRawInputBuffer is a function which retrieves a buffer full of events at once, reducing the number of internal mutex locks.) Because GetRawInputBuffer removes all the messages retrieved from the event queue when called, because Unity started using that function, it broke Rewired's ability to read mouse input. By changing Rewired to use the same function, it is able to grab all the mouse events before Unity, process them, and then Unity added an API so Rewired could pass these events on to Unity afterwards so its input system could function at the same time.
     
    Last edited: Feb 5, 2022
  14. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,624
    Yes.

    If you look how the User Data Store system is implemented in the UserDataStore_PlayerPrefs and in all the scripts that use it, saved user mappings are loaded whenever a controller is assigned to a Player. If you have saved data, it's loaded from the saved data. If not, it's loaded from the default data defined in the Rewired Input Manager.

    The documentation on saving data for the Gamepad Template shows converting the controller-specific data to Gamepad Template data before saving. When loading, the data is converted from the Gamepad Template format to the specific controller its being loaded into.

    If your purpose is to make all gamepads share the same user configuration, you have to save the data when changed and load the data when the controller is re-connected. The most straightforward way would be to make your own implementation of UserDataStore based on UserDataStore_PlayerPrefs, doing the Template data conversion there before it's saved and before it's loaded into the Player.
     
    Nefisto likes this.
  15. NikMikk

    NikMikk

    Joined:
    Nov 4, 2015
    Posts:
    25
    Hi!

    I'm having a problem where certain controllers won't vibrate cause they don't implement the "IControllerVibrator" interface, like Xbox360 controllers.

    I want to vibrate the last used controller, works wonders when playing on a PC with a PS5 controller, but if I change to my Xbox360 controller, it does not vibrate. However, when I use the RewiredPlayer instance directly(player.SetVibration) it works on the Xbox360 controller??

    Xbox360 controllers returns a null interface in the following code:
    Code (CSharp):
    1. var lastActiveController = rewiredPlayer.controllers.GetLastActiveController();
    2. var activeControllerVibration = lastActiveController.GetExtension<Rewired.Interfaces.IControllerVibrator>();
    3. if (activeControllerVibration != null)
    4. {
    5.     activeControllerVibration.SetVibration(0, finalVibrationValueLeft, 0.1f);
    6.     activeControllerVibration.SetVibration(1, finalVibrationValueRight, 0.1f);
    7. }
    I would really like to just vibrate the controller that is currently used instead of all connected controllers.
     
  16. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,624
    See the documentation on Controller vibration:
    https://guavaman.com/projects/rewired/docs/HowTos.html#Vibration-Rumble

    To set vibration in the Joystick(s), just get them from the Player class and set the motor levels on each of them.

    Code (csharp):
    1. // Set vibration by motor type
    2. foreach(Joystick j in player.controllers.Joysticks) {
    3.    if(!j.supportsVibration) continue;
    4.    j.SetVibration(leftMotorValue, rightMotorValue);
    5. }
    6.  
    7. // Set vibration by motor index
    8. foreach(Joystick j in player.controllers.Joysticks) {
    9.    if(!j.supportsVibration) continue;
    10.    if(j.vibrationMotorCount > 0) j.SetVibration(0, leftMotorValue);
    11.    if(j.vibrationMotorCount > 1) j.SetVibration(1, rightMotorValue);
    12. }
    13.  
    14. // Set vibration for a certain duration
    15. foreach(Joystick j in player.controllers.Joysticks) {
    16.    if(!j.supportsVibration) continue;
    17.    if(j.vibrationMotorCount > 0) j.SetVibration(0, leftMotorValue, 1.0f); // 1 second duration
    18. }
    19.  
    20. // Stop vibration
    21. foreach(Joystick j in player.controllers.Joysticks) {
    22.    j.StopVibration();
    23. }
    You do not need to be using IControllerVibrator or accessing the Controller Extension. Not all controllers have a Controller Extension.
     
  17. asqewfcq2egf

    asqewfcq2egf

    Joined:
    Nov 16, 2018
    Posts:
    15
    Hi, is it possible to call Rewired's update 'manually' at an arbitrary point within the playerloop?
     
  18. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,624
    No it's not. It can only be called in Update, FixedUpdate, and/or OnGUI.
     
    asqewfcq2egf likes this.
  19. Luchunpen_0

    Luchunpen_0

    Joined:
    Aug 7, 2014
    Posts:
    58
    Hi ! Have a question.

    Does the demo support android build ? I'm trying to test gamepad on android and have no actions.
    Test scene name "GamepadTemplateUI".
    Windows build with this scene works perfectly.

    Thanks.
     
    Last edited: Feb 9, 2022
  20. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,624
    Yes it does. It is a 100% fully-functional trial. It has every single feature the full version does.

    The documentation covers how to debug why "input doesn't work":
    https://guavaman.com/projects/rewired/docs/Troubleshooting.html#controller-doesnt-work
    https://guavaman.com/projects/rewired/docs/Troubleshooting.html#joystick-problems
    https://guavaman.com/projects/rewired/docs/Troubleshooting.html#debug-information
    https://guavaman.com/projects/rewir...l#debug-information-diagnosing-input-problems
     
  21. Luchunpen_0

    Luchunpen_0

    Joined:
    Aug 7, 2014
    Posts:
    58
    Thanks for reply.
    The problem was in Auto-assign joystick -> max joystic per player. Default value was equals [1], I set value [10] and it start working.
     

    Attached Files:

    • 123.png
      123.png
      File size:
      33.3 KB
      Views:
      259
  22. ObsidianSpire

    ObsidianSpire

    Joined:
    Sep 13, 2013
    Posts:
    48
    Hi, I was curious if Rumble Gamepad F510 or the Logitech Rumble Gamepad F510 has a joystick map template? I didn't see one while looking for it but I can still use it in-game so maybe it is named differently or treated as an Xbox 360 controller or something.
     
  23. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,624
    The list of all explicitly supported controllers is here:
    https://guavaman.com/projects/rewired/docs/SupportedControllers.html

    Logitech F510 is not on the list and therefore does not have a controller definition.

    From the docs:

    All other controllers not listed above
    Any controller which does not have a hardware definition will be usable only through user mapping or by mapping actions to numbered axes and buttons in the Unknown Controller map. These unrecognized controllers can only be supported if you provide your users a way to remap their controls, such as by using the included Control Mapper or by creating a custom control remapping screen. If you do not provide users with a way to map their controls, only the above listed recognized controllers will be usable. If you do provide your users a way to map their controls, virtually any controller will be usable.

    You can also create your own controller definitions to add extended support for more controllers, but the process can be involved, especially if you want to support all platforms. (See Creating new controller definitions for more information.) However, be advised that not all controllers are candidates for controller recognition. (See Can I add support for this controller? for more information.)

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

    If the Logitech F510 has an XInput connection mode like the F310 and F710, in that mode it will be treated like any other XInput compatible device on Windows if Use XInput is enabled:

    https://guavaman.com/projects/rewired/docs/ControllerMaps.html#xinput-devices-windows
     
  24. Barliesque

    Barliesque

    Joined:
    Jan 12, 2014
    Posts:
    128
    @guavaman I'm migrating a project to Unity 2021.2, using the latest release of Rewired. In the editor at runtime, I get a NotImplementedException thrown repeatedly. I'm guessing there's a mistake in the compiler directives in the following code, and that the throw statement can be safely commented out.

    Code (CSharp):
    1. #if UNITY_2021_1_OR_NEWER
    2.  
    3. #if (UNITY_STANDALONE_WIN && !UNITY_EDITOR) || (UNITY_EDITOR_WIN)
    4.  
    5.         public void WindowsStandalone_ForwardRawInput(System.IntPtr rawInputHeaderIndices, System.IntPtr rawInputDataIndices, uint indicesCount, System.IntPtr rawInputData, uint rawInputDataSize) {
    6. #if UNITY_2021_3_OR_NEWER
    7.             Rewired.Internal.Windows.Functions.ForwardRawInput(rawInputHeaderIndices, rawInputDataIndices, indicesCount, rawInputData, rawInputDataSize);
    8. #else
    9.             throw new System.NotImplementedException();
    10. #endif
    11.         }
    12.  
    13. #else
    14.         public void WindowsStandalone_ForwardRawInput(System.IntPtr rawInputHeaderIndices, System.IntPtr rawInputDataIndices, uint indicesCount, System.IntPtr rawInputData, uint rawInputDataSize) {}
    15. #endif
    16.  
    17. #endif
    18.  
     
  25. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,624
    I am completely baffled. The code you are showing me does not exist in Rewired. After searching through the files, I've determined you're showing me code from ExternalTools.cs (this information would have been nice to have up front because I was initially searching code related to Forward Raw Input functions in the Platofrms/WindowsStandalone/Functions.cs which is also part of this functionality). But what you're showing me does not match Rewired's code in any current branch of Rewired 1.1.41.5, which is the latest version of Rewired that you state you are using. (I suggest you verify that because you're likely not using the latest version. Window -> Rewired -> Help -> About.)

    The line #if UNITY_2021_3_OR_NEWER is extremely baffling because that is a non-existent version of Unity. This branching was done for Unity 2021.2, not 2021.3. I have no idea where this code came from, but all I can think of is it's from some older release of Rewired before all the details of this forward Raw Input change were completely worked out.

    I suggest you update Rewired.
     
  26. Barliesque

    Barliesque

    Joined:
    Jan 12, 2014
    Posts:
    128
    Firstly, apologies for neglecting to note the filename.

    I checked the Release Notes file, which said version 1.1.41.5, the last change relating to Text Mesh Pro and Control Mapper. Nonetheless, I deleted Rewired completely and reinstalled. ...Voilá! That branch now says
    UNITY_2021_2_OR_NEWER

    I've heard that the Package Manager could sometimes fail to replace some files. Maybe that's what happened here?
     
  27. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,624
    I don't know. That's really not good if it's capable of doing only a partial update of files. That could cause a virtually unlimited number of inexplicable, impossible to understand and difficult to track down problems.
     
  28. Zylex

    Zylex

    Joined:
    Nov 25, 2008
    Posts:
    238
    What is the current status of official Playstation 5 support? Currently we still have no controller vibration and nice support of PS5 controllers. I could not find it in the release notes or this thread.
     
  29. Nefisto

    Nefisto

    Joined:
    Sep 17, 2014
    Posts:
    333
    Can I remove those warnings when using the default UserDataStore?

    upload_2022-2-11_14-6-47.png


    **EDIT:** Another question, I'm going to implement primary/secondary keys, and want to know which is a good way to approach it in your system, initially I thought in use different categories, but if I understood it right different categories will result in different map controllers and is not possible (imk) to have multiple map controllers assigned at the same time, so this probably isn't the best option. Can you gimme some directions here?
     
    Last edited: Feb 11, 2022
  30. Nefisto

    Nefisto

    Joined:
    Sep 17, 2014
    Posts:
    333
    Another question, I doubt that this has something to do with rewired, but maybe you can gimme some direction. When using a PS4 controller the navigation start to go up and sometimes down, I thought that maybe this has something to do with the right stick deadzone, but if this was the case the right stick would be selected as the new key.

    Also, I tried this with 3 unique ps4 controllers, by cable, and by Bluetooth AND this happens ONLY with the PS joystick, I tried with X1 and a no-brand Xbox-like joystick and this problem does not happen. Did you have some clue about what is causing this?

    capture.gif
     
  31. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,624
    I haven't made any announcements about PS5 support, which is why there is no information in the documentation and it's not listed as one of the supported platforms. It has been an extremely long process getting approved for PS5 development. I don't have any ETA on when official support will be available.

    The only "official" means of supporting the platform at present is through the use of Custom Controllers:
    https://guavaman.com/projects/rewired/docs/CustomControllers.html
     
  32. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,624
    No.

    I'm not understanding your question or your statements.

    As best I can understand, you're asking if multiple Controller Maps can exist at the same time in a Player for a single controller. Yes they can.

    As for primary/secondary keys, there is no reason to use multiple Map Categories and multiple Controller Maps to do that. All the remapping examples included in Rewired (including Control Mapper) show allowing multiple bindings per Action. There's nothing to it. If you want Button A bound to Jump and Button B bound to Jump, make two ActionElementMaps, one that binds Button A to Jump and one that binds Button B to Jump.
     
  33. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,624
    I don't know what is the source of what you're seeing. I suggest you use Debug Information and found out exactly what his happening:
    https://guavaman.com/projects/rewired/docs/Troubleshooting.html#debug-information
    • Look at the raw and calibrated values of the joystick axis itself in the Controller. This would make it obvious if it's a dead zone issue or not.
    • Look at the value of the Action that is driving the UI in the Player
    • Look at the Controller Maps for all controllers in all Players that are set to control the UI and see if something else is mapping the UI Action. It's very possible something else is mapped to this same Action that you aren't aware of that is contributing input to it.
     
  34. Nefisto

    Nefisto

    Joined:
    Sep 17, 2014
    Posts:
    333
    I know that I can simply add multiple keys to some action, but this is not so simple when I have separated menus for primary/secondary entry. Because if I just search for elements that are bound to an action and drew then, how could I know which one is the primary and which one is the second? If I decide it using the order that they appear on rewired, as soon as I change the element that is being treated as primary the secondary will be the new primary, and this is a little weird. So I thought that maybe I could use some kind of built-in approach to separate the primary from the secondary key in a "more" proper way. Does it make sense?

    Some examples.
    a)
    capture.gif

    b)
    capture2.gif
     
  35. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,624
    I see. Well there is nothing in Rewired designed to handle that use case, so you will have to manage it however you see fit. Separate Controller Maps as you've stated are the only thing in Rewired that would help in any way. Otherwise, you'd have to track primary and secondary actions outside Rewired by keeping track of what index each binding would have.

    Creating separate primary and secondary Actions is also a possibility, but clunky.
     
    Nefisto likes this.
  36. AndyNeoman

    AndyNeoman

    Joined:
    Sep 28, 2014
    Posts:
    938
    Hey Guavaman, I hope you are well, I wonder if its's possible if I request a feature?

    In the player mouse component I would like to have the option to limit the area to a circle.
    At the moment I set the movement area to a square the size of the circle I want and clamp the position in the code, but when the controller stick is held diagonally it jitters a lot.
     
  37. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,624
    That's not a feature I plan on adding. Everyone may have their own specific shapes they want to fix the mouse movement to. That was never the intention of the class to provide that kind of functionality. This is a feature that should be implemented in your code on your end modifying the Player Mouse position. The problems you're experiencing with jittering at joystick corners will be just the same for me trying to implement this internally as you implementing it externally. Whatever solution exits for it, it would be exactly the same whether the code existed on the Rewired end or in your script.

    If the jitter has something to do with the order of your modifying the position and the script consuming it (the Input Module if using Unity UI), you will have to set script execution order so the script that is modifying the value runs before the scripts that are consuming the value.
     
    Last edited: Feb 13, 2022
  38. gewl

    gewl

    Joined:
    May 19, 2016
    Posts:
    95
    I just set up Rewired to use my 3Dconnexion Space Mouse for scene navigation in Edit Mode. The navigation is working great when I have "Allow Input in Editor Scene Views" checked and a Scene view focused, but I'd like for it to work when I have the Unity editor focused regardless of which specific tab is focused. Is it possible for me to set this up?
     
  39. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,624
    See "Ignore Input When App Not In Focus":
    https://guavaman.com/projects/rewired/docs/RewiredEditor.html#Settings
     
    AndyNeoman and gewl like this.
  40. gewl

    gewl

    Joined:
    May 19, 2016
    Posts:
    95
    Okay, thanks, that's an improvement!

    If it wouldn't be too much trouble, it might be nice if platform settings for "Editor" were exposed with the others, at least for this setting, since I don't want my built application receiving input when it isn't focused (and am absolutely going to forget to turn it off once in a while).
     
  41. gewl

    gewl

    Joined:
    May 19, 2016
    Posts:
    95
    I'm getting a weird one now. Sometimes when I release my 3d connexion mouse, Rewired will keep displaying the same values it had at the time of release—the debug information shows that all the axes are 'frozen', so it'll keep translating or rotating at the same rate until I jostle the mouse again (which seems to force an update). The debug info will also show that the mouse is continually active until I jostle it.

    It doesn't seem to be a problem with the mouse, since it doesn't keep showing that it's getting input outside of Rewired/Unity.

    The problem doesn't extend to other sources of input—if the 3d mouse's axes are 'stuck' and I left-click with my primary mouse, Rewired's debug info will reflect the left-click without updating the 3d mouse's axes.

    I can't really get repro on it, unfortunately—it sometimes happens just navigating the Scene camera, but it does seem to happen a little more if I'm switching editor tabs or doing something else that might cause a little CPU hitch or something.

    Couldn't find anything about this in the docs. Is there a way to force Rewired to double-check the mouse's axes?
     
  42. FreedTerror

    FreedTerror

    Joined:
    May 19, 2017
    Posts:
    17
    Hi, I'm trying to change some colors on the custom button component via script but, I can't seem to access the component. Any advice?
    Screenshot_8.png
     
  43. Nefisto

    Nefisto

    Joined:
    Sep 17, 2014
    Posts:
    333
    Another problem, I'm using the data store to save/load and reflect changes on a rebinding system to all gamepad templates, BUT for some reason when I connect an X360 this is recognized as XInput AND don't load my saved info. I'm basically calling the saving and load on connect/disconnect events.
     
  44. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,624
    This isn't a feature I'm inclined to add. Play in Edit mode is very flaky as you have seen and may be dropped in the future.

    If you want to enable or disable it differently for edit or runtime, disable it through a script using the public configuration property:

    https://guavaman.com/projects/rewired/docs/HowTos.html#changing-configuration-settings-at-runtime

    https://guavaman.com/projects/rewir...ConfigHelper_ignoreInputWhenAppNotInFocus.htm
     
  45. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,624
    No, you can't force Rewired to check mouse axes. That's not even how Raw Input works. Raw Input is an event-based system, not a polling-based system.

    There are no code differences at all in the part that update input or action values when it comes to running at edit time or runtime. Therefore, any weirdness you're experiencing almost certainly has to do with the nature of how Run in Edit mode works. This is documented here:

    https://guavaman.com/projects/rewired/docs/InputManager.html#run-in-edit-mode

    The important parts:

    Rewired does not update in the standard Unity Update, FixedUpdate, OnGUI loops in Edit mode because Unity does not execute these loops every frame when outside Play mode. Because of this, Rewired only runs in a special Editor update loop when in Edit mode. This has some important side effects:
    • Unity's Time class cannot be used when processing input. For example, if you need to multiply a value by Time.deltaTime, it will always return 0. Instead, you must use ReInput.time.unscaledDeltaTime.
    • When writing scripts, it's recommended you use the input events method to get input as opposed to polling in Update because the Update loop will not be executed every frame by Unity.
    • Rewired will never run in FixedUpdate in Edit mode. If using input events, only subscribe to events in the Update loop.
    • If you want to poll for input, do so from the EditorApplication.update callback.
    ------------------

    Even if Rewired receives the zero value event from Raw Input, it cannot process it until the editor Update executes. I can think of no other explanation as to why this would work differently in Edit mode vs Play mode. There is no true equivalent of Update available in the editor when outside of Play mode that I am aware of.
     
    Last edited: Feb 14, 2022
  46. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,624
    A whole lot more context would be helpful.
     
  47. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,624
    There's nothing special about XInput devices vs any other controllers in this regard. All XInput devices on Windows when use XInput enabled are recognized as XInput device and not the specific device type, but that would have no bearing on loading a Template map and converting it back to the device-specific map.

    The only way you're going to be able to solve this is to debug it and see exactly what data it's loading, whether that data is being sent to the Player, and the result of receiving that data on the Controller Maps. There are almost infinite things that could be causing it and I don't have access to your code or project, so I can't point you to anything specific and can only make guesses.
    • Log the data string that's being loaded. Does it look correct?
    • Log the bindings in the Controller Map after its been converted from the Gamepad Template map to the XInput controller map. Does it look correct?
    • Log the Controller Maps in the Player immediately after you add the data to the Player and verify it so you know some other script isn't changing the data after the fact.
     
  48. gewl

    gewl

    Joined:
    May 19, 2016
    Posts:
    95
    Thanks for the reply, that's helpful.

    I read the documentation when I was putting the controller together, and I'm currently polling for input from the EditorApplication.update callback—each time the callback is called, my scene view controller reads axes from Rewired afresh, and then applies the transform/rotation. I took the warning about the Update loop to mean that the Update method in [ExecuteAlways] classes was unreliable, but that EditorApplication.update was consistent.

    Since the transform/rotation is 'correctly' updating every frame with the values it reads from Rewired (via Player.GetAxis)—meaning the scene view camera is being moved as one would expect given values it reads from Rewired—and since Rewired's debug information is showing inaccurate activity for the mouse, it seems like the problem is taking place independent of anything my script is actually doing. Am I right to assume that nothing I do in my wrapper around Rewired should influence what Rewired itself is grabbing from the input axes?
     
  49. FreedTerror

    FreedTerror

    Joined:
    May 19, 2017
    Posts:
    17
    I'm trying to modify custom button's normal color in the Popup Window via script. Screenshot_1.png
     
  50. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,624
    Based on these two messages, now I understand. You were showing me an image of intellisense showing you that there was no class named CustomButton. That was not obvious from the clipping you sent. And you are trying to edit something in Control Mapper, which is an optional extra included with Rewired.

    CustomButton is not in the global namespace or the Rewired namespace. Open the CustomButton script to see what namespace it's in and include that namespace or type the fully-qualified name including namespace in Visual Studio.

    The fully-qualified name is:
    Rewired.UI.ControlMapper.CustomButton
     
    FreedTerror likes this.