Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Rewired - Advanced Input for Unity

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

  1. neapolitanstudios

    neapolitanstudios

    Joined:
    Feb 17, 2011
    Posts:
    75
    Sorry, I think there may be a misunderstanding - probably my bad explanation. I believe I am creating as you said - multiple independent UI panels. One for each player (see screenshot). I have the functionality working thanks to your documentation, using multiple RewiredEventSystems with specific PlayerIds.

    It's the hover/selection events that aren't working, and I understand that it's a Unity problem based on your response/documentation. I need to create my own feedbacks. I guess my question is if it is possible to access which gameobject is selected by a player through the Rewired Standalone Input Module/Rewired Event System? I have had no luck looking through the API.
     

    Attached Files:

    • UI.png
      UI.png
      File size:
      170.3 KB
      Views:
      21
  2. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,644
    There should not be any problem with highlighting or selection when using independent UIs. Something has to be set up incorrectly.

    In a proper setup independent UI setup, each UI object group has its own Event System and its own Rewired Standalone Input Module. Each Rewired Standalone Input Module has been configured to only take input from a specific Player. This means that Player Mouse has to be setup for every Player in their own Rewired Standalone Input Module, and ensuring that only one Player's Player Mouse has Use Hardware Pointer Position enabled (if any). You will also need to region lock each Player Mouse so it is unable to move out of its UI so it cannot interact with UI elements of other Players. If you are using keyboard/joystick navigation, it's much simpler. Just specify fixed navigation targets for each direction in the Selectables and don't use auto navigation. The UI's must be totally independent. In a setup like this, it is only possible for a single Event System to send messages to each Selectable, so there can by definition be no competing UI events sent to a Selectable.

    The only way there could be highlighting problems in a setup like this would be, if you are allowing Players to move their mouse cursors anywhere on the screen, enabling them to hover over UI elements that they cannot control, or in the case of keyboard/joystick navigation, if you are using auto navigation. If you need to support allowing Player Mouse to move anywhere on the screen, you will have to extend the Selectable UI objects and monitor the Player Id of the Rewired.Integration.UnityUI.PlayerPointerEventData sent to the Selectable in the UI events and ignore events from a non-owning Player id.

    "Always Update" must also be enabled on all Rewired Event Systems, and any other Unity Event systems that may exist in the scene need to be disabled/deleted. Touch input should also be disabled in each Rewired Standalone Input Module.

    This is not an issue with independent UIs and independent Event Systems when properly configured. That's the purpose of having multiple Event Systems. Each Event System can only track one single currently selected GameObject because Unity originally designed the system for a single user. With 4 Event Systems, 4 separate objects can be selected with no changes required to the Selectables. If this is not happening, then something is not setup correctly. Most likely, either "Always Update" is not enabled on every Rewired Event System, or you have another Event System in the scene that you are not aware of causing problems.

    Unity's Event System is a singleton, so only one can function in a scene. The "Always Update" changes the behavior so each Rewired Event System takes over as the singleton briefly when Update runs on the MonoBehaviour. This is mirroring how Unity handled the same issue with their Multiplayer Event System component. Each Event System takes a turn every frame to update the attached Input Modules and process user input. If "Always Update" is disabled, the Rewired Event System just acts as a normal Event System and will update but the EventSystem.current singleton instance value will not be changed to match the currently updating EventSystem resulting in the one EventSystem assigned to EventSystem.current receiving all input events from all Input Modules. The same EventSystem.currentSelectedGameObject will overwritten every Player as you try to change selection. The same is true for any Unity Event Systems that may exist in the scene. In both cases, you will have problems.
     
    Last edited: Mar 16, 2024
  3. andrewtha

    andrewtha

    Joined:
    Apr 28, 2013
    Posts:
    5
    Just wondering if anyone has experienced the same issue as me.

    When using Rewired and Unity UI - everything is fine with mouse/keyboard and PS5 controllers.

    When switching to and Xbox controller, every UI object (when using a face button) seems to trigger multiple times. If I select a toggle box, it turns on and off multiple times quickly, same goes with using buttons.

    Trying to find a solution to this, and not sure if there is something simple.

    Would love some help if anyone knows how!
     
  4. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,644
    Please provide the following information:
    1. Rewired version
    2. Unity version
    3. Platform which is exhibiting this issue
    4. Primary input source in use
    5. Optional secondary input sources in use
    6. Controller connection method
     
  5. Simonlite

    Simonlite

    Joined:
    Oct 1, 2021
    Posts:
    12
    Hey again!

    Theses are the values I get from the Value Raw:

    upload_2024-3-19_21-34-0.png

    Here are the Input options I have: upload_2024-3-19_21-41-31.png

    I hope this gives an insight, if I misunderstood something please don't hesitate to specify so I can provide complete information.

    I'm on a PC, on Windows 10 home and an Xbox 360 Controller.
    My game is a platformer, but it is meant to be played (preferably) with the Analog stick. Only the X axes is used on it.

    Thanks again!
     
  6. andrewtha

    andrewtha

    Joined:
    Apr 28, 2013
    Posts:
    5
    Hey Guavaman,

    1. Rewired version: 1.1.51.0
    2. Unity Version: 2022.3.21f1
    3. Platform: Windows standalone and Unity Editor.
    4. Primary input is Xbox Series X Controller
    5. Secondary attached inputs are keyboard + mouse.
    6. Controller connected via USB.

    Thanks!
     
  7. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,644
    The stick zero values look normal. I'm virtually certain your problem is the use of the radial dead zone as I stated in my previous message. Change the default dead zone type to Axial and see what happens.

    https://guavaman.com/projects/rewired/docs/RewiredEditor.html#settings-global-settings
     
    Last edited: Mar 19, 2024
  8. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,644
    Primary Input Source refers to your chosen Primary Input Source in the Rewired Input Manager -> Setting. There are many different input sources that can be used in Rewired and knowing which ones are in use can be very important because every one has its own code paths and controller definitions.

    Secondary Input Source(s) refers to alternate input sources for some platforms such as XInput and Windows Gaming Input. This is also shown on the Settings page.

    https://guavaman.com/projects/rewired/docs/RewiredEditor.html#Settings

    I suggest you test one of the example scenes like Simple Control Remapping and see what happens in that scene. This will rule in / out problems in your scene / setup. However, you will want to make the Primary and Secondary Input Sources match in the demo scene's Rewired Input Manager to your other Rewired Input Manager.

    FYI, there is no known cause for what you are reporting and therefore no simple solution without going through and figuring out where the double pressing is coming from. My first suspicion is that you have multiple Event Systems and Input Modules in your scene. That's just a total guess though.
     
    Last edited: Mar 20, 2024
  9. andrewtha

    andrewtha

    Joined:
    Apr 28, 2013
    Posts:
    5
    Thank you for the suggestions - they helped guide me to where the issue was.

    For some reason having "Send Navigation Events" on with my Event System causes this issue but only with Xbox Controllers. It's not anything to do with Rewired.

    Given I'm not using a direct navigation system in my UI and rather a simulated mouse cursor, turning this off fixed my problem.

    Thanks again.
     
  10. alexr1221

    alexr1221

    Joined:
    Mar 5, 2016
    Posts:
    70
    Hi,
    What means the removal of the old platforms such as PS3 or Xbox360? Is it meaning the controller will not be recognized or is it for specific features? Because I am not willing to upgrade rewired since that update.
     
  11. joonturbo

    joonturbo

    Joined:
    Jun 24, 2013
    Posts:
    78
    We are getting this error a lot when using controllers, and they randomly disconnect, often between scene changes.
    We are using Rewired initializer in every scene, and not doing anything else with the Rewired player or anything.

    Unity 2021.3.22f1, Rewired 1.1.41.5.U2021
    Developing on macOS Sonoma, but the error exists on PC and in builds.

    The error doesn't throw up any results on google

    Code (CSharp):
    1. Rewired: Error creating HID device!
    2. UnityEngine.Logger:LogWarning (string,object)
    3. Rewired.Logger:LogWarningNow (object,bool)
    4. Rewired.Logger:LogWarning (object,bool)
    5. Rewired.Logger:LogWarning (object)
    6. sAPYLfEmEFBaJJZbpmTRjSMIEVn:.ctor (uint,int)
    7. sAPYLfEmEFBaJJZbpmTRjSMIEVn:HuJvmADcRQGNsDfywzyrtnFkNGR (uint,int)
    8. oBsnpJWeMbAGbeFNwpGcBuzwhBHt:PcATSkvvdUWyQqdVyogwhEstWbf (uint,uint,uint,bool,System.Collections.Generic.List`1<sAPYLfEmEFBaJJZbpmTRjSMIEVn>)
    9. oBsnpJWeMbAGbeFNwpGcBuzwhBHt:DCJEwWSXaFFsGnXAxyKxEfqcJRA (intptr,uint,uint,bool)
    10. oBsnpJWeMbAGbeFNwpGcBuzwhBHt:chhWbMehsfLLhhbTuNrMijDqBoc (uint,uint,bool)
    11. oBsnpJWeMbAGbeFNwpGcBuzwhBHt:PywEZQiOnBAlFYowfvmroRSMukze ()
    12. oBsnpJWeMbAGbeFNwpGcBuzwhBHt:BWzhnrKmVLjCmIuFuVHajZlvkGN ()
    13. oBsnpJWeMbAGbeFNwpGcBuzwhBHt:OBAJlBlGqlFuhGvIHijolJsMXoT ()
    14. ohnLIeFFAsXJykqdyRiAarRRUxh:PBfhsKqYxjkOItUcfchhKHjFEhoJ ()
    15. SXFNZyxeXuwlYJopvvFQuTvhVdH:iwdVPtmmXLYSaAvRLgLKlTYTNrt ()
    16. SXFNZyxeXuwlYJopvvFQuTvhVdH:PBfhsKqYxjkOItUcfchhKHjFEhoJ ()
    17. SXFNZyxeXuwlYJopvvFQuTvhVdH:Update (Rewired.UpdateLoopType)
    18. bCQdWfFSooNJWAuNRMeMhvVaQlTy:Update (Rewired.UpdateLoopType)
    19. Rewired.ReInput:xSvteHCwnFacYLbuyaeXeqnWpVm (Rewired.UpdateLoopType)
    20. Rewired.InputManager_Base:DoUpdate (Rewired.UpdateLoopType,Rewired.Config.UpdateLoopSetting)
    21. Rewired.InputManager_Base:Update ()
    22.  
     
  12. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,644
    If you are using multiple Event Systems, you must either use Unity's Multiplayer Event System or use the Rewired Event System and enable "Always Update." If you are using Rewired's alongside Unity's, you must use Multiplayer Event System and not their normal Event System as it is not compatible with having multiple Event Systems of any type in a scene.

    See this message to understand how Unity's Event System works (singleton)::
    https://forum.unity.com/threads/rewired-advanced-input-for-unity.270693/page-184#post-9705557

    An Event System also has an Input Module. Unity's Event System by default uses the Standalone Input Module which gets input from Unity's input system. That would explain why the Xbox controller was sending Submit events and other controllers weren't.
     
    Last edited: Mar 20, 2024
  13. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,644
    Xbox 360 and PS3 build target support was removed (they were never complete anyway, wrapping UnityEngine.Input and not having any controller definitions). This change did not affect any other platforms.
     
    alexr1221 likes this.
  14. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,644
    Rewired has no knowledge of scene loading. There is no code path that would execute anything based on scene loading.

    HID devices are only created when the underlying input source(s) report a new device present. There is no other circumstance in which a HID device would be attempted to be created. This happens when a controller is connected and when Rewired is first initialized.

    The error "Rewired: Error creating HID device!" is not logged anywhere in Rewired's current codebase. You're using a version of Rewired that is over 2 years old. I suggest you update. Where it was previously logged was only on OSX in the native code path when a new HID device is detected from IO Kit and on first initialization.

    There was never anywhere in the Windows code base where "Rewired: Error creating HID device!" was ever logged, so the error on PC can't be the same. Also, the code paths on Windows and Mac are 100% different, even using totally different APIs that work very differently from each other, so I can see no possible way the same error could be occurring.

    Errors that happen only after scene loading make me highly suspicious that Rewired is being destroyed on scene load. Even if you are using Rewired Initializer, if you have unchecked Don't Destroy on Load in the Rewired Input Manager, the Rewired Input Manager will be destroyed on scene load. You must make sure you are managing the Rewired Input Manager lifetime correctly. Rewired being re-initialized will definitely cause problems, including potential loss of control due to controller re-assignment and loss of other runtime state when destroying and reinitializing. Because you say this happens on two completely different platforms, I am highly suspicious that the Rewired Input Manager is being disabled or destroyed on scene load and then re-enabled / instantiated.

    Log something in ReInput.InitializedEvent and see how many times it appears in the logs. If It appears more than once, you definitely have a lifetime management problem:
    https://guavaman.com/projects/rewired/docs/api-reference/html/E_Rewired_ReInput_InitializedEvent.htm

    The controllers being used also play a role in what code paths are being used. What controller are you testing with and how are they connected? If Dual Shock 4 or Dual Sense, is Enhanced Device Support enabled in Rewired Input Manager -> Settings -> Platform?

    When you say a controller "disconnects", are you saying it loses connection to the PC or just stops responding to input? If it's losing connection, this is not Rewired's doing. Rewired has no control over Bluetooth pairing or the power state of the controller. It can't disconnect a controller from the computer on any platform. If it is just losing the ability to control the game, use Debug Information to find out exactly where it is failing:
    https://guavaman.com/projects/rewir...l#debug-information-diagnosing-input-problems
     
    Last edited: Mar 20, 2024
  15. Peeling

    Peeling

    Joined:
    Nov 10, 2013
    Posts:
    443
    EDIT: Okay, not the bug I thought it was.

    I had thought Rewired was getting confused and blending axes together when swapping controllers on console (specifically steering and acceleration). Turns out that wasn't the case.

    Rather, a session of adding, duplicating, and deleting mapping seems to have left the wheel map with a dozen or more mappings I DEFINITELY never added (eg three copies of 'Map Wheel to Accelerate', which aren't dupes of anything else and I obviously never set up. Will see if I can figure out exactly what the process was.
     
    Last edited: Mar 21, 2024
  16. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,644
    What is your rebinding process? Are you using Input Mapper? It is likely something works differently than you are expecting. What you are describing sounds like exactly what would happen if you are trying to replace a binding but haven't set all the values correctly to tell it to do a replacement and it is instead adding bindings one at a time. Action Element Map Id is a unique identifier and must be set to the exact binding that is being replaced.
     
  17. Simonlite

    Simonlite

    Joined:
    Oct 1, 2021
    Posts:
    12
    Hey Guavaman!

    I changed the default Dead Zone type to Axial but nothing happened. The analog stick still has no Dead Zone on my Xbox 360 controller and slightest touch still moves my character.
    upload_2024-3-21_18-57-17.png

    When I open the Calibrate Controller in game, I have to move it almost double the initial default setting on the Dead Zone to make it work "normally" with an acceptable Dead Zone. Here you can see before and after.
    upload_2024-3-21_19-5-17.png upload_2024-3-21_19-5-27.png

    But having the Control Mapper is unnecessary for my game, since it is a very basic game and you say that the default Dead Zone of this controller should have big enough with the default Dead Zone already, and I can't seem to get that in my game. Any other ideas that can help me debug this somehow?

    Thanks!
     
  18. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,644
    Take a picture of the axis values in Debug Information at the moment the character starts moving. The raw value would be the most important.

    Before you do that, clear PlayerPrefs. If you don't, you could be doing testing with user-defined overrides of the calibration values which would make these tests pointless.

    If your stick is somehow ridiculously sensitive or poorly calibrated, you will see a value greater than 0.25 on the raw axis value with even the slightest press. But also what is important is the non-raw value, which will likely be a very small value like 0.05 or something, as it has been scaled based on the dead zone.

    Again, I don't know how your game works, but I am suspecting that you are using digital movement, i.e.: if(player.GetAxis("MoveHorizontal" != 0) // move. If this is the case, then any value beyond the dead zone is going to be translated into full movement. Dead zones are primarily meant to eliminate unintentional axis drift, not regulate when your character starts moving -- that is a gameplay concern. Based on your picture, it appears you want movement to start at around 50% raw value, which would be an absolutely massive dead zone. If your game requires that the character only start moving when the stick reaches a specific point, add your own filtering in your code to determine when the character should start moving. This approach solves the problem for all controllers simultaneously and doesn't require any user calibration and works with the default dead zones. This only applies to games that use digital movement (move with any non-zero input) rather than analog (character speed scales with axis value), though something similar could be done to scale the value for that case.

    Code (csharp):
    1. if(Mathf.Abs(player.GetAxis("MoveHorizontal")) > 0.3f) { // 0.3 because the axis value already has the default dead zone applied
    2.     // move
    3. }
    Another way to handle digital input is to use player.GetButton and GetNegativeButton instead of GetAxis and set the InputBehavior's Button Dead Zone value to the calibrated axis value at which the button should transition to on.
     
    Last edited: Mar 21, 2024
  19. Peeling

    Peeling

    Joined:
    Nov 10, 2013
    Posts:
    443
    Yeah, if I was rebinding at runtime I would have immediately blamed myself :) I was just using the Rewired Editor.

    While trying to establish which buttons were what on a racing wheel, I had gone through a lengthy process of adding, duplicating, and deleting lots of mappings. But none of them involved 'Wheel' (element) or 'Accelerate' (action), because they had already been set up months ago at the top of the list. When I re-opened the prefab after testing, however, there were a bunch of largely nonsense mappings including three copies of "Wheel" to "Accelerate" all at the bottom of the list.

    I guess it could be user error, but I know for sure I never saw or edited those mappings deliberately, and I haven't found any accidental way of doing it either (eg mouse-wheeling while over the action list or element dropdown). I could understand accidentally leaving a bunch of blank entries, OR a bunch of entries that I had created and missed deleting, but not ones that I never made.
     
  20. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,644
    The only thing I know of that can cause this kind of inexplicable change to data in the Rewired Input Manager is Unity serialized data corruption. It's not that uncommon. The most common cause is source control merging. Other known causes:
    https://guavaman.com/projects/rewired/docs/KnownIssues.html#serialized-data-corruption-after-import
    https://guavaman.com/projects/rewir...ialized-data-corruption-after-upgrading-unity

    I'm going to guess Wheel is element identifier id 0 and Accelerate is action id 0. This would correspond to a new uninitialized ActionElementMap being added. If you're curious what the stored data looks like, select the Rewired Input Manager and change the inspector to Debug mode and open User Data.
     
    Last edited: Mar 22, 2024
  21. protomor

    protomor

    Joined:
    Dec 13, 2021
    Posts:
    38
    Is there a simple way to go through a controller and reset all the axis' back to default settings?
     
  22. shotoutgames

    shotoutgames

    Joined:
    Dec 29, 2013
    Posts:
    290
    Apologees if answered previously?
    Is this just because I am using Unity 6.0 Beta?
    Assets\Rewired\Internal\Scripts\Misc\ExternalTools.cs(100,34): error CS0535: 'ExternalTools' does not implement interface member 'IExternalTools.WindowsStandalone_ForwardRawInput(IntPtr, IntPtr, uint, IntPtr, uint)'

    Thanks
     
  23. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,644
    If you are referring to clearing an axis's returned value, no. See this:
    https://guavaman.com/projects/rewired/docs/FAQ.html#consume-input

    Element values are set by the values received from the device.

    If you are referring to something else like reverting Controller Map bindings:
    https://guavaman.com/projects/rewir...ontrollerHelper_MapHelper_LoadDefaultMaps.htm
     
  24. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,644
    Yes. Rewired has no knowledge of that branch of Unity and if they've changed the naming convention again from 20xx to Unity 6, there's no way any of the preprocessor #ifs or other methods I've built in to detect future versions are going to work. Even if you made that particular file compile, other stuff will fail for the same reason. There are a number of internal runtime code paths that differ depending on version including greater than and less than comparisons. The version is detected by parsing the string returned by Application.unityVersion. All comparisons based on that are going to be broken if Unity 2024 is now being referred to as Unity 6.

    https://guavaman.com/projects/rewir...ng.html#unity-alpha-beta-preview-experimental
     
    Last edited: Mar 23, 2024
    shotoutgames likes this.
  25. shotoutgames

    shotoutgames

    Joined:
    Dec 29, 2013
    Posts:
    290
    Thank you for the explanation. I know it's not recommended but wanting a temporary fix, I implemented the missing with an empty method and just commented out all the version checks. Thanks again.
    Yes, it's definitely Unity 6 now
     
  26. Simonlite

    Simonlite

    Joined:
    Oct 1, 2021
    Posts:
    12

    Hey Guavaman!

    So this is approximately where my character starts moving, its almost immediately as I move the left analog stick:
    upload_2024-3-25_0-22-23.png

    But you were right! The code is working as a digital movement, because it is stated as such:

    moveInput = player.GetAxisRaw("MoveHorisontal");

    Together with:

    if (moveInput > 0)
    {
    moveInput = 1;

    }

    But my confusion is that with the above code for movement, the Unity Input Manager still didn't give me a "no-dead zone" response. It had a perfectly fine Dead Zone before I changed to Rewired with the above code, hence my confusion.

    Nonetheless, I changed up the code so now it says:


    if (moveInput > 0.3f)
    {
    moveInput = 1;

    }

    And this is giving a nice Dead Zone that I was expecting so everyhing works nicely now, THANKS!
    What did you mean by "0.3 because the axis value already has the default dead zone applied" by the way? I put my value to 0,2f in the end, cause I thought that felt better, but maybe it had no difference?

    Thanks again!
     
  27. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,644
    All that means is Unity defaults to an even bigger dead zone value for Xbox controllers than Rewired does, which would be a problem for a game that needs more input resolution. Unity's input manager has dead settings for each axis. If you've modified these, this could be where the discrepancy comes from. If not, they must be applying a large dead zone internally. Since I don't have access to the Unity source code, I can't say for certain.

    You're applying your filter to the final Action value. Action values come from the underlying controller elements that contribute input. All recognized controllers have a default dead zone value which is applied to the raw value coming from the controller and is reflected in the Action value.

    Example:
    Rewired Xbox 360 Controller axis dead zone: 0.25
    Axis raw value: 0.25
    Axis calibrated value: 0

    The calibrated value is used in the Action value calculation. Therefore, Rewired is already applying a 0.25 dead zone to the axis. Your code then applies a second dead zone on top of that. Since you changed the value to 0.2, you are requiring a value of 0.2 or greater from an already-calibrated value to make your character move. In other words, for a properly calibrated axis with a reasonable dead zone, you require the user move it 20% beyond the dead zone for the character to move.
     
    Last edited: Mar 25, 2024
  28. Simonlite

    Simonlite

    Joined:
    Oct 1, 2021
    Posts:
    12

    Okay, so based on the screenshot I showed you, does it seem like the Raw Value of when my player moves is accurate then? As in, the controller works as intended and Rewired is responding as intended?
    Because then I might think that the change to the Dead Zone (adding 0.2f), is the Dead Zone I want. And to explain why, when I play other platforming games on Steam (Dead Cells, Celeste etc) which have the same behavior (as in they also has full speed when it leaves Dead Zone), then it is usually around where I have it set now (0.2 ontop of the 0.25 applied by Rewired), and some other platform games have even more.
    I understand that for games that actually use the full values of the axis for a more precise movement might need a smaller Dead Zone (such as first person shooters for accurate turn rates, or cars for accurate drifts and so on..). But for platformers I am suspecting they need more since otherwise slightest movements would turn your character unintended.

    That is my thesis atleast hehe :)

    If you do not agree, and you still think I am doing it wrong, do you think I should get more Xbox controllers here and try them out as well? I do not mind debugging, cause I like Rewired, but I hope to also slowly understand more as I use it in more games.

    Thanks again Guavaman, you're a champ!
     
  29. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,644
    Your problem is a question of gameplay mechanics. The axis dead zone is simply there to prevent axis noise from causing input.

    Applying a minimum threshold to input before moving the character is the correct way to handle this gameplay design question. This is handled entirely outside of the input system as it should be. I would consider it incorrect to modify the stick's dead zone to solve this gameplay concern.

    Consider this: What if you wanted to control something with analog input at some other point in your game? A software mouse cursor, for example. You would have a problem on your hands if you tuned the stick's dead zone specifically for your character movement needs because that dead zone would also apply to the mouse cursor.

    Applying your own minimum threshold to the Action value before moving your character is the correct way to handle this problem. I am certain that all the games you've played that use digital input also do it this way. It would be too unpredictable to simply check if the value != 0 before moving digitally because you have no idea what controllers your players will be using or how they are calibrated. I would have been able to tell you the correct solution earlier if I knew your game used a digital input scheme.
     
    Last edited: Mar 26, 2024
  30. guavaman

    guavaman

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

    See Updating Rewired before updating.

    Release notes:

    1.1.52.0:

    Changes:
    - Added Custom Platforms: Developers can now add support for platforms not supported natively by Rewired.
    - Added Custom Platform example.
    - Updated Unity version check handling for Unity 6 in preparation for Unity 6 support. (Unity 6 support has not been added in this release.)

    API Changes:
    - Added Rewired.Platforms.Custom.CustomPlatformConfigVars class.
    - Added Rewired.Platforms.Custom.CustomPlatformInitOptions class.
    - Added Rewired.Platforms.Custom.CustomPlatformInputSource class.
    - Added Rewired.Platforms.Custom.CustomPlatformInputSource.InitOptions class.
    - Added Rewired.Platforms.Custom.CustomPlatformInputSource.Joystick class.
    - Added Rewired.Platforms.Custom.CustomPlatformUnifiedControllerSource class.
    - Added Rewired.Platforms.Custom.CustomPlatformUnifiedKeyboardSource class.
    - Added Rewired.Platforms.Custom.CustomPlatformUnifiedMouseSource class.
    - Added Rewired.Platforms.Custom.HardwareJoystickMapCustomPlatformMap class.
    - Added Rewired.Platforms.Custom.HardwareJoystickMapCustomPlatformMap.Axis class.
    - Added Rewired.Platforms.Custom.HardwareJoystickMapCustomPlatformMap.Button class.
    - Added Rewired.Platforms.Custom.HardwareJoystickMapCustomPlatformMap.Elements class.
    - Added Rewired.Platforms.Custom.HardwareJoystickMapCustomPlatformMap.MatchingCriteria class.
    - Added Rewired.Platforms.Custom.HardwareJoystickMapCustomPlatformMap<TMatchingCriteria> class.
    - Added Rewired.Platforms.Custom.HardwareJoystickMapCustomPlatformMapSO class.
    - Added Rewired.Platforms.Custom.ICustomPlatformInitializer interface.
    - Added Rewired.Platforms.Custom.IHardwareJoystickMapCustomPlatformMapProvider interface.

    Bug Fixes:
    - Updated editor code to handle recently changed Xbox Game Core build target strings when automatically setting Rewired_Core.dll build targets.
     
  31. AffectusGames

    AffectusGames

    Joined:
    Jan 6, 2020
    Posts:
    4
    Hello, I have a hard time finding a solution to my problem.

    I have a remapping screen that works great, and I use the input mapper class to listen for a new input (for the default category and layout) and save it using the datastore component.
    What I want is for the player to choose a new valid input and save that new input in another map (The UI map).

    What I currently do for a single remap in the default map is

    • On click on a button I start the listening
    Code (CSharp):
    1. // Start listening
    2.             _inputMapper.Start(
    3.                 new InputMapper.Context()
    4.             {
    5.                 actionId = _inputAction.id,
    6.                 controllerMap = _simpleControlRemappingCustom.GetControllerMap(_category, _layout),
    7.                 actionRange = _axisRange,
    8.                 actionElementMapToReplace = _actionMapIdToReplace
    9.             };
    10.             );
    11.  
    12.  
    • when an input is mapped, I save the datastore inside the OnInputMapped(InputMapper.InputMappedEventData data) method.
    In the second step (when saving or just before), I'd like to assign that new input to the other UI map.

    I tried using the same method as your keyboard/mouse example, using two inputmappers to listen twice, but it didn't work.

    Can you give me directions on how to manually save a key to a map without listening?

    Thanks in advance, and I'm sorry if my message is confusing.

    PS: I'm not using the Control Mapper. I built a custom view where I manually place one row for each action I want to remap. Each row binds the onclick event and calls the inputmapper. I'm not sure it's an issue, but I thought I should mention it.
     
  32. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,644
    There is nothing built in that will help you synchronize bindings across controller maps. The only way to do it is to change the bindings manually.

    Iterating Action Element Maps:
    https://guavaman.com/projects/rewired/docs/HowTos.html#enabling-disabling-action-element-maps

    All the necessary functions are in these classes:
    https://guavaman.com/projects/rewired/docs/api-reference/html/T_Rewired_ControllerMap.htm
    https://guavaman.com/projects/rewired/docs/api-reference/html/T_Rewired_ControllerWithAxes.htm
    https://guavaman.com/projects/rewired/docs/api-reference/html/T_Rewired_ActionElementMap.htm

    Specific functions:
    https://guavaman.com/projects/rewir...d_Rewired_ControllerMap_ReplaceElementMap.htm
    https://guavaman.com/projects/rewir...d_ControllerMap_ReplaceOrCreateElementMap.htm
     
    Last edited: Mar 28, 2024
    AffectusGames likes this.
  33. guidaye

    guidaye

    Joined:
    May 20, 2022
    Posts:
    19
    Hi guavaman,
    We have encountered a problem that game responses to the keyboard input even no on focus.
    This happens when we click on other window right after we launch our game in windowed mode, when the first scene shows up, it responses to the keyboard input as we typing in other window.
    we have setting "Ignore Input When App Not In Focus" checked. but problem remains.
     
    Last edited: Mar 28, 2024
  34. alexr1221

    alexr1221

    Joined:
    Mar 5, 2016
    Posts:
    70
    Hi, is there a way to easily get the raw values of a thumbstick instead of the calibrated one? The only use I found is in the controllerremapping scene.
     
  35. AffectusGames

    AffectusGames

    Joined:
    Jan 6, 2020
    Posts:
    4
    Thank you so much for your help! I think I'm almost good.
    The remap happens. I can confirm in the rewired debug information that my main action (Default map) and my secondary action (UI map) are remapped. I can also confirm in the game that both work when I press the key.

    BUT, it seems that the save (or load) doesn't work correctly for the secondary action.
    No matter what I update or add to the UI map, the UI map won't save to player prefs.

    These are the maps before AND after saving to playerPrefs with ReInput.userDataStore.Save();
    => all good as shown in the debug information inspector below
    To be sure I save after the remap, I save when the view is disabled (when closing the menu).


    upload_2024-3-28_21-42-23.png

    Now, the same, but after restarting the scene
    => The first one was saved, but not the UI one
    upload_2024-3-28_21-45-52.png

    Do you have any idea what is wrong with my code? I can't figure it out... Why doesn't it persist?

    Code (CSharp):
    1.  
    2. private void OnInputMapped(InputMapper.InputMappedEventData data) {
    3.   RemapSecondaryAction(data);
    4.   _currentInputMapperContext = null;
    5.   StartCoroutine(UpdateUi());
    6. }
    7. private void RemapSecondaryAction(InputMapper.InputMappedEventData data) {
    8.   // 95 for UI Alt Close Task List
    9.   // Hardcoded for now
    10.   const int secondaryActionId = 95;
    11.   // Take properties from the original action data
    12.   AxisRange swapAxisRange = data.actionElementMap.axisRange;
    13.   ControllerElementType swapElementType = data.actionElementMap.elementType;
    14.   int swapElementIdentifierId = data.actionElementMap.elementIdentifierId;
    15.   KeyCode swapKeyCode = data.actionElementMap.keyCode;
    16.   ModifierKeyFlags swapModifierKeyFlags = data.actionElementMap.modifierKeyFlags;
    17.   // Get all the element maps with the secondary action
    18.   var secondaryActionElementMapsFound = new List < ActionElementMap > ();
    19.   Player.controllers.maps.GetElementMapsWithAction(secondaryActionId, false, secondaryActionElementMapsFound);
    20.   // Loop through all the element maps and swap the action with the original data
    21.   foreach(var secondaryElementMap in secondaryActionElementMapsFound) {
    22.     // Take the Action and some properties from the secondary action element map
    23.     int swapActionId = secondaryElementMap.actionId;
    24.     Pole swapAxisContribution = secondaryElementMap.axisContribution;
    25.     bool swapInvert = secondaryElementMap.invert;
    26.     // Replace the secondary element map with the original data
    27.     secondaryElementMap.controllerMap.ReplaceOrCreateElementMap(
    28.       ElementAssignment.CompleteAssignment(
    29.         secondaryElementMap.controllerMap.controllerType,
    30.         swapElementType,
    31.         swapElementIdentifierId,
    32.         swapAxisRange,
    33.         swapKeyCode,
    34.         swapModifierKeyFlags,
    35.         swapActionId,
    36.         swapAxisContribution,
    37.         swapInvert,
    38.         secondaryElementMap.id
    39.       )
    40.     );
    41.   }
    42. }
    43.  
    44.  
     
  36. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,644
    Provide the following information:
    • Version of Rewired
    • Build platform
    • Primary Input Source (Rewired -> Settings -> PLATFORM)
    • Native Keyboard Handling (Rewired -> Settings -> PLATFORM)
    Rewired relies on MonoBehaviour.OnApplicationFocus to determine if the application is in focus.
    If Unity is not sending this event to Rewired's MonoBehaviour for whatever reason, including if the Rewired Input Manager is not initialized in the first scene of the game, it cannot know whether the application is in focus or not.

    Based on my analysis of the code and my testing how Unity works in Unity (2023.1.0f1), for this to happen requires all of the following to be true:
    1. Windows Standalone build
    2. Application.runInBackground is true
    3. Primary Input Source: Raw Input or Direct Input + Native Keyboard Handling enabled.
    4. Rewired Input Manager not present in or instantiated in Awake in the first scene of the game. Even if Rewired is in the first scene but is not instantiated until Start or later, it will not receive the focus event from Unity.
    Since writing this, I see Unity has added Application.isFocused to the API. This could now be used to detect the focus on start without relying on the focus event being sent. This is not currently used in Rewired's code. The only workaround for your issue is to make sure Rewired is initialized in the first scene of the application. The Rewired Initializer works as well because it instantiates Rewired in Awake and the OnApplicationFocus event is sent by Unity after Awake runs on all enabled scripts.

    Edit: I have fixed the issue and will be uploading a new version (1.1.54.0) today.
     
    Last edited: Mar 29, 2024
  37. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,644
    https://guavaman.com/projects/rewir...l/M_Rewired_ControllerWithAxes_GetAxisRaw.htm

    You cannot get the value of an Action with uncalibrated values. This is not calculated. Only the controller elements themselves can provide raw values.
     
  38. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,644
    You have probably designated the UI map category to be non-user-assignable.

    Line 865 of UserDataStore_PlayerPrefs.cs:
    PlayerSaveData playerData = player.GetSaveData(true);

    The value for userAssignableMapsOnly being passed to the function is true. This means do not save non-assignable maps. This is because it would be pointless to save controller maps that cannot be changed.
     
  39. AffectusGames

    AffectusGames

    Joined:
    Jan 6, 2020
    Posts:
    4
    Thanks a lot! I missed that for that category. It works perfectly now. Awesome support!
     
  40. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,644
    Rewired 1.1.54.1 is available on the Unity Asset Store:

    See Updating Rewired before updating.

    Release notes:

    1.1.54.1:

    Bug Fixes:
    - New Custom Platform Hardware Joystick Map Platform Map axis values are now set to the correct default values when adding an axis.

    1.1.54.0:

    Changes:
    - Added variants to Rewired.Platforms.Custom.HardwareJoystickMapCustomPlatformMapSimple.

    API Changes:
    - Added Rewired.Platforms.Custom.HardwareJoystickMapCustomPlatformMapSimpleBase class.
    - Moved Rewired.Platforms.Custom.HardwareJoystickMapCustomPlatformMapSimple.MatchingCriteria class to Rewired.Platforms.Custom.HardwareJoystickMapCustomPlatformMapSimpleBase.MatchingCriteria.

    Bug Fixes:
    - Added detection of initial application focused state with Application.isFocused (Unity 2017+) to eliminate edge case of application incorrectly responding to input events in builds if window is defocused during initial application loading while Application.runInBackground is true and Rewired is not initialized on Awake in the first scene of the application on certain platforms using certain input sources.

    1.1.53.0:

    Changes:
    - Added editor inspector support for Custom Platform Hardware Joystick Map Platform Map variants.
    - Updated Custom Platform example to illustrate variants and HardwareJoystickMapCustomPlatformMapSimpleSO.

    API Changes:
    - Added Rewired.Platforms.Custom.HardwareJoystickMapCustomPlatformMapSimple class.
    - Added Rewired.Platforms.Custom.HardwareJoystickMapCustomPlatformMapSimple.MatchingCriteria class.
    - Added HardwareJoystickMapCustomPlatformMapSimpleSO class.
     
    Last edited: Mar 29, 2024
  41. guidaye

    guidaye

    Joined:
    May 20, 2022
    Posts:
    19
    Thanks for your reply and here is the information of our project:
    Rewired version: 1.1.45.0
    Build platform: Windows Standalone with Application.runInBackground = true
    Primary Input Source: Raw Input + Native Keyboard Handling enabled.
    All thoes matches what you present as the reproduce conditions. and for the last point(No.4) I clicked on the other window right after I launched the game, at this point, the Rewired Input Manager hasn't been instantiated quite possiblely, If I wait for the first scene to show up, The cursor will be locked within our game windows, so only when the focus get translated to other window before the first scene shows up can lead to the case.

    I will try to upgrade to the latest version 1.1.54.0 as you mentioned to see if it fixed the problem.
    Again, thanks a lot for your support.
     
  42. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    2,047
    I see it (1.1.54.1) complains now of needing Rewired for Unity 6000, it didnt before the last version
     
  43. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,644
    As it should. Rewired 2023 is compiled against Unity 2023 libraries. Every Unity major version requires a new branch of Rewired. The only reason it wasn't logging warnings was that it couldn't even detect the Unity version.

    1.1.52.0:

    Changes:
    - Updated Unity version check handling for Unity 6 in preparation for Unity 6 support. (Unity 6 support has not been added in this release.)
     
  44. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    2,047
    Not saying it shouldnt, but it didnt before, and Im pretty sure i was only 1 version behind, possibly because it was 2023.3 and when the version turned to 6000 i just threw in the compile define to cheer it up and it moved on
     
  45. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,644
    Rewired has reported this incorrect Unity version error for many years. I get complaints about the warning every single time a new major version of Unity beta comes out. I made the decision a long time ago to keep this warning in and not allow it to be silenced. It is considered an error to use a version of Rewired incompatible with the version of Unity for which it was built. This is for many, many reasons. There are so many things that could be broken and there is no way to know until that code path executes in some cases. There very well could be errors that you are not aware of. There are many things in the editor and a few at runtime that use reflection. If any of that API has changed, Rewired will break when that code executes and Unity's API updater cannot detect these changes. Some errors may not even be detectable until you attempt to compile on one platform or another. Even many of the scripts that are compiled in the Rewired directory have important version checking code that can cause the wrong code within #if statements to be compiled if used in the wrong version of Unity leading to all sorts of error messages that get reported to me on a regular basis. And then there are the myriad Rewired extras, integrations, and platform plugins which all have the potential of being broken or resulting in unexpected behavior. The Unity 6 update was even a bigger issue as there are a number of version specific checks in code as well that may significantly change behavior of all manner of things which would have been broken without any errors or warnings being logged.

    The original reason I added the version check was this constant nagging problem with the Asset Store that I get support requests on on a very regular basis. This issue can come up every single time a user installs or updates Rewired from the Asset Store if they are working on multiple projects in different versions of Unity.

    Using Rewired in a newer major version of Unity than the one for which it was not built is every bit as much of an error as opening a project built in a newer version of Unity in an older version. The older version of Unity has no idea what to do with the new and changed data format and API.
     
    Last edited: Mar 31, 2024
  46. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    2,047
    Appreciate the explanation. I love the product, i have had my struggles with getting going on some parts of it, but it is a solid product one of the few i would highly recommend to people
     
    guavaman likes this.
  47. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,644
    Thanks!
     
  48. Andrew-Carvalho

    Andrew-Carvalho

    Joined:
    Apr 22, 2013
    Posts:
    45
    Is there any way to get map data without a controller being connected? I don't need the map loaded, just access to the data that holds the bindings of actions to element IDs.

    The use case is as follows:
    A game is launched without a controller connected but needs to display a specific set of controller glyphs on screen for button prompts.

    With the controller connected, the way this is done is by using the active map on the player and iterating through the element IDs to look up the correct sprites to display in the UI. I need a way to do this before an controller is connected.

    On previous projects I've had to write a script to manually set the default glyph sprite on button prompts to work around the limitation of not having maps loaded. This solution is cumbersome and will show incorrect bindings in the case where a player has remapped their inputs. I am hoping there is a better way to do this when using rewired as this approach on one of our current projects would be an unreasonable amount of work.
     
  49. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,644
    See the documentation:
    https://guavaman.com/projects/rewired/docs/HowTos.html#get-mappings-for-joystick-not-attached

    If saved user data is involved:
    https://guavaman.com/projects/rewir...lper_GetJoystickMapInstanceSavedOrDefault.htm

    There are many very good reasons this cannot be a transparent or even reliable process depending on the platform, input source(s) in use, and controllers in use. There is no way to know the specific device element map that will be loaded for any device until that device is present, low-level identifying information is exposed through the input API that ultimately ends up handling it (multiple input sources may detect a device, but which one handles it is decided per-device at detection time based on information provided by the hardware/driver), and a match of that identifying information for that specific input source is performed against the set of known maps. The only platforms where this would be predictable are console platforms that have a single input source that only supports a very limited set of devices with no variants. This is not possible on PC, Mac, Linux, Android, etc. due to the vast number of devices, variants of devices, and different possible input sources.
     
    Last edited: Apr 2, 2024
  50. Andrew-Carvalho

    Andrew-Carvalho

    Joined:
    Apr 22, 2013
    Posts:
    45
    This is the exact use case I am dealing with and the logic is conditionally compiled for consoles.

    Thanks! I think this is all I need to solve the specific issue I've run into during testing. I appreciate the quick response!