Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. 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:
    5,501
    What you are reporting is expected and unavoidable. Fixed Update has to run for other functionality in Rewired regardless of whether or not you are getting input in Fixed Update. The input update does not happen in Fixed Update if you have it disabled.

    I cannot disable mouse polling in Rewired. Rewired uses the mouse position for various things including getting the screen position of the pointer for Unity UI.
     
  2. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,501
    It's all over the documentation:
    https://guavaman.com/projects/rewired/docs/ControllerMaps.html#xinput-devices-windows
    https://guavaman.com/projects/rewired/docs/KnownIssues.html#xinput-device-name
    https://guavaman.com/projects/rewired/docs/KnownIssues.html#windows-xinput-devices-use-x360-map
    https://guavaman.com/projects/rewir....html#windows-xbox-one-controller-doesnt-work

    That's exactly what it should be doing. Mapping UICancel or UISubmit to mouse buttons is an error and is specifically warned against in the documentation:

    https://guavaman.com/projects/rewired/docs/RewiredStandaloneInputModule.html#faq

    Problem: Receiving duplicate mouse clicks when clicking on a UI button

    Do not assign UI Submit or Cancel Actions to Mouse Left Button or Mouse Right Button or you will receive double-clicks evey time the mouse button is pressed over a button. The mouse button click on a UI element is based on mouse cursor position and does not use the Action system.

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

    Unity's UI is designed to have two completely different systems for Keyboard/Joystick and Mouse. The Keyboard/Joystick system uses the Navigation system, which involves setting an active selected GameObject in the EventSystem, and the InputModule sends directional navigation events, OnSubmit, and OnCancel events to the currently selected Selectable GameObject in the Event System. This system is only for keyboard/joystick navigation.

    Mouse navigation does not use any of the above. It uses the mouse pointer position on-screen and the InputModule sends OnClick, OnPointerEnter, OnPointerExit, etc., events to the Selectable on the Game Object under the mouse pointer. Unity's system does not support a Cancel functionality for mouse input.

    Mapping OnSubmit or OnCancel to mouse buttons will cause the currently selected GameObject in the EventSystem (if one is selected) to receive these events regardless of where the mouse is on the screen. This is normally not what you want to happen when using a mouse pointer.

    There is no functional difference between Joystick and Keyboard input in Unity UI. Only controller maps and/or controller assignment could be responsible. Check all your Controller Maps in your Player using Debug Information and verify at runtime that the UI Actions are on enabled Controller Maps assigned to the Player you have chosen to have control over the UI.

    As I noted before, if you're seeing different mappings shown at runtime vs what you're seeing in the Rewired Input Manager, outdated XML/JSON save data is the most likely cause:

    https://guavaman.com/projects/rewired/docs/UserDataStore.html#clearing-playerprefs

    IMPORTANT:

    During development, you may run into a situation where your controls don't seem to make sense. This may happen when you make some runtime control changes, save them, and then proceed to change your mappings in the Rewired Input Manager. Because UserDataStore_PlayerPrefs is configured to save controller data on disconnect and load controller data on start and controller connect, the loaded settings will override new changes you make to the default mappings in the Rewired Input Manager.

    During development, it may be useful to disable or remove the UserDataStore_PlayerPrefs component. If you've already saved controller settings and want to remove them, you can use the Clear All Player Prefs button in the Debug Options foldout on the UserDataStore_PlayerPrefs inspector. WARNING: This will clear ALL PlayerPrefs data for the current project. This is due to the limitation that there is no way to look up what keys exist in PlayerPrefs.
     
  3. Q-Ted

    Q-Ted

    Joined:
    Dec 16, 2016
    Posts:
    46
    I see..

    We're not using the UI input module of Rewired or the mouse/touch functionality. We have a custom UI input module, which doesn't process the pointer on non-mouse platforms. I'm a bit confused why mouse updates are required when the application isn't making use of any of the data or why InputManager_Base.FixedUpdate also updates the mouse data.
     
  4. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,501
    I was trying to avoid having to explain my internal design, but internal implementation details to follow: InputManager_Base.FixedUpdate doesn't also update the mouse data. Only the first of InputManager_Base.FixedUpdate or InputManager_Base.Update per thread frame will update the mouse values. This is why any code at all is being executed in Fixed Update and it's not just exiting out instantly. That is the means Rewired uses to find the thread frame so it can run some code only once per frame, which will will be available to both Fixed Update and Update for the duration of the thread frame. Unity has no main thread update callback. The code you see running in FixedUpdate would be running in Update if Update were running first in that frame, which would happen if your render frame rate were higher than the physics frame rate.

    Rewired is not structured in such a way that the Mouse Controller object has any relation to the underlying polling of the mouse. That functionality runs entirely separately from any part of the Rewired API and is a special internal class that grabs information from Unity every main thread frame and makes that data available in a thread safe manner to the rest of the program. Mouse.enabled = false does nothing but disable the processing of the high-level Mouse Controller object, not the low-level thread safe Unity data class. The Mouse Controller object obtains its input values from the underlying mouse input source, in this case, UnityEngine.Input through the thread-safe class, or in the case of native Windows, the Raw Input mouse input source which receives its value through Raw Input events. Disabling the mouse does not affect the underlying input source. I would have to do significant restructuring to make it possible to disable the Unity mouse polling, and frankly, I just don't have time to do it with all the other more important things that are backed up like PS5 support, rebuilding PS4 support, Mac GameController Framework support, and Unity 2022 support.

    There are also quite a few things that are not obvious that use the mouse. For example, on PS4, Unity maps the Dual Shock 4's touchpad to mouse input. I'm sure there are more that I can't remember right now.
     
    Last edited: Jun 22, 2022
  5. NikMikk

    NikMikk

    Joined:
    Nov 4, 2015
    Posts:
    25
    Hi Guavaman!

    Is there a way to SEND inputs to the Rewired system?

    I want to record my key pressed using
    Code (CSharp):
    1. player.AddInputEventDelegate(OnInputUpdate, UpdateLoopType.Update);
    Then replay them to automate playtests of our game.

    Like faking the inputs?

    Is this possible currently, or do you know any workaround? :)
     
    Last edited: Jun 23, 2022
  6. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,549
    Take a look at custom controllers.

    https://guavaman.com/projects/rewired/docs/HowTos.html#simulating-input

    https://guavaman.com/projects/rewired/docs/CustomControllers.html
     
    NikMikk likes this.
  7. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,501
    @longroadhwy is correct. Custom Controllers are the only way to insert values into the Player-Action system. There is no way to insert your own values into actual Controllers.
     
  8. NikMikk

    NikMikk

    Joined:
    Nov 4, 2015
    Posts:
    25
  9. NikMikk

    NikMikk

    Joined:
    Nov 4, 2015
    Posts:
    25
    I now have another issue, all my actions are fired each frame without any explanations to it.


    Code (CSharp):
    1. player.AddInputEventDelegate(OnInputReceived, UpdateLoopType.Update);
    2. private void OnInputReceived(InputActionEventData obj)
    3. {
    4.     Debug.Log($"OnInputReceived: {obj.player.name} - {obj.actionName} - {obj.eventType.ToString()}");
    5. }
    It prints out almost all Actions even though I just enter play mode and don't touch anything. :/
    upload_2022-6-23_23-32-15.png
     
  10. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,501
    The explanation is the overload of AddInputEventDelegate you are using. It's doing exactly what it's supposed to be doing. You told it to send you an event whenever any Action updates. You have to specify a specific event for which you want a callback such as JustPressed and the Action for which you want to receive the event. See the documentation on getting input:

    https://guavaman.com/projects/rewired/docs/HowTos.html#get-input

    Code (csharp):
    1. // This event will be called every frame any input is updated
    2. player.AddInputEventDelegate(OnInputUpdate, UpdateLoopType.Update);
    3.  
    4. ...
    5.  
    6. // This event will be called when the "Fire" button is first pressed
    7. player.AddInputEventDelegate(OnFireButtonDown, UpdateLoopType.Update, InputActionEventType.ButtonJustPressed, "Fire");
    8.  
    9. ...
     
    NikMikk likes this.
  11. NikMikk

    NikMikk

    Joined:
    Nov 4, 2015
    Posts:
    25
    Ohh, that's amazing, I totally missed that.

    Thanks you so much :)
     
  12. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    522
    Any progress or updates on the 2022 support?
     
    iDerp69 and Linkupdated like this.
  13. lazylukey

    lazylukey

    Joined:
    May 26, 2017
    Posts:
    35
    @guavaman Hi again, we recently made a fix to RewiredStandaloneInputModule.cs

    We added
    Code (CSharp):
    1. if (!Rewired.ReInput.isReady) return;
    to the top of
    Code (CSharp):
    1. public override void ActivateModule()
    . Reason being, when the Ignore Input When App Not In Focus setting was set to false and the game is running under SteamVR + OpenXR it would cause SteamVR to crash reliably on launch, the game would then eventually continue to start up but XR has of course failed to initialise. No crashes of the standalone ever occurred and behaviour was fine in standard non-VR and in VR using the Oculus OpenXR runtime. Anyway thought I'd let you know regardless.. Is this fix safe you think? Didn't seem to cause a single issue for us
     
  14. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,501
    That doesn't sound like a fix to me but a workaround for some kind of bug in SteamVR or OpenXR. There is nothing in Rewired that could possibly cause a crash. At worst, you should get a null reference exception trying to access some Rewired class or function if ActivateModule is called before Rewired is initialized and before Awake has run on the RewiredStandaloneInputModule.

    That seems like an error to me that ActivateModule should even be getting called, especially before Awake is run. ActivateModule shouldn't be getting called unless ShouldActivateModule is called first. You'll notice ShouldActivateModule already has this:

    Code (csharp):
    1. if (!Rewired.ReInput.isReady) return false;
     
  15. lazylukey

    lazylukey

    Joined:
    May 26, 2017
    Posts:
    35
    Yeah you're right, ah well I think the workaround seems safe/stable from our testing. In case it gives you anymore potential clues: we deactivate our Rewired UI event system GO in Start() and then activate the new Input System event system for VR only. Very strange SteamVR/OpenXR could somehow force ActivateModule() to be called before Awake()..
     
  16. Acissathar

    Acissathar

    Joined:
    Jun 24, 2011
    Posts:
    669
    What issue are you running into? I'm using it in 2022.1.6, and while I do get the warning message about the wrong version, everything seems to be still be working as I would expect it to.
     
  17. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,501
    I'm working on it still. I don't have any announcements to make about it yet. There will also be some new things in this update that I have to get done before releasing it.
     
    iDerp69 likes this.
  18. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    522
    That's cool, thanks. Rewired seems to be working just fine right now despite the warning, so i guess it will be ok :)
     
  19. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    522
    It seems to work fine. I will be presenting my game to a large audience in 3 weeks, and the warning makes me nervous, but yeah, so far everything seems ok.
     
  20. MatthewDickson

    MatthewDickson

    Joined:
    Jan 8, 2019
    Posts:
    2
    Quick question about the InputMapper and the Hash/Pound Key (#).
    When I press the # key the InputMapper returns an Quote/Apostrophe ('), is this a bug?
    Note: This happens in the ControlRemapping1 example.
    FYI using a UK English keyboard
     
  21. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,501
    No this is not a bug. Rewired's keyboard system on every single platform except Windows Standalone gets its key values from UnityEngine.Input.GetKey. Windows Standalone has the option to use native keyboard input which is enabled by default. The Windows Standalone native keyboard code is designed to give identical key results to UnityEngine.Input. UnityEngine.Input does not explicitly support any keyboard layout besides US and neither does Rewired. The Windows Key code sent by windows is mapped to Unity's KeyCode enum, because Rewired uses Unity's KeyCode enum to maintain compatibility with Unity. The Windows Key code enum. This is the list of Windows enum values returned:
    https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.keys?view=windowsdesktop-6.0

    There is no Hash key enum in that list. The key is returning one of the OEM keys most likely, probably Oem7.

    Rewired actually has a few maps to support non-us layouts, but it is by no means complete, nor is it a feature I advertise. These were only added because of requests from users using these layouts even though Rewired's native keyboard input on Windows was never intended to add features but was only ever implemented to fix bugs in Unity's keyboard input in certain old versions of Unity. I see from my code there are special cases for layouts UK, UK Extended, and German. These layout maps map a couple of the Oem keys to specific keys on those keyboard layouts:

    Code (csharp):
    1. {
    2.     (int)NativeConsts.KeyboardIdentifier.United_Kingdom,
    3.     new Dictionary<int, KeyCode>() {
    4.         { (int)Keys.Oem8, KeyCode.BackQuote },
    5.         { (int)Keys.Oem3, KeyCode.Quote }
    6.     }
    7. },
    8. {
    9.     (int)NativeConsts.KeyboardIdentifier.United_Kingdom_Extended,
    10.     new Dictionary<int, KeyCode>() {
    11.         { (int)Keys.Oem8, KeyCode.BackQuote },
    12.         { (int)Keys.Oem3, KeyCode.Quote }
    13.     }
    14. },
    15. {
    16.     (int)NativeConsts.KeyboardIdentifier.German,
    17.     new Dictionary<int, KeyCode>() {
    18.         { (int)Keys.Oem4, KeyCode.Backslash },
    19.         { (int)Keys.Oem6, KeyCode.BackQuote }
    20.     }
    21. }
    If the key is not found in the layout map, it will use the default, and the default for OEM7 is the quote key on a US keyboard.

    This is not a bug but rather a lack of explicit mapping of all keyboard layouts to the Unity KeyCode enum. Based on my testing at the time I implemented this, Unity did not support any form of international key mapping, and for consistency between native and non native modes, as well as for consistency with all other build targets, I did not delve into the deep world of international keyboard layout mapping.
     
    Last edited: Jul 1, 2022
  22. VoidNuggets

    VoidNuggets

    Joined:
    Jan 10, 2022
    Posts:
    1
    Hi
    I'm using unity 2020.3.7f1 LTS Rewired version: 1.1.41.5.U2020

    I've followed both the docs and Youtube tutorials and got all the player and menu inputs to work as intended.
    The only issue I'm having is for some reason only the Xbox One controller is working. Neither the ps4 nor the ps5 will work. I used the Gamepad Template. The weird thing is the Debugger fully detects them and shows them being Enabled and assigned to the right player id but when you go into the buttons and axes nothing happens when I use the PS controllers.
    I've also tried some of the sample scenes. The Xbox controller worked perfectly, but not the PS. They show up and everything, but inputs don't do anything.
    I tried making a joystick map just for the ps4 to see if it would work, but same result.

    Both ps4 and ps5 worked in the old input system.
    I've made sure to add a "/" to all the old input manager names to avoid them being used.
    Thinking it might be a Unity glitch, I closed everything and restarted my pc which has helped other glitches in the past but nothing.
    I also built my current project just to see what would happen. Oddly enough the ps5 controller started working, but only the "X" button on the ps4 worked. and of course Xbox worked.

    So I'm kind of at a loss for what can be causing this. As far as I can tell, I've set everything up correctly and everything works-- just not the PS controllers. I've spent a long time looking in the docs, in this forum, and everywhere else google sends me, but I can't find anyone else reporting this issue.

    Any Suggestions from anyone would be greatly appreciated.
     
  23. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,501
    Inexplicable problems with PS4, PS5, and Nintendo Switch controllers on Windows are very frequently caused by Steam. Close Steam entirely and restart the editor. Disable any code that initializes Steam (Steamworks.net) and re-test.

    To understand what Steam does to input, see this:
    https://guavaman.com/projects/rewired/docs/Troubleshooting.html#steam

    Other possible causes are PS4 controller drivers and mapping tools such as DS4Win.
     
  24. Cambesa

    Cambesa

    Joined:
    Jun 6, 2011
    Posts:
    119
    Hello guavaman, I'm trying to show whether the user is using a controller or keyboard/mouse automatically. In billboards we are showing controller or keyboard hints for controls based on the most recent input but thre are conflicting inputs in the pipeline.
    I tried things like checking for player1.getbutton(a) to switch to controller hint display but that is also registered as a keyboard space, switching the billboards back to keyboard display again. The same goes for WASD vs the joystick on a controller, UP on a joystick is also registered as W on the keyboard. How do i differentiatie between any input being either from the controller(s) or keyboard/mouse? controller1.getanybutton() also respons to the keyboard/mouse instead of purely to the controller.
     
  25. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,501
    I don't know how you have implemented glyphs, so I can't really help you specifically. The documentation contains instructions on displaying glyphs and for detecting the last used controller:

    https://guavaman.com/projects/rewired/docs/HowTos.html#display-glyph-for-action
    https://guavaman.com/projects/rewired/docs/HowTos.html#last-used-controller

    You will see the glyph code using overloads of functions to get ActionElementMaps for a specific controller.
     
    Last edited: Jul 13, 2022
  26. guavaman

    guavaman

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

    If you currently support the PS4 platform, do not update yet as the PS4 plugin is not yet available for download (trying to get the details worked out with Sony at the moment), and PS4 support was removed from the base Rewired.

    1.1.42.0:

    Changes:
    - Added Unity 2022 branch.
    - Removed support for many old platforms: Windows 8 Phone, Windows 8 Store, Windows 8.1 Universal, Ouya, PS3, Wii, WiiU, Xbox 360, Blackberry, Google Nexus Player, Gamestick.
    - Removed PS4 support from core. A plugin is now required for PS4 support. See Special Platforms in the documentation for details.
    - Added support for Sony PlayStation 4 plugin.
    - Added support for Sony PlayStation 5 plugin.
    - Added support for Nintendo Switch plugin running in Unity Editor.
    - OSX: Updated SDL2 library to 2.0.20, universal Intel/Apple Silicon. (SDL2 library files in project must be deleted and re-installed from the menu.)
    - Added Rewired_DirectInput.pdb files.
    - Added option to disable mouse input on platforms and avoid polling for mouse input values on Unity-based input sources to reduce CPU usage on certain platforms.

    Bug Fixes:
    - Removed warning in editor when Unity Input System is enabled in Unity 2021.2+.
    - Rewired Input Manager Settings configuration is no longer reset when using Compact Ids function.
    - Controller Map returns the correct controller type even before data is baked when creating a Controller Map from XML.
    - Controller id defaults to -1 instead of 0 for incomplete Controller Maps which have been created outside a Player and have no associated Controller.
    - Creating an ActionElementMap in an incomplete Controller Map can no longer throw an exception if no Controller exists when the Controller Map has an undefined Controller id.
    - Control Mapper: Adding a Map categories that is set to not User Assignable to the list of categories to display no longer break the layout.
     
  27. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,549
    That is a great update @guavaman . Thanks again for Rewired.
     
    guavaman likes this.
  28. sk1zZ

    sk1zZ

    Joined:
    Mar 30, 2015
    Posts:
    9
    Hi!
    Is it possible to register GetButton("UISubmit") with LMB? For joysticks, it works well, but for mouse it just doesn't register anything.
     
  29. hyouuu

    hyouuu

    Joined:
    Nov 26, 2020
    Posts:
    42
    Hi! We're thinking of replacing all UI components with UI Toolkit, and it seems after the conversion no Canvas or EventSystem is needed anymore - I guess for Rewired to work we still need those 2? Any possibility and plans to not require those?
     
  30. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,501
    Yes, you can do it, but it would be an error to assign UISubmit to the mouse button. This is explained in the documentation:

    https://guavaman.com/projects/rewired/docs/RewiredStandaloneInputModule.html

    Mouse:

    DO NOT map any UI Actions to Mouse buttons or axes. This is a very common mistake and will lead to many problems. See this for more information.

    Problem: Receiving duplicate mouse clicks when clicking on a UI button

    Do not assign UI Submit or Cancel Actions to Mouse Left Button or Mouse Right Button or you will receive double-clicks evey time the mouse button is pressed over a button. The mouse button click on a UI element is based on mouse cursor position and does not use the Action system.

    Unity's UI is designed to have two completely different systems for Keyboard/Joystick and Mouse. The Keyboard/Joystick system uses the Navigation system, which involves setting an active selected GameObject in the EventSystem, and the InputModule sends directional navigation events, OnSubmit, and OnCancel events to the currently selected Selectable GameObject in the Event System. This system is only for keyboard/joystick navigation.

    Mouse navigation does not use any of the above. It uses the mouse pointer position on-screen and the InputModule sends OnClick, OnPointerEnter, OnPointerExit, etc., events to the Selectable on the Game Object under the mouse pointer. Unity's system does not support a Cancel functionality for mouse input.

    Mapping OnSubmit or OnCancel to mouse buttons will cause the currently selected GameObject in the EventSystem (if one is selected) to receive these events regardless of where the mouse is on the screen. This is normally not what you want to happen when using a mouse pointer.
     
    sk1zZ likes this.
  31. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,501
    Rewired's integration for Unity UI is the Rewired Standalone Input Module. This is not for UI Toolkit. I don't have any plans to make a UI Toolkit integration right now. You could certainly make one if you want, however. It doesn't even sound like it's finished according to the manual. I don't support experimental, alpha, beta, or preview features because it's a gigantic pain to keep having to rework things and somehow attempt to support all the various permutations over time.
     
  32. Lunzren

    Lunzren

    Joined:
    Jun 22, 2021
    Posts:
    7
  33. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,501
    The Touch Pad touch control has inspector options that determine the format of the data it outputs:

    https://guavaman.com/projects/rewired/docs/TouchControls.html#touch-pad




    A Touch Pad Mode of Delta and a Value Format of Pixels would yield the same result as a mouse. The delta value is determined by the UnityEngine.getTouch position of the previous frame with the current frame.

    Further, how you apply this output to your camera will determine how it will behave. How are you applying this output? Are you using the Player-Action system to read the Action values or are you reading the position directly from the Unity events?
     
  34. Lunzren

    Lunzren

    Joined:
    Jun 22, 2021
    Posts:
    7

    I'm using Delta and Pixels but it's still not working out for me. I'm doing this with the playmaker action "Rewired Player Get Axis Raw", storing it as a variable and using the "Mouse Look Mobile" action to control the camera. I have the FSM on my FPS Controller object and not the camera. I just tried doing this with the thumbstick and that seems to be working better.
    https://drive.google.com/file/d/1aqvnDwR_JpQwfoVH0YGShwJm4QS6ynQc/view?usp=sharing
     
  35. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,501
    Delta values should not be multiplied by Time.deltaTime:
    https://guavaman.com/projects/rewired/docs/HowTos.html#relative-absolute-axes

    Disable mouse touch simulation:
    https://docs.unity3d.com/ScriptReference/Input-simulateMouseWithTouches.html
     
  36. Lunzren

    Lunzren

    Joined:
    Jun 22, 2021
    Posts:
    7
  37. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,501
    Create a script named DisableSimulateMouseWithTouch.cs, add the script to a GameObject in the scene.

    Code (csharp):
    1. using UnityEngine;
    2.  
    3. public class DisableSimulateMouseWithTouch : MonoBehaviour
    4. {
    5.     void Awake()
    6.     {
    7.         Input.simulateMouseWithTouches = false;
    8.     }
    9. }
    I would be surprised if PlayMaker didn't have an action for that. It's been part of UnityEngine.Input forever.
     
  38. Lunzren

    Lunzren

    Joined:
    Jun 22, 2021
    Posts:
    7
    Thanks! and last thing sorry man it's still glitching out what exactly was I supposed to do about the "Delta values should not be multiplied by Time.deltaTime:"?
     
  39. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,501
    If the PlayMaker action you are using multiplies the value by Time.deltaTime or you are doing the multiplication manually through a series of Actions, it will not work correctly.

    If none of that is being done and the problem still exists, then there's no explanation I can think of other than a problem with the data UnityEngine.Input.GetTouches is returning. I would not be able to fix that. Rewired relies on UnityEngine.Input.GetTouches to get the position of touch and calculates the delta from the previous frame to the current. There's nothing in Rewired's code that would cause studdery, intermittent delta values.

    Are you reading the input in FixedUpdate by any chance?
     
    Last edited: Jul 16, 2022
  40. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,501
    This has been changed in Rewired 1.1.42.0. Now mouse polling will be stopped on platforms / input sources that use UnityEngine.Input for mouse input when the Mouse is disabled. There is also an option to disable the mouse for a platform through the Rewired Input Manager -> Settings page as well.
     
    Q-Ted likes this.
  41. MalekGames

    MalekGames

    Joined:
    Dec 8, 2016
    Posts:
    1
    Hi I'm trying to setup a custom controller, but as soon as I open the custom controllers tab in the rewired input manager editor I get spamming errors and I can't edit or add controller properties, as the controller properties section doesn't render.
    Repro steps:
    - Create a new project in Unity 2021.3.6f1 or 2020.3.36f1
    - Install latest Rewired (1.1.42.0)
    - Create a rewired input manager prefab
    - Edit the prefab and select the custom controllers tab
    Errors:
    Code (csharp):
    1. MissingMethodException: Method not found: string Rewired.Data.CustomController_Editor.get_typeGuidString()
    2. Rewired.Editor.InputEditor.KWhjchWlTFIdbtXEuhOKaDnMFags (System.Boolean ) (at <0fb8129c40a746e6ae08c8bd6bb313d6>:0)
    3. Rewired.Editor.InputEditor.OnGUI () (at <0fb8129c40a746e6ae08c8bd6bb313d6>:0)
    4. UnityEditor.HostView.InvokeOnGUI (UnityEngine.Rect onGUIPosition) (at <44a70d1b13cf47e29810e30f45ffae08>:0)
    5. UnityEditor.DockArea.DrawView (UnityEngine.Rect dockAreaRect) (at <44a70d1b13cf47e29810e30f45ffae08>:0)
    6. UnityEditor.DockArea.OldOnGUI () (at <44a70d1b13cf47e29810e30f45ffae08>:0)
    7. UnityEngine.UIElements.IMGUIContainer.DoOnGUI (UnityEngine.Event evt, UnityEngine.Matrix4x4 parentTransform, UnityEngine.Rect clippingRect, System.Boolean isComputingLayout, UnityEngine.Rect layoutSize, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <7096c6494db14f0c807ca461735e58a8>:0)
    8. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)
    9.  
    10. GUI Error: You are pushing more GUIClips than you are popping. Make sure they are balanced.
    11. UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
     
  42. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,501
    Thanks. Download the 1.1.42.1 from the Unity Asset store which fixes the issue.
     
  43. guavaman

    guavaman

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

    Please see Updating Rewired before updating.

    Release Notes:

    1.1.42.1:

    Bug Fixes:
    - Fixed missing method exception thrown when editing Custom Controllers in Rewired Editor.
     
  44. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    522
    I want to use two identical joysticks, one for each hand. I created two Joystick maps, but both maps are getting assigned to both joysticks.
    How do I set it up so that the right hand map goes on one stick, and the left hand map on the other stick, and how would I say which stick is which?

    This is what i have so far:
     

    Attached Files:

  45. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,501
    The Rewired editor does not have the capability to define different controller maps for multiple identical controllers assigned to the same Player.

    You would have to manage loading the controller maps you want for each controller manually via a script in the Player to achieve this.

    Your script would have to determine which controller is which and load the controller maps you want for each. You would also have to decide how to handle the many possible cases where problems could arise such as when the user unplugs one of the two controllers, or plugs the right in before the left, etc.

    https://guavaman.com/projects/rewired/docs/HowTos.html#enabling-disabling-controller-maps
    https://guavaman.com/projects/rewired/docs/HowTos.html#managing-controller-maps-runtime
    https://guavaman.com/projects/rewired/docs/HowTos.html#loading-controller-maps-runtime

    Depending on your game design, you may also be able to use a separate Player for each controller, which would make some aspects of the task much easier and some harder (such as remapping.)
     
  46. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    522
    Right now I am doing something like this, with two layouts and disabling the unwanted one:

    Code (CSharp):
    1.  
    2.         var RHC = player.controllers.GetController(ControllerType.Joystick, 1);
    3.         var LHC = player.controllers.GetController(ControllerType.Joystick, 2);
    4.  
    5.         player.controllers.maps.SetMapsEnabled(false, LHC, "Default", "Default");
    6.         player.controllers.maps.SetMapsEnabled(false, RHC, "Default", "LHCLayout");
    I will add a keyboard button to swap the controllers around. Probably not the most elegant but I need to have a demo working within the next few hours! This seemed to be far harder to figure out than it should have been.
     
  47. seoyeon222222

    seoyeon222222

    Joined:
    Nov 18, 2020
    Posts:
    155
    This is a question about the cursor.

    Depending on the state of the game / type of controller,
    I want to manage the visibility of the cursor.

    ex)
    GameMode | Controller | Cursor Visible
    ---------------------------------------------------------------
    UI | keyboard Mouse | true (Arrow Point)
    GameView | keyboard Mouse | false
    UI | GamePad | true (Gampad Crosshair Point)
    GameView | GamePad | true


    Q1) Did I get it right? Is there a better recommended way?

    - Do not use the default OS cursor
    cursor.visible = false;
    cursor.LockState = CursorLockMode.Locked;

    - Use PlayerMouse instead

    - Create a script to refresh the cursor depending on the controller's change event and game state



    Q2) The cursor on the virtual mouse(PlayerMouseSprite Examples) is spinning strangely
    There seems to be a problem with the PlayerMouseSprite example.
    Image_1300.png

    I checked the hidden hardware pointer.

    upload_2022-7-29_17-8-52.png
    The mouse cursor is not hidden after clicking on an area outside the game view (any space in the editor).

    I am using three monitors.
    One of them has a flipped screen.
    Perhaps because of this, when the mouse moves outside the game view and returns, the shape of the cursor turns strangely.
    It is not always accurately reproduced. It could be a different matter.
    upload_2022-7-29_17-13-51.png

    upload_2022-7-29_17-16-43.png
    Is there any effect of this problem in the actual build?
    How do I solve this?
     

    Attached Files:

  48. seoyeon222222

    seoyeon222222

    Joined:
    Nov 18, 2020
    Posts:
    155
    It's a question on a different topic, so I wrote it in a separate article.

    I'm a beginner who's just using Rewired.
    I have a question about the concept.

    Q1) How to Design Action Categories / Map Categories / Map Enabler Rules

    For example
    The "A" button on the GamePad has three functions depending on the state of the game.

    UI mode: Confirm
    Combat mode: Attack
    Scenario mode: Interaction

    How to Design Action Categories / Map Categories / Map Enabler Rules?

    Q2) Map Enabler Rules
    All questions below are due to a lack of understanding of Map Enabler Rules...

    Q2-1)
    Is it the same function as enabling/disabling the action map in the new input system?
    Is there any examples to understand about Map Enabler Rules?
    upload_2022-7-29_17-46-37.png
    Q2-2) Should all maps be added to Players Default Maps in advance? (Left Image)
    (Regardless of using Map Enabler Rules?)

    upload_2022-7-29_17-51-37.png


    upload_2022-7-29_17-51-54.png

    Is this the right way to use it?

    Q2-3)
    What is difference between "player.controllers.maps.SetMapsEnabled( ... )" and mapEnabler ?
     
    Last edited: Jul 29, 2022
  49. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,501
    Player Mouse is the only built-in method Rewired offers to do anything with cursors. So there is no other way, unless you want to move the OS cursor yourself through native code for the OS in question or implement your own software cursor instead of using Player Mouse.

    There's no possibility the problem is in the script. Open the PlayerMouseSprite example scene in Rewired/Examples. Watch the Transform values in the inspector of the cursor sprite. You will see nothing ever changes except the Transform position. Rotation is not touched. Any visual cursor rendering problem is outside the responsibility of the script. The script does nothing but change the transform position. You can see it in the code.

    Code (csharp):
    1. // Callback when the screen position changes
    2. void OnScreenPositionChanged(Vector2 position) {
    3.  
    4.     // Convert from screen space to world space
    5.     Vector3 worldPos = Camera.main.ScreenToWorldPoint(new Vector3(position.x, position.y, distanceFromCamera));
    6.  
    7.     // Move the pointer object
    8.     pointer.transform.position = worldPos;
    9. }
    The example just moves a sprite around in space. The angle of the camera looking at the sprite is going to affect how it appears.

    This script is not a script you can just use in your project. It does nothing but show an example of moving a sprite in a scene with the camera in a specific, static position, facing a specific direction. The moment you rotate the camera, it's not going to work because the sprite is going to be left in space where it was before you moved it.

    It is far more common to use Unity UI for displaying a cursor. There is also an example of that.
     
    Last edited: Jul 30, 2022
    seoyeon222222 likes this.
  50. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,501
    Create three Map Categories:
    UI
    Combat
    Scenario

    Create Controller Maps for each category and assign them to be loaded in the Player on start.

    I don't know anything about Unity's new (new) input system, but I very much doubt Map Enabler Rule Sets are the same as their action map. A Controller Map would probably be the most likely equivalent to an action map.

    https://guavaman.com/projects/rewired/docs/ControllerMaps.html

    Controller Maps and Map Enabler Rule Sets are entirely different things. Map Enabler Rule Sets allow you to control the enabled state of Controller Maps in a managed way.

    https://guavaman.com/projects/rewired/docs/MapEnabler.html

    All documentation and examples are on the Map Enabler documentation page linked above.

    There is no one right way to use Rewired. It depends entirely on how you want to use it.

    Read the documentation on Controller Maps to understand how they work, when they're loaded, etc.
    https://guavaman.com/projects/rewired/docs/ControllerMaps.html

    A common way of doing a set up like this is to load all Controller Map categories in the Player on start, and then enable/disable them based on some game state. That is one of the possible uses of Map Enabler -- to make managing state-dependent Controller Map enabled states easier.

    But there are times when you would want to instead unload and load Controller Maps as necessary. Having different control layouts are one common reason to do this. There are many other possible reasons.

    DisableAllInput is not doing what you think it's doing. rs.enabled = false does not disable any Controller Maps. You are disabling the Rule Set itself. This means that Rule Set is no longer evaluated and essentially doesn't exist anymore. Whatever Rules exist in that Rule Set will not be executed. This is explained in the Map Enabler documentation:

    "Rule Sets can be enabled and disabled to control whether they are evaluated or not then ControllerMapEnabler.Apply is called or whenever rules are evaluated."

    By disabling your rule sets, you have not disabled input. You have simply disabled all the rules you have defined and none of them will be evaluated when ControllerMapEnabler.Apply is called. They've all been turned off.

    The example code in the documentation shows making a rule that enables one Map Category while disabling all others:

    Code (csharp):
    1. // Exclusively enables Controller Maps in the "GameplayShared" category in the "Leftie" Layout for Joysticks only
    2. private ControllerMapEnabler.RuleSet mapEnabler_default_leftieJoystick = new ControllerMapEnabler.RuleSet() {
    3.  
    4.    tag = "leftie_joystick",
    5.    rules = {
    6.  
    7.        // First disable all Controller Maps for all Joysticks
    8.        new ControllerMapEnabler.Rule() {
    9.            enable = false,
    10.            controllerSetSelector = ControllerSetSelector.SelectControllerType(ControllerType.Joystick)
    11.        },
    12.  
    13.        // Enable Controller Maps in the "GameplayShared" category in the "Leftie" Layout for all Joysticks
    14.        new ControllerMapEnabler.Rule() {
    15.            enable = true,
    16.            controllerSetSelector = ControllerSetSelector.SelectControllerType(ControllerType.Joystick),
    17.            categoryName = "GameplayShared",
    18.            layoutName = "Leftie"
    19.        }
    20.    }
    21. };
    You will see it is a Rule Set containing two rules. One disables all Joystick Controller Maps. The next enables "Gameplay Shared" Joystick Controller Maps. The end result of this rule set when evaluated is only "Gameplay Shared" is enabled.

    Your code for UseRuleSets is also incorrect. You are trying to use an exported constant Rule Set Id to select the Rule Set to enable. RewiredConsts.MapEnablerRuleSets.UI cannot be used to select a Rule Set in a Player's Map Enabler at runtime. There is no id that corresponds to a Rule Set at runtime. That is what Tag is for. The constant exported for rule sets exists only for the purpose of instantiating that Rule Set (loading it from the Rewired Input Manager) into a Player's Map Enabler at runtime. That is not a common thing to do since most of the time you will assign these Rule Sets to your Player in the Rewired Editor and they will be loaded for you when the application starts. This constant id serves no other purpose. Once the application starts. Rule Sets are instantiated for each Player, after which point they have no connection anymore to the Rule Set parent definition from which they came which exists in the Rewired Input Manager.

    In addition to that, your code is trying to use the Id as an index, which is also incorrect:

    https://guavaman.com/projects/rewired/docs/BasicUsage.html

    "Id" is NOT an "Index"

    Anywhere the term Id is used in the API is a UNIQUE ID, not an Index, and cannot be used to iterate over items or get the first Joystick.

    You have to use the Tag to select a rule set at runtime. Again, this is shown in the Map Enabler documentation:

    Code (csharp):
    1. // Enable the Rule Set with the tag "UI"
    2. player.controllers.maps.mapEnabler.ruleSets.Find(item => item.tag == "UI").enabled = true;

    This is explained in great detail in the documentation here:
    https://guavaman.com/projects/rewired/docs/HowTos.html#enabling-disabling-controller-maps
     
    Last edited: Jul 30, 2022
    seoyeon222222 likes this.