Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Rewired - Advanced Input for Unity

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

  1. Bartolomeus755

    Bartolomeus755

    Joined:
    Jun 20, 2013
    Posts:
    249
    Great update and thx for adding native 2019 support.
     
    guavaman likes this.
  2. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,243
    This is still true, but I just released the 2019 branch in anticipation of 2019 going out of beta which was rumored to be in early April. I have no idea if that's on track or not. And I do anticipate possible further issues with the Control Mapper code which was changed due to breaking API changes in EventSystem in 2019.1 if they decide to change the API again before finalizing it. But I wanted to have some kind of 2019.1 branch out at the time 2019.1 goes out of beta. Plus I wanted to get these other changes released which I've been working on for a long time and didn't want to wait for Unity to officially launch 2019.1 to do that.
     
    Bartolomeus755 likes this.
  3. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,479
    I was looking at this thread currently on the beta ...

    https://forum.unity.com/threads/fee...about-2019-1-in-its-current-state-b10.655342/
     
    guavaman likes this.
  4. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,696
    I was referring to what the "Restore Defaults" button on the control mapper does.
    Your above post supplied the solution.
    Thank you for the support.
     
    Last edited: Apr 9, 2019
  5. f1chris

    f1chris

    Joined:
    Sep 21, 2013
    Posts:
    308
    Thx @guavaman for your help. If you tell me what .cs file I can run it with a Debug.Log .

    I was wondering after what you said it may be some interference since I'm using a huge project with tons of windows. So i used another simpler smaller project I had but with same results :-(
     
    Last edited: Apr 9, 2019
  6. TommiH

    TommiH

    Joined:
    Jan 14, 2008
    Posts:
    252
    Hello @guavaman,

    I've looked further into an issue I mentioned earlier on this thread: Sometimes, when I pause the game and later unpause it, using Ctrl-Shift-P, it triggers a key combination that I never pressed. I've finally figured out what's happening: If, during the pause, I press, say, M, this gets buffered up somehow, and the next time I press Ctrl-Shift-P, it all gets combined into Ctrl-Shift-M. Which is clearly not what we want - it should not register any key presses during pause at all, and even if there's some reason it should (like edit-time features), it shouldn't combine keys that I never pressed at the same time.

    I'd appreciate a workaround, or failing that, a fix in an update soon.

    Best regards,
    Tommi Horttana
     
  7. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,243
    There's no CS file. It's all in Rewired_Editor.dll. The only thing you could possibly log is Screen.width and Screen.height from within OnGUI inside an Editor Window.

    Have you tried resetting your Unity editor layout? I hear the editor layout can be the source of all kinds of issues including crashes.
     
  8. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,243
    What is your definition of a "pause"? My guess: Time.timescale = 0. And then you're calling GetButtonDown in FixedUpdate?

    Guess: This is referring to Windows Raw Input / Direct Input + Native Keyboard Handling.

    How this works:
    1. Windows delivers input event messages at the beginning of every cycle.
    2. Rewired stores the input events for every enabled Update Loop (Update, Fixed Update) separately in a queue so no events are missed (button down's at low frame rates for example).
    3. The queue is processed for that Update Loop the next time it comes around.
    4. You set Time.timescale to 0, so FixedUpdate never runs and Rewired cannot process the queue.
    5. You then set Time.timescale back to 1 and all queued key events that were received since the last time FixedUpdate was processed are handled.
    It's doing exactly what it should be doing. The problem here is that Rewired's FixedUpdate is not being allowed to run to process events because Unity is never calling FixedUpdate because of the timescale setting.
     
    Last edited: Apr 9, 2019
  9. TommiH

    TommiH

    Joined:
    Jan 14, 2008
    Posts:
    252
    No. I mean the Unity editor pause, which can be triggered either by pressing the middle button at the top of the editor (between Play and Step Forward) or by pressing Ctrl-Shift-P. And I'm calling the Player.GetButtonDown function in Update.
     
  10. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,243
    Oh. Well the explanation would be the same then. Unity is not calling Update in Rewired so it can't possibly process the input events it's receiving when the editor is paused until it is unpaused. If the application is considered not in focus, these events should be discarded. The only scenario I can imagine where this would happen is if you pause it and then click in the Game window and start pressing keys. The only possible workaround I can think of is to clear all events every time Application.isPlaying changes, but doing that within a DLL that cannot access Unity Editor functions may not be possible since I can't detect Application.isPlaying == false in Update (Update won't be called).
     
  11. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,243
    Re-reading this, the value M should never exist beyond the first frame that input is processed again which would be immediately when you unpause the editor. If the value of M is sticking and being processed at some time in the future after the application has already started playing again, that's completely different. Look in Debug Information and look at the value of the M key in Controllers -> Keyboard. If this is sticking on, then the problem is something entirely different. (Windows is sending a Down event but never an Up to the window would be my guess, or the Up is somehow being lost.)
     
  12. TommiH

    TommiH

    Joined:
    Jan 14, 2008
    Posts:
    252
    As far as I can tell, the M is only "sticking" until the first frame after the unpausing. Unfortunately, that's enough. The way I'm able to repro this is by simply playing the game, pressing Ctrl-Shift-P to pause it, then pressing M (and releasing it), and then pressing Ctrl-Shift-P again to unpause the game. The key combination Ctrl-Shift-M is now triggered. I don't need to click in the game view after pausing the game for this to happen.

    And in fact, I don't even have to have Unity in focus for this to happen - I might just as well type M here on this website and it'll still register somehow.... which is quite weird indeed, since when I'm unpaused, obviously no input in this text box has any effect. I guess I'll check if this happens with Unity's input...

    Can you tell me a bit about what happens between the scenes with Rewired? Is it just using Unity's input as a back-end? Or does it read the keyboard on its own?
     
  13. TommiH

    TommiH

    Joined:
    Jan 14, 2008
    Posts:
    252
    Well, it turns out this happens with Unity's input as well. Which is pretty odd, I have to say.
     
  14. TommiH

    TommiH

    Joined:
    Jan 14, 2008
    Posts:
    252
    I tested some more. It looks like the difference between Unity input and Rewired is that with Unity input, it won't take the input if you're not focused on the game view. However, with Rewired, you can be alt-tabbed out, and it'll still have an effect. So could you shed some light on how Rewired is reading the keyboard?
     
  15. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,243
    There is no single one way Rewired handles input. Everything is dependent on the platform, the input sources in use, and the options enabled. Every single platform and input source is different, and further options change the code path, and even the device itself can change the code path. Running in the editor can also be different from a build. I can only assume that you are referring to Windows, Raw Input or Direct Input, with Native Keyboard Handling enabled.

    I already posted above an explanation of how keyboard input is processed in Windows, Raw/Direct Input with Native Keyboard Handling enabled.

    What you are seeing in Unity is the same thing you are seeing in Rewired. Unity is also queuing up key input events sent by Windows every update cycle. It obviously isn't processing that queue until Editor Play is resumed.

    Rewired has its own, very complex system for working in the editor in Windows. It is very complex because it has to work under so many different scenarios including in Edit mode, in docked or separated game Windows, in the Scene view in edit mode, in focus, out of focus, detecting specific editor windows being in focus or not, etc, etc. Every single thing Rewired does in the editor was figured out by trial and error. There's is necessarily a lot of hackery involved in application and window focus detection because Rewired does not have access to the Unity source code, so it has to use a combination of the very sparse information available through the Unity API and through whatever information it can glean from the Windows API about the current application. Rewired is not going to work 100% exactly like Unity does because it just doesn't have access to the same information Unity does about the internals of the editor application. In addition, Rewired HAS to run off of Unity's main Update loop and cannot run outside of it like the Unity editor potentially can do (when you press Pause, Unity has the luxury of still updating and processing some code paths in the system every cycle or reading certain Unity variables regardless of whether or not its paused -- Rewired can't do that except on other threads which are very restricted in what they can do when interacting with the Unity API.)

    The only setting in Rewired that can affect how input is handled with regard to focus is "Ignore Input When App Not in Focus":
    http://guavaman.com/projects/rewired/docs/RewiredEditor.html#Settings

    The Unity Player setting of "Update in Background" affects whether or not this is possible as well since Rewired is subject to updating only when Unity allows it.
     
    Last edited: Apr 9, 2019
  16. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,243
    @TommiH Specifically, in this scenario, there's a cascade of things leading to this result. It all boils down to the fact that Rewired isn't allowed to update itself when you pause the editor, nor does it even know that you paused it. Everything in the code that is dependent upon checking states of any watched Unity variables breaks down as does any reliance on Unity runtime events such as MonoBehaviour.OnApplicationFocus. The checks to determine if input should be allowed and events queued under these circumstances fail because Unity is paused and all the values it relies on to know that information were not updated after the time of pausing. The only way to handle this scenario is to somehow be able to detect the special case of explicit editor pausing within the runtime DLL (no UnityEditor.dll dependency) and implement special-case code specifically to handle editor pausing and unpausing.
     
    Last edited: Apr 9, 2019
  17. TommiH

    TommiH

    Joined:
    Jan 14, 2008
    Posts:
    252
    Thanks for the detailed explanation, and sorry, I didn't notice you editing in the initial explanation in your initial reply.

    Since builds cannot be paused the way the editor is, I assume this problem won't be possible in them, which is good. So it's just us using the editor that have to deal with this. For now, I've just stopped using Rewired for this cheat code. I very often pause the game and then alt-tab to discuss with my team mates in a chat etc. and getting a mission skipped when I got back was pretty annoying. But at least I know why it happens now. A shame that this can't be fixed, but nonetheless, thanks for your continued work on making our lives easier when it comes to handling input!
     
  18. joe_ftg

    joe_ftg

    Joined:
    Nov 9, 2015
    Posts:
    42
    Hi, I've got a keyboard related issue where holding W then Left Shift works correctly, but holding Left Shift then W does nothing. It is the same with S, but A and D are fine.

    It's not a hardware issue, as Rewired displays the keys being pressed in the debug information, but the actions (Sprint and MoveUpKey) are not getting set (in the debug information) (see attached).

    The Sprint action is 1 while I hold Shift until I also hold W at which point both reset to 0.

    If I map the Sprint action to any other key such as Left Ctrl, it works fine. It's driving me crazy! Any ideas?

    rewired1.PNG rewired2.PNG rewired3.PNG rewired4.PNG
     
  19. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,243
    The only way possible for an Action to ignore a key being down is if there is an Action in one of your Keyboard Maps that binds a key combination of Modifier + Key. It doesn't have to be on the same Keyboard Map. The presence of that mapping will block the other Action bound to only the Key if the Modifier is currently held down.
     
  20. f1chris

    f1chris

    Joined:
    Sep 21, 2013
    Posts:
    308
    I reset my layout to factory settings with same results.

    I'll wait for your "cantered" solution on next update and will see from there. If same results, I'll produce the log.
     
  21. joe_ftg

    joe_ftg

    Joined:
    Nov 9, 2015
    Posts:
    42
    Yes, that was it. Thanks!
     
  22. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,243
    I'm not sure when the next update will be. If you want to try a beta, contact me here:
    http://guavaman.com/rewired#support
     
    f1chris likes this.
  23. shadiradio

    shadiradio

    Joined:
    Jun 22, 2013
    Posts:
    76
    Well, for what it's worth, I'm incredibly grateful for Rewired and all your hard work & patient support. It is by far, the most indispensable plugin and an automatic install for every new project. I believe that for many projects, Rewired can literally save teams years of work and research (especially for multiplayer titles). Thanks!
     
    guavaman likes this.
  24. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,243
    Thank you! It means a lot to me! :)
     
  25. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,243
    I have found a way using a a class that is instantiated by a script in the Unity project using #if UNITY_EDITOR directives passed to the DLL as an interface to detect editor pausing and execute special case code. I am able to clear pending keyboard/mouse input events and block new incoming ones while the editor is paused. However, any existing Action values or Keyboard key values will not be cleared on editor pause. This would block the new keys pressed while paused from causing events to be fired on the frame after unpause. I can't guarantee this will solve your use case, but it addresses the underlying issue.
     
  26. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,243
    Rewired 1.1.25.1 is now available on the Unity Asset Store:

    See Updating Rewired before updating.

    1.1.25.1:

    Changes:
    - Rewired Editor: Changed popup window positioning system due to non-reproducible window centering Unity editor bug reported. Popup windows are now positioned in a fixed location in the editor window.
    - Unity Editor, Windows Standalone, Native Keyboard Handling and/or Native Mouse Handling: Pausing runtime Play mode in the Unity Editor now clears keyboard and mouse input queue and blocks further input from being queued while paused.
     
  27. f1chris

    f1chris

    Joined:
    Sep 21, 2013
    Posts:
    308
    I can confirm the Popup window positioning issue is now fixed. Tested in both of my projects where I had the same problem.

    Thx again for the super quick fix !!
     
  28. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,243
    Glad it works. Add that to the mental list of perfectly legitimate things I can't do in my code base -- call Screen.width or Screen.height in an Editor window. The list just keeps on getting longer and longer.
     
    Last edited: Apr 11, 2019
    f1chris likes this.
  29. jons190

    jons190

    Joined:
    Sep 13, 2016
    Posts:
    252
    HI all! I have a question fro the group! Has anyone here successfully used rewired to set up any type of VR controllers? And if so, what were your best practices? I've read the rewired docs and it seems possialbe but before I get to hacking at my code (with my very limited code knowledge) I thought i wold ask here first.

    I have rewired setup on a gearvr/Go game (android based with Unity) and it works great with a standard bluetooth gamepad. Gives me about 90% of the functionality I need. BUT I would also like to support the Gear/Go controller. The Go controller ALMOST works (natively???) but the button mapping seems wrong. I'm not sure where to begin in setting up the UNITY input mapper, then setting up the code and making it all play well with Rewired without stepping ont he bluetooth code.

    Anyway, Thought I would ask first, surely someone has done this before me....

    Cheers mates!
     
  30. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,243
    This is stack of different questions and issues all rolled up into one. I'm going to do my best to unroll this and explain things.

    1) There's no one universal way of supporting VR controllers. Every controller is different, the way they're detected on different platforms is different. It is a case-by-case issue, per-platform, per-device. Therefore, the way of using them is going to vary just as widely.

    >> The Go controller ALMOST works (natively???)

    2) The fact that you're even seeing the Go controller on Android puts it into a different category than other devices. Rewired uses UnityEngine.Input as the source of all input on Android. If the Go controller is appearing at all to Rewired ,that's only because Unity has done something to make it appear. These things are not standard HID devices that you can support simply through HID or gamepad API. Unity must be wrapping the native SDK for this device and exposing it as a Joystick through UnityEngine.Input. That's the only way Rewired would see it.

    >> but the button mapping seems wrong.

    3) If Rewired is detecting any kind of input from this device without you first mapping it in-game (unless you have an Unknown Controller map defined), then you have "Support Unknown Gamepads" enabled in the Rewired Editor -> Settings -> Android page. This option exists to make MOST gamepads just work, but it has significant downsides that essentially makes those devices that do not conform to the standardized Android API Gamepad template not work correctly. Sounds like your Go device is one of these. It's unrecognized so it's being treated as a standardized gamepad as your options tell it to, but the device doesn't map to Android's Gamepad layout and therefore it's not working as you expect. There's no way to fix this but to A) disable that option (which has consequences) or B) make a Controller Definition for it so it can be recognized.

    4) Even if you (or more likely I) make a Controller Definition for this controller, there's no guarantee it's going to work unless Unity exposed all the special controls on it somehow through joystick axes. For example, the touch pad. If they don't expose these as joystick-like axes where left is -1 and right is +1, it's going to be a big problem.

    5) If the concerns in #4 are true, the only option is to support the device through the native SDK (or whatever native way this device is supposed to be normally accessed in Android) and write a Custom Controller script and make a Custom Controller to get the data and pipe it into Rewired. Then you would want to somehow detect and deal with the other Joystick that's appearing.

    I can't tell you exactly what to do without having the device, seeing exactly how it works, how it shows up to Unity, and what data is available from it. Only then would I know whether it would be better to support it through UnityEngine.Input as a joystick or use a Custom Controller to feed the data in.
     
    Last edited: Apr 13, 2019
    jons190 likes this.
  31. mdsitton

    mdsitton

    Joined:
    Jan 27, 2018
    Posts:
    36
    I'm having an issue with the new XInputGuitar hardware map. Mainly with whammy, the calibration seems to alter the raw axis value in the debug info. Basically how it shows in the control mapper is that we are unable to get axis data below 0. Anything from -1 to 0 is ignored, and the default calibration setup to make sure -1 is mapped to 0 causes this new forced 0 point to push the calibrated resting axis position above 0.

    Any ideas, i looked through the Asset file and everything seems fine (other than it being located in the wrong location in the new update
    assets/Rewired/Internal/data/controllers/HardwareMaps/Joysticks
    instead of
    assets/Plugins/Rewired/Internal/data/controllers/HardwareMaps/Joysticks
    )
     

    Attached Files:

  32. mdsitton

    mdsitton

    Joined:
    Jan 27, 2018
    Posts:
    36
    Also when i delete the guitar hardware map, and add the guitar sub-types into the MicrosoftXbox360.asset file along with the calibration values used in the guitar map the same issue occurs. No more full range motion. With the calibration disabled in the asset the full range of motion is available and calibrating in game works properly with the same settings applied.
     
  33. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,243
    Wrong file location:
    http://guavaman.com/projects/rewired/docs/Updating.html

    I cannot control where Unity extracts files from Unitypackages.

    A Controller Definition cannot alter the raw value data in a Controller axis. Raw is raw. If you are referring to player.GetAxisRaw, that's an Action value and entirely different and does not ignore axis calibration: http://guavaman.com/projects/rewired/docs/api-reference/html/Overload_Rewired_Player_GetAxisRaw.htm
     
  34. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,243
    It sounds to me like the calibration settings are wrong. Use this tool to get the raw data and tell me what it returns for each position of the whammy bar:
    https://www.dropbox.com/s/urbh1cqkwkws23b/XInputJoystickElementIdentifier.zip?dl=0

    At rest:
    Full down (while holding the guitar as if playing it):
    Full up:

    At runtime, when you press the "Calibrate" button in Control Mapper, you will be able to map the whole range of the element properly, then set invert if necessary.
     
  35. f0ff886f

    f0ff886f

    Joined:
    Nov 1, 2015
    Posts:
    181
    Question, I was recently trying to identify why entering Play Mode takes so long in my editor (2018.3.11f1, Rewired 1.1.24 U2018)

    One thing I found is a huge (recursive?) callstack in Rewired, and I'm not sure what it is / why its happening:

    upload_2019-4-14_12-53-3.png

    As you can see its taking about 6s on the profiler time. I don't think I'm doing anything terribly abusive (single player game, just using Player0, no fanciness). Do you have any idea what this could be coming from?

    I managed to extend it so far:
    upload_2019-4-14_12-55-12.png
     
  36. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,479
    The latest Rewired is version 1.1.25.1

    From the Rewired documentation it sounds like this issue.

    https://guavaman.com/projects/rewired/docs/KnownIssues.html#increased-compile-play-time-editor
     
    Last edited: Apr 14, 2019
    guavaman and f0ff886f like this.
  37. f0ff886f

    f0ff886f

    Joined:
    Nov 1, 2015
    Posts:
    181
    Thank you!!! I check and it saves me about a second without the profiler turned on, so not as much as I was hoping, but that completely clears up this problem.
     
  38. jason07

    jason07

    Joined:
    May 10, 2011
    Posts:
    33
    Hi,

    I'm trying to detect whether the current input is from a joystick or mouse, I don't care what action was executed. I've gone through the Rewired documentation on Getting contributing input sources for an Action, but since my programming skills aren't the best I'm stuck on how to move forward. I'm pasting what I have started below and any suggestions on what to do next is much appreciated:

    Code (CSharp):
    1. using UnityEngine;
    2. using Rewired;
    3.  
    4. public class ControllerOrMouseCheck : MonoBehaviour {
    5.    
    6.     public bool IsCurrentInputSource(int actionId, ControllerType controllerType)
    7.  
    8.     void Update() {
    9.         if(/*input was from joystick*/) {
    10.             Debug.Log("Input was from Joystick");
    11.  
    12.         }
    13.  
    14.          if(/*input was from mouse*/) {
    15.             Debug.Log("Input was from mouse");
    16.         }
    17.     }
    18. }
     
  39. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,243
    If you don't care about the Action, don't use the Action system.

    Look at this:
    http://guavaman.com/projects/rewired/docs/HowTos.html#last-used-controller
     
    jason07 likes this.
  40. xelanoimis

    xelanoimis

    Joined:
    Oct 29, 2013
    Posts:
    35
    Hi, I'm having some troubles with the LoadDefaultMaps - I hope you can help with an idea if possible.

    In my controls config page I want a button (for each of the 4 players) to reset all the mappings to default values (I support remapping). Players may assign either a keyboard or a joystick and they can change the mapping for any of them, depending which is assigned. I keep the joystick mapping and apply it when assign another joystick, to keep the player's preferences (I use templates for known joysticks).

    If I have a joystick assigned, player.controllers.maps.GetAllMaps return the mappings both for joystick and for keyboard. LoadDefaultMaps resets that joystick and keyboard.

    However, if the keyboard is assigned, player.controllers.maps.GetAllMaps only returns mappings for keyboard. LoadDefaultMaps only resets the keyboard. When I assign the joystick back, I get the old custom remapped values for the joystick.

    If I involve a second joystick, it seems that each player remembers the mapping for each joystick individually. If I reset the mappings for joystick1 (and keyboard), then assign joystick 2, I get back the custom mapping for joystick 2.


    So, please let me know if there's a way to reset all the mappings to default values for a player, for all the joysticks, even when no joystick is assigned?

    My alternative would be to do the LoadDefaultMaps after a joystick is assigned. Or to store and use the default mapping values like I do with custom mappings.

    rewired version 1.1.24.0.U2018
    Thanks!
     
  41. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,243
    What you are describing is the result of the Joystick Map history system in a Player.
    1. When a Joystick is not assigned to a Player, there are no Joystick Maps loaded in that Player for that Joystick.
    2. When you assign a Joystick to the Player, the Joystick Maps applicable to that Joystick are loaded in the Player at that time from the Rewired Input Manager.
    3. When you make mapping changes to those Joystick Maps and then unassign the Joystick from the Player, the Joystick Maps for that Joystick are stored in a session history in the Player and the Joystick Maps cleared from the Player. This is done so that the next time that Joystick is reattached, the previously-modified maps are used instead of loading the defaults from the Rewired Input Manager again, wiping out whatever changes they had made during the same session.
    4. This history is session-only. Rewired does not force the use of a persistent map storage system like UserDataStore or something custom. This history system will function without regard to XML/JSON saving/loading. User mappings will not be lost when a Joystick is disconnected and reconnected for whatever reason (battery dies, controller sleeps, etc.)
    5. You cannot clear the Joystick Map history in a Player.
    6. All functions that affect Controller Maps in a Player affect only those Controller Maps that are currently loaded at the time that function is called. This includes player.LoadDefaultMaps.
    7. I do not have a viable solution to suggest to you for this issue. Resetting all Joystick Maps, those loaded and those not currently loaded, to a default value is not a function available in Rewired. Your users will have to reset the values to default again after they plug the controller back in in this case if that's the result they want.
     
    Last edited: Apr 17, 2019
  42. xelanoimis

    xelanoimis

    Joined:
    Oct 29, 2013
    Posts:
    35
    Thank you for the details!

    My goal was for players with known controllers (e.g. xbox360) to only set their remap preferences once. That's why I keep the xml mapping in a string after they remap and I apply to all devices when assigned. Basically I have 3 categories: known joysticks, unknown joysticks, and keyboard. These mappings I also save on disk for each player to remember. But I wanted the reset to take a player back to its defaults.

    I think it's still doable, if I store the original xml mapping when I connect a known/unknown/keyboard device the first time. And replace the custom mappings with the original ones when reset, instead of calling LoadDefaultMaps, which would not reset unassigned joysticks. Second potion would be to clear my custom mappings (kept as xml in my strings) on reset and call LoadDefaultMaps when device is assigned.

    One question, is the LoadDefaultMaps heavy? Does it load from the internal assets, from the hard disk? Or it just have the mapping in memory and does the same workload as adding a map from an xml string?


    Also as feedback for future versions, Rewired would be really great if it would give more low-level access to its structures.

    Input devices handling is tricky and there's no perfect way to do it. It would be best to allow users to adapt this logic to their game. For example it's impossible to know why a player wants to remap. Some may have a known joystick with a broken button, others may have an unknown joystick and trying to map it as the classic ones, and some other players may just prefer to inverse two buttons for accessibility. In my case, I favor user preferences, assuming they will have known joysticks and they just want to use a different scheme than what I proposed as default.

    Anyways, the greatest advantage of the library is that you take popular controllers and offer internal mappings to have them working as classic joysticks (like xbox360). The template mappings were a really great addition! So what is missing is a lower-level api, functions to access the mapping definitions created in rewired editor and let the users apply them to assigned controllers (as templates if they are known controllers). Just something to think for future versions.

    Thanks again for your help!
     
  43. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    150
    Hi.
    It seems Mouse.GetButtonDoublePressDown never returns true, as well as Mouse.GetButtonDoublePressHold
    I tried the following code
    Code (CSharp):
    1. if (player.mouse.GetButtonDown(0))
    2.     Debug.Log("Single LMB");
    3.  
    4. if (player.mouse.GetButtonDoublePressDown(0))
    5.     Debug.Log("Double LMB");
    I can see "Single LMB", but not "Double LMB". The settings for double press duration are default (0.3).
     
    Last edited: Apr 17, 2019
  44. sledgeweb

    sledgeweb

    Joined:
    Sep 9, 2016
    Posts:
    25
    I'm REALLY LOVING Rewired, but I'm having trouble figure one last thing out... and I'm not sure if its a Rewired issue or a Unity issue, but hoping somewhere can help.

    I'm trying to get my menus set up for controller/keyboard support. They work fine when I use a mouse.

    The flow goes like this... when you start the game there is a disclaimer/info screen that has a CONTINUE button. This button is highlighted at start using the EventSystem input. So, I can press X on a controller, or ENTER on keyboard, or press left click on mouse and it will fade that panel out, revealing the main menu (both screen are on the same canvas).

    Here's where I'm having trouble. In that main menu, I want the first button, which is NEW GAME, to be highlighed by default (or at least highlight when I move the controller stick up/down). If I click on the CONTINUE button with my mouse, NEW GAME is highlighted. This is because the OnClick runs a little script that set New Button to Selected.

    However, if I click with the controller or keyboard, the NEW GAME button is not highlighted. I did some digging and found out this is maybe due to OnClick not executing, and that I need to set up an event trigger. So, I set an event trigger for Submit, and I put the same script hookup in there to set new button to be selected. But, I cannot get this to work! NEW GAME button is only highlighted if I use the mouse.

    Right now, I have no Player Mouse set up, I'm just using the default. But, I have tried setting up a Player Mouse, and I've tried setting it up as System Player and Player 0. I've tried creating maps just for system player, and just for player 0, and having them set up with actions for UISubmit. But I've not been able to find any combination that seems to work.

    Does anyone here have an idea of what I'm doing wrong?
     
  45. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,243
    It sounds to me like what you are trying to do can be handled much more easily by saving and loading data as Controller Templates:
    http://guavaman.com/projects/rewire...ving-and-loading-controller-template-mappings
    1. When the user remaps their controls on a recognized gamepad, you convert it to a Gamepad Template map and save that to XML/JSON.
    2. Every time a Joystick is assigned to a Player, you load the saved mapping if found.
    3. If no saved map is found, call LoadDefaultMaps on the Player to clear the Joystick Map Memory.
    4. When resetting to defaults while no Joystick is assigned, clear your saved Gamepad Template mapping from your data storage system. Since it's a Controller Template, you can even clear the mapping individually from PlayerPrefs because there's only going to be one key per Player.

    Rewired loads the data from the Rewired Input Manager MonoBehaviour component. It uses Unity's serialization system entirely. How that works at a low level is up to how Unity handles its serialized data.

    You can already do this manually in several ways:
    http://guavaman.com/projects/rewired/docs/HowTos.html#loading-controller-maps-runtime
    http://guavaman.com/projects/rewired/docs/HowTos.html#get-mappings-for-joystick-not-attached

    If you are referring to being able to CHANGE the runtime definitions in the Rewired Input Manager, that's not going to happen. That goes directly against the design of the Rewired Input Manager system. It was designed as a database of default mappings the developer sets up in the editor. This information is intentionally static and unchangeable at runtime. User modifications are handled through the XML/JSON saving/loading system, resulting in two different sources of mapping information -- defaults and user.
     
  46. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,243
    Two things:
    1. This is a bug that it's not working with no Speed value passed.
    2. However, there is no user-definable default duration setting for a Controller Button double press. What you are referring to is the InputBehavior setting which does not affect Controllers in any way. Input Behaviors affect only ACTIONs in Players. This is an entirely separate system that exists on top of Controllers. Controllers don't know anything about the Player or Action systems. Controller values are consumed by Players to determine Action values using Input Behaviors as a means for setting certain properties for that Action. Calling player.GetButtonDoublePressDown would take the InputBehavior settings into account for the Action's double-press value, but the Controller.Button will not do so.

    The issue only occurs when using the overloads with no user-defined speed setting passed in. Pass a speed value of 0.3f into both of these methods and they will work.
     
  47. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,243
    I'm glad you like Rewired.

    This is not a Rewired issue. This is purely a Unity UI usage issue. At the point the UI events are sent out from the RewiredStandaloneInputModule, control is completely out of Rewired's hands and into Unity UI's. In addition, the EventSystem is not customized by Rewired in any way. How the EventSystem works is all Unity. The only thing the RewiredStandaloneInputModule does is read input values from Players and send out events to the UI system. If there is no current EventSystem.currentSelectedGameObject, it won't send out any UI Navigation events, just like the StandaloneInputModule won't.

    You must set the Button you want highlighted yourself in a script using EventSystem.current.SetSelectedGameObject when changing pages in the UI. It sounds like your problem here is when/how you are setting this. You don't have to do it in OnClick on a Button in your previous menu. You could also do it in OnEnable in your new menu. Or else have the new menu check the state of EventSystem.current.currentSelectedGameObject in Update to detect when nothing currently enabled is selected and select some default. There are many ways to deal with this issue.

    The Button component's inspector-exposed "On Click" event will fire both when OnSubmit is sent from a Keyboard/Joystick Submit event and when OnPointerClick is sent from a mouse click event. The same is not true for the "Pointer Click" event on an Event Trigger component added to the Button. Event Trigger "Submit" will respond to Keyboard/Joystick Submit events, but it will not respond to mouse click events. You need to use both if you are overriding a Button's events with an Event Trigger. This is how Unity UI's events work.
     
    Last edited: Apr 17, 2019
  48. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    150
    Got it! Thanks for a quick response and keep up your good work.
     
  49. xelanoimis

    xelanoimis

    Joined:
    Oct 29, 2013
    Posts:
    35
    Yes, that's exactly what I'm doing, using the templates for known joysticks - love the templates :) I also store the mappings for the keyboard and unknown joysticks (even though 2 unknown joysticks may differ in mappings) and use the appropriate one based on what controller type was assigned.

    If you say that LoadDefaultMaps reads from the rewired manager component, that should be fast enough too (that data is part of a scene object and it is loaded into memory by Unity at start).

    Thanks for the validation!
     
  50. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,243
    I saw you mention Controller Templates several times but didn't get that you were already converting the maps to Controller Template maps. So it sounds to me like calling LoadDefaultMaps on assignment is the best solution. (Or load the map/template instances directly for the current category/layouts that are in use and assign them.)

    In case you weren't already aware, events were added to the Player for controller assignment/unassignment in a recent version of Rewired:
    http://guavaman.com/projects/rewired/docs/HowTos.html#assigning-controllers
     
unityunity