Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

Rewired - Advanced Input for Unity

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

  1. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,882
  2. Wikzo-DK

    Wikzo-DK

    Joined:
    Sep 6, 2012
    Posts:
    77
    I already have that, but in the rumble documentation for Rewired I can only find this method:


    player.SetVibration(motorIndex, motorLevel, duration);


    It works, but how can I specify the high and low frequencies? With the native NintendoSDK, I can do the following:


    VibrationValue rumble;
    rumble.amplitudeHigh = 1f;
    rumble.amplitudeLow = 0.5f;
     
  3. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,882
    Look at the documentation that came with the Nintendo Switch Plugin. The documentation location is shown in the text file in the plugin zip.

    Nothing Switch-related is online due to NDA. If you need help with the Nintendo Switch plugin, contact me through the website.
     
  4. Wikzo-DK

    Wikzo-DK

    Joined:
    Sep 6, 2012
    Posts:
    77
    Ahh, got it. Thanks! Didn't even consider looking into that folder. Maybe consider adding a note on the online website that the documentation is part of the plugins folder? :)
     
  5. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,882
    Glad you found it. I think having the documentation location listed the instructions is enough. One must read them to install it properly. Edit: I have absolutely no idea how, but it appears the documentation link is no longer included in the instructions file. That makes no sense. I will put it back.
     
    Last edited: Nov 1, 2018
  6. slumtrimpet

    slumtrimpet

    Joined:
    Mar 18, 2014
    Posts:
    345
  7. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,882
  8. T0T0S

    T0T0S

    Joined:
    Nov 30, 2015
    Posts:
    3
    Hello!
    I was just wondering if there were news about native input being supported using .NET 4.6 backend ?
     
  9. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,882
    Native input has always worked in Windows using the .Net 4.6 backend. The critical editor bug listed here was fixed in 2017.1.p4 as it states.

    The issues with the .Net 4.6 backend listed here are Unity issues and not something I can workaround or do anything about. Fixing of these issues is entirely dependent upon Unity fixing these bugs. For example, at the time of writing, the OSX .Net 4.6 backend simply failed every single extern call through Dllimport, a critical feature of .Net required to make calls out to external DLLs. There can be no possible native input without this feature of .Net working. These issues are not about Rewired, they're about Unity. I'm not tracking Unity's progress on all these issues in their systems that happen to also affect Rewired every time they update Unity. It's very possible they've been fixed by now, but I don't know. You could check the Unity release notes. Edit: I have looked through all their release notes and can't find anything. Yet they did say they acknowledged the error when I reported it on 2017.2 and would send it to the developers for resolution. My only choice is to download every version of Unity released since 2017.2 and re-test.
     
    Last edited: Nov 4, 2018
  10. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,882
    After testing, the critical OSX issue was fixed in 2017.4.1f1.
     
    Last edited: Nov 4, 2018
  11. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,882
    The Windows 4.6 backend crash on exit issue appears to have been resolved somewhere in the 2017 branch and never affected the 2018 branch (resolved by the time the released 2018.1).

    As far as I can tell, all of the identified .Net 4.6 issues I was aware of have been resolved by Unity.
     
    MrG and Bartolomeus755 like this.
  12. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,882
    Rewired 1.1.20.0 is now available on the Unity Asset Store.

    Please see Updating Rewired before updating.

    1.1.20.0:

    Changes:
    - Windows Standalone, XInput: Vibration output moved to the input thread to reduce performance spike when setting vibration values on some XInput devices.
    - Xbox One: Added logging to report when the required Gamepad.dll has not been installed for newer versions of Unity that no longer crash when an exception is thrown on an extern function call.
    - Xbox One: Not installing the required Gamepad.dll will no longer cause GC every frame as exceptions are thrown and swallowed.
    - PS4: Changed controller monitoring system to eliminate memory allocations.
    - Changed virtual button system used for Player.GetButtonTimedPress, Player.GetButtonDoublePress, Player.GetButtonRepeating, etc., to require a button down state to initiate the special button press type. This prevents special button state tracking from initiating after a button press that enabled the Controller Map containing the bindings to the Action being queried for the special button state.
    - Added Universal Fighting Engine 2 integration.
    - Control Mapper: Added theming for more calibration window elements.
    - All controller vibration is now stopped when application loses focus and Run In Backround is disabled in Unity Player settings.

    New Controller Definitions:
    - Thrustmaster FireStorm Dual Power

    Modified Controller Definitions:
    - Thrustmaster Dual Analog 3: Changed dead zone.
    - 3Dconnexion Space Mouse, OSX Native: Fixed incorrect axis mappings.
    - Nintendo Switch Handheld: Changed all element names to match terminology guidelines.
    - Nintendo Switch Joy-Con (L): Changed all element names to match terminology guidelines.
    - Nintendo Switch Joy-Con (R): Changed all element names to match terminology guidelines.
    - Nintendo Switch Joy-Con (Dual): Changed all element names to match terminology guidelines.
    - Nintendo Switch Pro Controller: Changed all element names to match terminology guidelines.
    - 8Bitdo NES 30 Pro: Added support for AP 40 controller.

    New PlayMaker Actions:
    - RewiredJoystickSetVibration
    - RewiredJoystickStopVibration

    New Behavior Designer Actions:
    - RewiredJoystickSetVibration
    - RewiredJoystickStopVibration

    Bug Fixes:
    - Fixed missing Tooltip attribute compiler error in Unity 4.3.x - 4.5.x.
    - Control Mapper: Theme custom Invert Toggle sprite now works correctly.
    - Fixed Player.GetButtonTimedPressUp not working when expireIn set and Activate Action Buttons on Negative Value enabled in Rewired Input Manager Settings.
    - Unity Windows Editor, Raw Input / Direct Input + Native Mouse Handling: Tearing the Game panel off while Rewired is running no longer causes the mouse to stop to working in Game window.
    - Build, Windows Standalone, Raw Input / Direct Input + Native Mouse Handling: Mouse clicks in the title bar of the application in windowed mode no longer return mouse button events in Unity 2017+.
    - Fixed 40 byte memory allocation per frame in Unity 2018+.
    - Xbox One, Mono Scripting Backend: Added workarounds for a bug in Unity's Xbox One Mono implementation causing it to throw a System Execution Engine exception (Attempting to JIT compile method) on legal code used in internal SerializedObject class used in XML and JSON handling added in 1.1.18.0.
     
  13. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,459
    I will have to look into Control Mapper theme options in more detail. More to test this weekend. :)
     
  14. MaccyDBoy

    MaccyDBoy

    Joined:
    May 25, 2017
    Posts:
    29
    Hi @guavaman !

    I wanted to have some info about the integration with the Corgi Engine.

    I did everything as told in the docs and all works smooth as butter ! But here's what bothering me, i don't understand how corgi engine MMInput communication with Rewired. that would help me create other controls easily.

    If you can explain to me the basics of how rewired communicates with Corgi Engine or if you can point me in the good direction so i can easily modify/create buttons actions in corgi engine so they can reflect on rewired.

    Sorry if i'm not very clear, but it is not easy to explain ! haha Thanks :)
     
  15. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,882
    The Rewired integration for Corgi Engine extends the MoreMountains.CorgiEngine.InputManager class. How everything works is based entirely on Corgi Engine's input manager system. Nothing has been done to provide you with an "easier" way to add Actions to Corgi Engine without modifying the source code. That's the way Corgi Engine works so that's the way the Rewired integration works. Look at the source code to InputManager.cs and RewiredCorgiEngineInputManager.cs. You will need to add variables to InputManager for the new actions, and then initialize them in InitializeButtons and InitializeAxis in RewiredCorgiEngineInputManager because the Rewired version extends the Corgi Engine version. Of course you will also have to add the Actions to the Rewired Input Manager and set up the Controller Maps as usual.
     
    MaccyDBoy likes this.
  16. MaccyDBoy

    MaccyDBoy

    Joined:
    May 25, 2017
    Posts:
    29
    AAAAAAAAAAAAAAAAAAAAAAAH that makes a lot of sense.

    Thank you gentleman
     
  17. Lone-Coder

    Lone-Coder

    Joined:
    Sep 8, 2012
    Posts:
    59
  18. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,882
    I would suggest you copy the RewiredCorgiEngineInputManager.cs, rename it, and move it to somewhere outside the Rewired folder. This way you can update Rewired and your changes won't be destroyed. You'll have to replace the RewiredCorgiEngineInputManager component with your new copy on the GameObject where you put it.
     
  19. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,882
    That would require a complete built-in glyph system including glyph database, integration into the Action Element Map system, etc. It would very incomplete without glyphs for other controllers such as HOTAS, etc. And because of localization, it also requires that I create a complete localization system to go along with it all because people are going to want different glyphs for different regions. It would need to handle all kinds of requirements such as animated glyphs and glyphs depicting directional movements on joysticks. That's a lot of work to design and build all those systems and make them open enough for people to customize everything the way they want. It's been on the todo list for several years, but I have not had time to get to it because of so many other things of higher priority.
     
  20. Lone-Coder

    Lone-Coder

    Joined:
    Sep 8, 2012
    Posts:
    59
    Thanks for the reply. I understand it's a big request.

    An incomplete implementation would be better than nothing. Perhaps there could be fallbacks of some kind for the exotic controllers.
     
  21. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,882
    Actually, an incomplete implementation would result in angry customers. I've learned never to add anything without completely fleshing it out and providing as many possible features as I can pack into it to try to cover all the use cases. If someone has to replace the system because it can't do the thing they want it to do, they'll leave a bad review.

    An incomplete implementation also makes it far harder to change in the future and make a complete, proper implementation and keep compatibility. The API would be baked in for eternity. I've never removed anything from Rewired's API in all these years. I do not add things to Rewired that are intended to be stop-gaps or temporary for removal later. It has to be right when it's added or I won't add it.

    The docs cover how to make one for yourself (including code) that doesn't need to have all the extreme flexibility of a generic one for every use case. Consider this the incomplete implementation:
    http://guavaman.com/projects/rewired/docs/HowTos.html#display-glyph-for-action
    http://guavaman.com/projects/rewired/docs/HowTos.html#display-glyph-for-active-elements

    This is still on the to-do list, but there are many things of much higher priority on it such as desktop IL2CPP compatibility and rewriting the controller definition data system. I don't see getting to built-in glyph or localization systems any time soon.
     
    Last edited: Nov 8, 2018
    arvzg likes this.
  22. Kadaiyen

    Kadaiyen

    Joined:
    Jul 16, 2012
    Posts:
    14
    Is there a preferred way to handle AI through Rewired? Sorry if this has already been discussed, the forum search features refuse to let me search by AI, NPC, etc. :(

    My use case might include routing many AIs' actions through Rewired input to share motor components across all actors, for example. Is that something that's possible, or even recommended through Rewired?

    Thanks!
     
  23. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,882
    I do not recommend you handle AI through the input system. If you really want to, the only way you can is through Custom Controllers:
    http://guavaman.com/projects/rewired/docs/CustomControllers.html
     
  24. Kadaiyen

    Kadaiyen

    Joined:
    Jul 16, 2012
    Posts:
    14
    Understood. Thanks!
     
  25. blurdot

    blurdot

    Joined:
    Jan 26, 2014
    Posts:
    20
    Hi there @guavaman, I recently tried to use an AssemblyDef for rewired, but now I get the error below whenever I stop play in the editor, it only happens when rewired is inside a folder that has an Assembly Definition....any ideas?:

    Rewired: Unable to find class Rewired.Editor.UnityEditorBridge! You may see this error if you have compile errors in other scripts when you start Unity. Fix the compile errors. If you have no other compile errors, please reinstall Rewired.
    ------- Rewired System Info -------
    Unity version: 2018.2.14f1
    Rewired version: 1.0.0.91.U5
    Platform: Windows
    Editor Platform: Windows
    Using Unity input: False

    0x000000014153A9C8 (Unity) StackWalker::GetCurrentCallstack
    0x0000000141540F06 (Unity) StackWalker::ShowCallstack
    0x000000014140FEFB (Unity) GetStacktrace
    0x00000001408B14D0 (Unity) DebugStringToFile
    0x00000001418DFBE8 (Unity) DebugLogHandler_CUSTOM_Internal_Log
    0x000000002F7B9730 (Mono JIT Code) (wrapper managed-to-native) UnityEngine.DebugLogHandler:Internal_Log (UnityEngine.LogType,string,UnityEngine.Object)
    0x000000002F7B9393 (Mono JIT Code) [DebugLogHandler.cs:10] UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
    0x000000002F7B8C15 (Mono JIT Code) [Logger.cs:48] UnityEngine.Logger:Log (UnityEngine.LogType,object)
    0x000000002F7B88A9 (Mono JIT Code) [Debug.bindings.cs:117] UnityEngine.Debug:LogError (object)
    0x000000002F7B7DCB (Mono JIT Code) Rewired.Logger:LogError (object,bool)
    0x000000002F7B6A0B (Mono JIT Code) Rewired.Editor.EditorManager:‮‬
‪
‍‫‏‬‎‮‌‮‬‎
‎‭‎‭‎‬‭‮ (object,bool)
    0x000000002F7B6023 (Mono JIT Code) Rewired.Editor.EditorManager:lilqySrXTlgqifckymoquEdPPvS ()
    0x000000002F7B330B (Mono JIT Code) Rewired.Editor.EditorManager:CzmHHBvfTKXqIELSDFGVcloojLmD ()
    0x000000002F6E30D3 (Mono JIT Code) Rewired.Editor.EditorManager:JHiZrLlVcaVaVhZboePuCQqDqVN ()
    0x000000002F6E2D47 (Mono JIT Code) (wrapper delegate-invoke) <Module>:invoke_void ()
    0x000000002F6E2A4D (Mono JIT Code) [EditorApplication.cs:191] UnityEditor.EditorApplication:Internal_CallUpdateFunctions ()
    0x000000002F479B65 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void (object,intptr,intptr,intptr)
    0x00007FFA93E2A68B (mono-2.0-bdwgc) [mini-runtime.c:2809] mono_jit_runtime_invoke
    0x00007FFA93DB1BB2 (mono-2.0-bdwgc) [object.c:2915] do_runtime_invoke
    0x00007FFA93DBAB9F (mono-2.0-bdwgc) [object.c:2962] mono_runtime_invoke
    0x0000000140BFBBC7 (Unity) CallStaticMonoMethod
    0x0000000140BFB94E (Unity) CallStaticMonoMethod
    0x00000001413E1453 (Unity) SceneTracker::Update
    0x000000014144D268 (Unity) Application::TickTimer
    0x00000001415ECF85 (Unity) MainMessageLoop
    0x00000001415EF378 (Unity) WinMain
    0x000000014243421A (Unity) __scrt_common_main_seh
    0x00007FFABF1F3034 (KERNEL32) BaseThreadInitThunk
    0x00007FFAC0D81461 (ntdll) RtlUserThreadStart
     
  26. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,882
    blurdot likes this.
  27. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,882
    Last edited: Nov 10, 2018
    blurdot likes this.
  28. blurdot

    blurdot

    Joined:
    Jan 26, 2014
    Posts:
    20
    Ah! Ok, I'll update and see if that fixes it, thanks!
     
  29. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,882
    You were also using the Unity 5 branch of Rewired in Unity 2018. I'm surprised it even worked. You would have definitely gotten API updater problem notices from Unity asking you to update obsolete methods. They've also changed quite a bit of stuff in the editor that would affect a lot of things.
     
    blurdot likes this.
  30. blurdot

    blurdot

    Joined:
    Jan 26, 2014
    Posts:
    20
    I updated and all works perfectly now, thanks!
     
    guavaman likes this.
  31. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,882
    Rewired 1.1.21.0 is now available on the Unity Asset Store.

    Please see Updating Rewired before updating.

    1.1.21.0:

    Changes:
    - Added Simple Combined Keyboard Mouse Remapping example.

    API Changes:
    - Added InputMapper.mappingContext property.
    - Added InputMapper.Options.allowButtonsOnFullAxisAssignment property.

    Bug Fixes:
    - Fixed bug causing mouse buttons to studder intermittently on and off when polled in FixedUpdate on platforms or configurations that use UnityEngine.Input as the source of mouse input.
     
  32. Doghelmer

    Doghelmer

    Joined:
    Aug 30, 2014
    Posts:
    112
    I have a question regarding localization in the Control Mapper: What is the best way to change the text for the buttons that appear in the "Controller", "Keyboard" and "Mouse" columns? For example, if I wanted "Left Stick X" to appear as "Palo izquierdo X". I understand that the rest of the text in Control Mapper can be changed with files like DefaultEnglish, but wasn't sure about the particular button titles.
     
  33. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,882
    There is no localization system built into Rewired for controller, controller element, or Action names. The only way you could do this is to make a lookup table of translated names based on the element identifier ids and change Control Mappers source code to use that instead of using the methods built into ActionElementMap to get the names.

    You can find CSV files of the controllers and controller elements in the documentation here:
    http://guavaman.com/projects/rewired/docs/HowTos.html#display-glyph-for-action

    Control Mapper's localization system only concerns text generated by Control Mapper for its interface, not other text from the rest of the Rewired system.
     
  34. TDragona

    TDragona

    Joined:
    Oct 30, 2016
    Posts:
    1
    In the project I'm working on, we are testing going from Unity 2017.1.1f1 to 2018.3.0b9. Yes we know it's a beta but would like to do that Update. While testing it out, I found out that the Rewired we have in the project seems broken in the sense of multiple errors pop in the console on startup. The most prominent error is that the rewired manager is missing (even though it is still there) and that rewired is not initialize. Any idea of what I could do to help fix this without completely having to delete and reinstall Rewired?
     
  35. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,882
    Without seeing the actual error it reports with stack trace, I can't tell you. You have to update Rewired anyway. You can't use the 2017 branch of Rewired in Unity 2018.

    http://guavaman.com/projects/rewired/docs/Updating.html

    Clean reinstall: (this is not necessary unless you've moved files around within Rewired's folder)
    http://guavaman.com/projects/rewired/docs/Troubleshooting.html#clean-reinstall
     
  36. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,882
    http://guavaman.com/projects/rewired/docs/HowTos.html#last-used-controller
     
  37. emongev

    emongev

    Joined:
    Jul 5, 2012
    Posts:
    29
    Quick question, which ive searched but to no avail :/ Hopefully its a really quick answer

    I have a controller with an X and Y axis.

    Is there anything similar to PositiveXAxis WasPressed, Hold and Was Released?

    EDIT: I seem to have managed to get a similar effect using GetAxis with GetAxisPrev, not sure if this is the best way to go though :)
     
    Last edited: Nov 17, 2018
  38. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,882
    See Negative Buttons:
    http://guavaman.com/projects/rewired/docs/HowTos.html#button-press-types

    Negative Buttons:

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

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

    See Getting Input:
    http://guavaman.com/projects/rewired/docs/HowTos.html#get-input

    Rewired mirrors Unity's method nomenclature for getting input values:
    All Actions can be queried for Button or Axis value regardless of the underlying hardware mapped to that Action.
     
  39. FREEZX

    FREEZX

    Joined:
    Apr 2, 2013
    Posts:
    60
    Hi @guavaman and thanks for making this great plugin. I've been using it for a while now, and i can say i'm a very happy customer!

    I'm having an issue with UWP IL2CPP though - the game crashes on controller disconnects.
    I read through the special platform support section for UWP apps, but i'm not using HID devices, they are disabled in Rewired, build settings, and the manifest. I'm running Unity 2018.2.15 and the current version of Rewired (1.1.21.0, previously i was on an older version with the exact same issue). Based on the stack trace using Unity's debug symbols, it seems like the origin of the issue is in Unity's engine code.

    I think i'm getting the same issue as this person:
    https://shadowndacorner.com/2018/09/03/fixing-a-bug-in-unitys-input-system-by-building-for-release/

    Here's a stack trace screenshot:
     
    Last edited: Nov 18, 2018
  40. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,882
    Awesome! I'm glad you're happy with Rewired! :)

    It most likely is. This must be a new bug if you don't HID device support enabled, but there have been crash problems in Unity's IL2CPP UWP controller handling for a very long time. Here are the ones I documented:
    http://guavaman.com/projects/rewired/docs/KnownIssues.html#uwp-il2cpp-controller-disconnect-crash

    Unfortunately there's no way to disable Unity's controller input.

    There are also some serious bugs in Microsoft's system as well which I discovered but had no way of reporting.
     
    FREEZX likes this.
  41. FREEZX

    FREEZX

    Joined:
    Apr 2, 2013
    Posts:
    60
    Just an update - i found the issue started in 2018.2.0, and it's super simple to reproduce - Just add rewired and an InputManager to an empty project in a new scene. I also reported the bug to Unity. In 2018.1.9 seems like it's working just fine.
     
  42. FREEZX

    FREEZX

    Joined:
    Apr 2, 2013
    Posts:
    60
    Also happens on .NET, so it's not just an IL2CPP issue.
     
  43. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,882
    Thanks. I spent the last 4.5 hours building and testing and going through source code only to come to several conclusions:

    1. It only happens when you have a controller plugged when when you first launch Unity and then unplug it afterwards. Starting the application with no controller plugged in will not lead to a crash when you plug a controller in and then unplug it.

    2. It is easily reproducible in Unity 2018.2.16f1 using nothing but the following script in a project:

    Code (csharp):
    1. using UnityEngine;
    2.  
    3. public class GamepadTest : MonoBehaviour {
    4.  
    5. #if ENABLE_WINMD_SUPPORT
    6.  
    7.     void OnGUI() {
    8.         GUILayout.Label("Gamepad Count: " + Windows.Gaming.Input.Gamepad.Gamepads.Count);
    9.     }
    10.  
    11. #endif
    12. }
    3. This is a bug in Unity (or possibly the Windows UWP API), not Rewired, that occurs after any call is made to Windows.Gaming.Input.Gamepad.

    I can't do anything to make this work. The bug that's causing it is preventing anything outside of Unity itself from interacting with the Gamepad API. Rewired and nothing that uses Windows.Gaming.Input.Gamepad can work with Unity 2018.2.0+ on UWP until Unity fixes this bug.
     
    Last edited: Nov 18, 2018
  44. FREEZX

    FREEZX

    Joined:
    Apr 2, 2013
    Posts:
    60
    I understand. I rolled back my game to 2018.1.9 and all is good. I ranted about this and other issues on the Windows platform forum. Thank you so much for your support!
    https://forum.unity.com/threads/a-r...te-of-uwp-in-unity-2018-2-and-2018-3b.585061/
     
  45. churi24

    churi24

    Joined:
    Sep 17, 2013
    Posts:
    78
    Hi, I have a question..
    I'm using UserDataStore_PlayerPrefs to store the changes on the keyboard.
    The keycode assigned and saved is working.. if we assign "E" to the interaction, the object moves, and if I change to "F", the object moves too, so this is working.
    When I execute this line,
    Code (CSharp):
    1. Debug.Log(ReInput.mapping.GetKeyboardMapInstance(0, 1).GetElementMapsWithAction(idAction)[0].keyboardKeyCode);
    I get the keycode mapped on rewired at the first time ("E"), but not the keycode saved by the player ("F"). Where I will find the keycode saved corresponding to the action?
     
  46. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,882
    All functions in ReInput and child helper classes deal only with default developer-defined data in the Rewired Input Manager, not saved user data overrides.

    UserDataStore provides an interface for saving and loading user-defined data. It is up to your implementation how and where to save and load it. How that data is saved and loaded and what happens to it when Save or Load is called that is up to the UserDataStore implementation. The default included implementation of UserDataStore_PlayerPrefs loads the data directly into Players when loaded. It does not provide an interface for you to preview the Controller Maps, analyze them, make changes, etc., to the saved data. If you want to do that, you will have to make your own UserDataStore implementation or manipulate the data from the XML/JSON/whatever format you decided to save it in. (ControllerMap.CreateFromXml can be used to create a Controller Map from Xml.)

    The documentation covers saving and loading of maps here:
    http://guavaman.com/projects/rewired/docs/HowTos.html#saving-loading-controller-maps
     
    Last edited: Nov 19, 2018
  47. churi24

    churi24

    Joined:
    Sep 17, 2013
    Posts:
    78
    okidoki, thanks!, I replace the code with this and now is working:

    Code (CSharp):
    1.         player.controllers.maps.GetElementMapsWithAction(ControllerType.Keyboard, idAction,true, lActionElementMap);
    2.         Debug.Log("Keycode: " + lActionElementMap[0].keyboardKeyCode);
    3.  
    Now I have another question. Our game will use gamepad, keyboard and mouse. It's a fps. I would like to know why so many entries are necessary in the inputManager (approx 391). For each axis there are 29 different entries. I would like to know if this affects the performance.
     
  48. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,882
    This is explained when you first install Rewired during the automated installation. "To support all platforms, Rewired must add entries to the Unity Input Manager file." If you want Rewired to run on all platforms, you cannot remove these entries. They are required in order for Rewired to get input from the mouse and joysticks on platforms that use UnityEngine.Input as the input source or when disabling native input or choosing Unity as the input source on platforms that offer native input. There is no possible way to get input from joysticks on any platform that doesn't implement a native input library without these entries.
    • You cannot remove these entries.
    • They do not affect performance in any way.
    List of platforms supported by Rewired including which use Unity input and which use native input:
    http://guavaman.com/projects/rewired/docs/Overview.html#tested-platforms

    Hiding Unity Input Manager entries:
    http://guavaman.com/projects/rewired/docs/HowTos.html#hide-input-settings-launcher
     
  49. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,459
    @guavaman provided you all of the details in his previous message.

    Never a problem at all when it comes to performance. Rewired is the gold standard when it comes to input. The wonderful part about Rewired is being able to mix and match all different type of controller setups. I have tried a FPS style environment with 20 flight controllers (stick/throttle/HOTAS/flight pedals), a racing wheel, a few gamepads and keyboard/mouse and it works wonderfully for that purpose. Yes it was single player. You can do all of the wonderful what if scenarios. What if the customer only has flight stick and using racing pedals? What if the customer wants to use flight pedals with keyboard and mouse?
     
    guavaman likes this.
  50. lczyzycki7lvls

    lczyzycki7lvls

    Joined:
    Sep 10, 2018
    Posts:
    2
    Hi,

    we've tried to use controller maps in our projects to toggle between different gameplay modes, the way that is suggested in Rewired's docs. Unfortunately, when using manually defined maps for specific types on gamepads, enabled state doesn't seem to be carried between devices in any way.

    I've made a quickfix relying on controller connected/disconnected events:
    Code (CSharp):
    1. using System.Collections.Generic;
    2. using Rewired;
    3. using UnityEngine;
    4.  
    5. static class ControllerMapsFix
    6. {
    7.     private static bool m_initialized;
    8.     private static Dictionary<int, bool> m_snapshot;
    9.  
    10.     [RuntimeInitializeOnLoadMethod]
    11.     public static void Init()
    12.     {
    13.         if (m_initialized)
    14.             return;
    15.  
    16.         m_initialized = true;
    17.         ReInput.ControllerConnectedEvent += OnControllerConnected;
    18.         ReInput.ControllerPreDisconnectEvent += OnControllerDisconnecting;
    19.     }
    20.  
    21.     private static void OnControllerDisconnecting(ControllerStatusChangedEventArgs eventArgs)
    22.     {
    23.         if (eventArgs.controllerType == ControllerType.Joystick || eventArgs.controllerId == 0)
    24.             SaveEnabledMapsSnapshot();
    25.     }
    26.  
    27.     private static void OnControllerConnected(ControllerStatusChangedEventArgs eventArgs)
    28.     {
    29.         if (eventArgs.controllerType != ControllerType.Joystick)
    30.             return;
    31.        
    32.         var player = ReInput.players.GetPlayer(0);
    33.         var controllers = player.controllers;
    34.  
    35.         /* If the first id isn't 0, it means that the main controller was just disconnected and we should rely on
    36.          a snapshot saved in OnControllerDisconnecting, rather than get a new one. */
    37.         if (controllers.Joysticks[0].id == 0 && eventArgs.controllerId != 0)
    38.             SaveEnabledMapsSnapshot();
    39.  
    40.         if (m_snapshot == null)
    41.             return;
    42.        
    43.         foreach (var map in controllers.maps.GetMaps(ControllerType.Joystick, eventArgs.controllerId))
    44.             map.enabled = m_snapshot.ContainsKey(map.categoryId) && m_snapshot[map.categoryId];
    45.     }
    46.  
    47.     private static void SaveEnabledMapsSnapshot()
    48.     {
    49.         if (m_snapshot == null)
    50.             m_snapshot = new Dictionary<int, bool>();
    51.         else
    52.             m_snapshot.Clear();
    53.  
    54.         var mapsHelper = ReInput.players.GetPlayer(0).controllers.maps;
    55.         foreach (var map in mapsHelper.GetMaps(ControllerType.Joystick, 0))
    56.             m_snapshot[map.categoryId] = map.enabled;
    57.     }
    58. }
    While that seems to work properly, it's quite an ugly workaround. Is there any clean way, supported by the plugin, to achieve this behavior?