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. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. 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,495
    I don't understand what you're describing here.

    "the controller isn't being added to the player, as it is shown in Rewired's Debug Info panel."

    What is shown in the Debug Info? Players -> Player # -> Controllers. Are you saying after calling AddController it is not being added to the Player? Nothing has changed in this code.

    It sounds like you're saying the Rewired Player object returned when GameLauncher executes is not the same Player object returned when polling the key press. This isn't possible unless Rewired is initializing, then deinitializing, then reinitializing again. Are you disabling the Rewired Input Manager before you do your polling? That would explain it. Rewired is completely reset when you do that now. It wouldn't have been before. Log the player.GetHashCode() and see if the value changes.

    No. Disabling the Rewired Input Manager to disable input was never a proper or allowed way to disable input. See the Input Manager docs:
    • Do not disable or enable the Input Manager during runtime.
    This behavior has indeed changed due to the changes made for Run in Edit Mode. Now disabling the Rewired Input Manager deinitializes Rewired meaning all runtime classes become no longer valid. When the Rewired Input Manager is reinitialized, it is completely reset and no objects pre-disable are valid anymore. Controllers will be reassigned, maps reloaded, etc.
     
  2. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,495
    @Situacao Hmm. Scratch that last deleted post. It was intentional that it be reset when disabled at runtime. I just didn't expect anyone to be disabling the Rewired Input Manager since this wasn't meant to be a supported operation. I think it's better to leave it as it is now and disable Rewired entirely if the currently selected Rewired Input Manager is the active singleton and it is disabled.

    I think I will add a bunch of internal checks to every Rewired object to log an error when they're accessed after their parent ReInput singleton has been destroyed or reset.
     
    Last edited: Jul 4, 2018
    Situacao likes this.
  3. Situacao

    Situacao

    Joined:
    Dec 4, 2013
    Posts:
    21
    Yep, that was the issue. I've stopped disabling the Input Manager and everything works fine now. Thank you very much!

    No problem, me disabling the Input Manager at the time was just an easy way to disable all inputs when I didn't want them. As I've improved how I handle inputs in the UI and such, simply disabling all maps works wonders now. :)
     
    guavaman likes this.
  4. s8cusyqr

    s8cusyqr

    Joined:
    Jul 9, 2018
    Posts:
    7
    I have a dictionary of keycodes. How to change keycodes to be compatible with rewired?
    private static Dictionary<KeyCode, ButtonAction> _keyCodeToActionMapping = new Dictionary<KeyCode, ButtonAction>
    {
    { KeyCode.LeftArrow , ButtonAction.Left },
    { KeyCode.RightArrow, ButtonAction.Right },
    { KeyCode.UpArrow , ButtonAction.Up },
    { KeyCode.DownArrow , ButtonAction.Down },
    { KeyCode.Escape , ButtonAction.Cancel },
    { KeyCode.Return , ButtonAction.Shoot },
    { KeyCode.Y , ButtonAction.Taunt },
    { KeyCode.M , ButtonAction.Strafe },
    };
     
  5. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,495
    I don't know what you're trying to achieve, but there's no reason at all to try to use KeyCodes as keys for Actions.

    See this:
    http://guavaman.com/projects/rewired/docs/HowTos.html#exporting-constants
     
  6. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,495
  7. Karearea

    Karearea

    Joined:
    Sep 3, 2012
    Posts:
    386
  8. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,495
    That's not the appropriate topic for it. It's already in the documentation in 3 places in addition to the console message displayed in the editor and logged.

    http://guavaman.com/projects/rewired/docs/KnownIssues.html#windows-standalone-il2cpp
    http://guavaman.com/projects/rewired/docs/KnownIssues.html#osx-standalone-il2cpp
    http://guavaman.com/projects/rewired/docs/KnownIssues.html#linux-standalone-il2cpp
     
  9. Thermos

    Thermos

    Joined:
    Feb 23, 2015
    Posts:
    148
    Hi,

    I used to pause input via changing the "Rewired Input Manager" GameObject's activation. But I tried to upgrade to 1.1.16 from 1.1.14, seems deactivating input manager will set controllers to null and loose current map activation settings(I also modify map activation in run-time like switching from battle mode to UI mode). So my approach of pausing input is not suitable anymore.

    Is there any nice API to pause and resume entire input system like an Active{set;} ?
     
  10. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,495
    See my answer above: https://forum.unity.com/threads/rewired-advanced-input-for-unity.270693/page-86#post-3553395

    Disabling the Rewired Input Manager to disable input was never a proper or allowed way to disable input. See the Input Manager docs:
    • Do not disable or enable the Input Manager during runtime.
    Disabling it had a lot of side effects you were probably not aware of. It was not designed to be disabled and have its Update function interrupted.

    There is no "disable all input" method. When you want to stop processing input for some reason, you should be setting a flag (or flags), or set a state somewhere in your code that can be checked to determine whether input should be processed or not and anything that uses input should check permissions before processing it. Stopping input as a means of preventing your scripts from processing that input isn't the best approach.

    There are many means of flow control in Rewired already:
    • Enabling/disabling Controller Maps
    • Enabling/disabling Controllers
    • Assigning and unassigning Controllers to Players
    • Enabling/disabling individial Action Element Maps (bindings)
    While those exist, they're not meant to be a substitute for a larger permission system in your game.
     
  11. Thermos

    Thermos

    Joined:
    Feb 23, 2015
    Posts:
    148
    Thanks! That's very detail explanation.
     
  12. aer0ace

    aer0ace

    Joined:
    May 11, 2012
    Posts:
    1,511
    I'm trying to use Rewired for the first time, and I'm a little stuck on mouse input.
    I tried using GetAxis() from the SystemPlayer and from the first Player, and I get different results.

    It seems that the SystemPlayer returns absolute screen position, and the first Player returns a delta vector.

    What is the appropriate way to generate an absolute screen position from a Player? I tried adding Mouse.screenPosition or Mouse.screenPositionPrev to no success.
    Is it most appropriate to just use the SystemPlayer for mouse absolute screen position?
     
    Dustin88 likes this.
  13. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,495
    This isn't possible. The absolute position is never returned through Mouse X and Y. The only way to get the absolute position is through Mouse.screenPosition.

    All Players get Controller axis values through Controller.GetAxis. There's no way the System Player could be getting different values from the Controller (Mouse) than another Player. The only way the value could differ by the time it comes out through the Action is through things that modify the Action's value. That is Controller Maps (bindings) and Input Behaviors.

    I suggest you recheck all your Controller Maps and make sure you are actually binding Mouse X/Y to the Actions you think and nothing else is bound that may also be returning at the same time. Also check your Input Behaviors to see if you're transforming the Mouse XY axis value.

    Use Debug Information to see what's going on:
    http://guavaman.com/projects/rewired/docs/Troubleshooting.html#debug-information

    Look at the information live because you can also be thrown off if you're loading some XML data info System Player that's changing its bindings and/or input behaviors.

    You can also look at the sources of the Action to determine if something is contributing to the Action value you're not aware of (some old binding, etc.):
    http://guavaman.com/projects/rewired/docs/HowTos.html#get-contributing-input-sources
     
  14. aer0ace

    aer0ace

    Joined:
    May 11, 2012
    Posts:
    1,511
    Thanks for the tips. This will help. Actually, now that I think about it, the SystemPlayer did not have a Mouse Map assigned to it. So, I'm assuming it was just falling back on to Unity's input, because the mouse cursor was definitely moving all around the screen as expected. I'll have to check to be sure once I'm in front of it. Thanks again for the tips.
     
  15. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,495
    If the System Player has no Mouse Map assigned to it, no input will ever come through any Action in System Player from Mouse input. No input is possible without a Controller Map. That's why I said to check the Controller Maps. You may have some assignments you don't realize sending input into the Player from other sources.
     
  16. aer0ace

    aer0ace

    Joined:
    May 11, 2012
    Posts:
    1,511
    Okay, I've tracked down my issues. Thanks. I'm currently trying to integrate Rewired with NGUI, and I had some NGUI properties still being used. Basically, my issue is, I'd like to use Mouse.screenPosition, since that's the position of the hardware cursor, when in Mouse mode. However, I'd also like to support the analog stick on an 360 controller, which would rely on the X/Y deltas instead, which GetAxis() provides.

    I would preferably like to use GetAxis() for both 360 controller and mouse, but that would mean I would need to cache a starting location to initialize, and then use that cached location as the screenPosition? Should I just start the cached position in the center of the screen and do something like (pseudocode):

    Code (CSharp):
    1.  
    2. GetAxis(string name)
    3. if (player.hasMouse)
    4. {
    5. switch(name)
    6. {
    7.   case("Horizontal"):
    8.       return Mouse.screenPosition.x;
    9.   case("Vertical"):
    10.       return Mouse.screenPosition.y;
    11. }
    12. }
    13. else
    14. {
    15. switch(name)
    16. {
    17.   case("Horizontal"):
    18.       lastScreenPosX = lastScreenPosX + player.GetAxis("MoveHorizontal");
    19.       return lastScreenPosX;
    20.   case("Vertical"):
    21.       lastScreenPosY = lastScreenPosY + player.GetAxis("MoveVertical");
    22.       return lastScreenPosY;
    23. }
    24. }
    25.  
    ?
     
  17. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,495
    That would work, but you'd need to process the GetAxis value * Time.deltaTime and a pointer speed. You also would want to clamp the value to the screen width and height so it doesn't go out of bounds.
     
  18. Meowx

    Meowx

    Joined:
    Oct 10, 2015
    Posts:
    33
  19. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,495
    No, it made Unity angry. Unity is responsible for loading the assemblies, not Rewired. Rewired is just one of those assemblies that Unity has to load. That error is showing Unity is just simply not loading the assembly.

    See the docs, Updating Rewired - Issues when Updating:

    Issues when Updating

    If you experience issues when updating, you may find it easier just to delete the Rewired folder and reimport it. Rewired stores no data in its folder so you are safe to just delete it and reinstall it in any situation where problems occur. However, during this delete and reinstall process, be sure you DO NOT save your scene until after importing Rewired again and verifying the Rewired Input Manager works as expected.

    See Troubleshooting - Doing a clean reinstall of Rewired
     
  20. Meowx

    Meowx

    Joined:
    Oct 10, 2015
    Posts:
    33
    thanks, will check it out!

    edit: double checked that I had the most recent version of Rewired, did a fresh install, and all's well again!
     
    Last edited: Jul 11, 2018
    guavaman likes this.
  21. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,548

    There is older post on integrating Rewired and NGUI here that you might find useful.

    https://forum.unity3d.com/threads/rewired-advanced-input-for-unity.270693/page-40#post-2613846
     
    guavaman likes this.
  22. aer0ace

    aer0ace

    Joined:
    May 11, 2012
    Posts:
    1,511
    @longroadhwy , thanks for the link. I've stumbled upon this code over on the Tasharen forums.

    But I think I need to step back to describe what I'm doing.

    I'm making a turn-based strategy game where the primary view is a board of units. The primary input method is mouse, but I'd also like to support keyboard only and gamepad only control.

    The example provided uses mouse input in a delta capacity via GetAxis() rather than an absolute screen capacity for clicking on objects with mouse cursor accuracy.

    Does this mean that the best way to deal with my situation is to use Mouse.screenPosition from Rewired as I describe above, or should I implemented the "universal" solution that uses GetAxis() to abstract the input?

    So, NGUI aside, I think I have to get back to basics and nail this down first.

    And then, overriding GetAxis() for NGUI has been pretty challenging to get right given the requirements I described above.

    EDIT:
    I should also mention that with using GetAxis() I can surely create my own software cursor, but I was hoping to use the hardware cursor for performance reasons, hence the additional desire to use Mouse.screenPosition
     
    Last edited: Jul 11, 2018
  23. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,495
    If you want to use the hardware cursor, you could only use it when the user is using the mouse. So you would be having two different cursors -- hardware for mouse and software for other controllers. If you wanted to move the hardware cursor with a joystick, you'd have to do it through native code on the target platform because Rewired does not allow you to set the mouse position on any platform.
     
  24. edu-silveira777

    edu-silveira777

    Joined:
    Sep 12, 2012
    Posts:
    1
    Hello, Guavaman !
    Firstly, thank you for providing such a complete and awesome asset that is facilitating our lives a lot.
    I have a question about mappings: One new feature we're adding to our new co-op game is Split Controllers to allow 2 players to play in one controller. We have achieved a working solution, by "cutting" the controller in half, inverting the joystick axises and rotating the controller. So in the split mapping, everything "rotates" like a Joy-Con.
    However, in our solution, each "half" of the controller's actions are mapped in the same category. So, even though physically there are 2 players using the same controller, Rewired is only using Player0 for TWO characters.

    My question is: Is it possible to have 2 rewired players use the same controller? Our solution works but is kinda weird, since we're not using all the players we've listed in the Input Manager. I think it would make more sense having Player0 and Player1 each using a half of the controller (so, the controller would use 2 mappings: SplitLeft for 0 and SplitRight for 1). The way we're doing now, only Player0 is using a Split mapping, that has actions mapped for both halves of the controller.

    So, in case my explanation was a bit confusing:
    Game now: Single split mapping that has actions for both sides of the controller. If a split mapping is identified, the game adds 2 characters, each listening to the mapping's respective actions. There are 2 people playing in the same controller, but only one rewired player.
    What I want to achieve: 2 split mappings, one for each side of the controller: the game adds the 2 characters, one listening to SplitLeft's mapping and the other to SplitRight's mappings. There are 2 people in the same controller and 2 rewired players.

    Thank you in advance !
     
    Last edited: Jul 12, 2018
  25. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,495
    Thanks!

    Of course. They Keyboard is by definition a shared controller. Your controller maps determine what inputs on that controller are mapped to what Actions for a Player. Look at any of the included examples like EightPlayers to see one way of doing it on a keyboard using Layouts.

    Assign the controller to multiple Players:
    http://guavaman.com/projects/rewired/docs/HowTos.html#assigning-controllers

    You will have to manage Joystick assignment yourself at this point because Rewired's auto-assignment system is just going to assign the Joystick back to the first Player that previously owned it on reconnect, not both.

    You will also need to manage what maps are loaded/enabled when reassigning controllers around and such:
    http://guavaman.com/projects/rewired/docs/HowTos.html#managing-controller-maps-runtime
     
    edu-silveira777 likes this.
  26. socobons

    socobons

    Joined:
    Jun 3, 2015
    Posts:
    15
    Hello guavaman! First of all thanks for the incredible work you have been doing!
    I'd adquire rewired some days ago and I have my game fully supported with any kind of inputs. Amazing!!

    I have a question though:
    I've created a canvas for my main menu following the documentation, all the touchs controls are working as a charm.
    The next step was to add some kind of navigation through the menu by any kind of controller or the keyboard.
    My approach as in other games i've released is to iterate a list of the buttons presents in the UI and trigger the action that the TouchControll has linked through the editor via the TargetButton.

    So my question is : Is possible to manually trigger any kind of action via custom script?
    Usually I used the Unity Button Onclick, doing an Invoke manually when needed.

    Thanks again for the terrific work you are doing!!
     
  27. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,495
    Thanks!

    Yes. Custom Controllers.
     
  28. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,548
    I can see this being useful for flight games that have drones. I will have to take a look 3Dconnextion devices in more detail. I did see some industrial controllers from APEM (they are the parent company of CH Products) that would be a good fit too. So many options to think about now. :D
     
    guavaman likes this.
  29. marcos

    marcos

    Joined:
    Oct 18, 2009
    Posts:
    592
    Hi @guavaman

    I'm trying to get the Bolt integration working with the latest version of Bolt (1.4).

    I keep getting the following error whenever I attempt to add the units:
    Does the integration require an update?

    Kindest,
    Mark
     
  30. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,495
    Probably. He must have made some breaking change. I cannot support multiple versions of Bolt. I will look into updating the integration. I'm considering just getting rid of it all together. There's little point in having it. All it does is add input events. You can just as easily use the input polling system with no integration whatsoever.
     
  31. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,495
    Rewired 1.1.18.0 is now available for registered users. If you'd like to get early access to updates, please contact me here. The update will be available on the Unity Asset Store as soon as they approve it.

    Please see Updating Rewired before updating.

    Release Notes:

    1.1.18.0:

    Changes:
    - Added Input Manager mappings for Unity joysticks 12-16 in Unity 2018+.
    - Improved XML handling.
    - Added option to export data to JSON.
    - Added internal checks and error logging when attempting to use invalidated Rewired objects created by a Rewired Input Manager that has been destroyed or reset.
    - Modified Control Mapper assignment swapping system to prevent user from creating non-visible mappings under certain scenarios when a swap of a certain combination of full-axis and split-axis fields would create an additional mapping that wouldn't fit in the visual display based on the number of columns chosen for the current Controller type. The "Swap" button is no longer displayed if the swap operation would create a non-visible mapping.
    - Rewired Standalone Input Module: Added "Allow Touch Input" inspector option.
    - Added support for Flight Stick, Steering Wheel, Guitar, and Drum controller types on PS4 platform.
    - Added Six DoF Controller Template option to PlayMaker integration.
    - Added Six DoF Controller Template option to Behavior Designer integration.
    - Added ControllerTemplateMap system for saving and loading maps for Controller Templates as opposed to maps for specific controllers.
    - Modified many PlayMaker Actions removing required data storage fields when unnecessary.
    - Re-created Bolt integration due to breaking changes made in Bolt 1.4.0.

    API Changes:
    - Added ControllerMap.ToJsonString method.
    - Added ControllerMap.ToControllerTemplateMap method.
    - Added CalibrationMap.ToJsonString method.
    - Added CalibrationMap.ImportJsonString method.
    - Added CalibrationMap.ImportXmlString method.
    - Added InputBehavior.ToJsonString method.
    - Added InputBehavior.ImportJsonString method.
    - Added ControllerWithAxes.ImportCalibrationMapFromJsonString method.
    - Added Player.ControllerHelper.MapHelper.AddMapFromJson methods.
    - Added PS4ControllerExtension class.
    - Added ControllerMap.controller property.
    - Added ControllerTemplateMap class.
    - Added ControllerTemplateActionElementMap class.
    - Added ControllerTemplateActionAxisMap class.
    - Added ControllerTemplateActionButtonMap class.

    New Controller Definitions:
    - 3Dconnexion SpaceMouse - includes support for SpaceMouse Compact and SpaceMouse Wireless.
    - Sony PS4 Flight Stick
    - Sony PS4 Steering Wheel
    - Sony PS4 Guitar
    - Sony PS4 Drums

    Modified Controller Definitions:
    - 3Dconnexion SpaceNavigator: Changed display name to "3Dconnexion SpaceNavigator".
    - 3Dconnexion SpaceExplorer: Changed display name to "3Dconnexion SpaceExplorer".

    Bug Fixes:
    - Control Mapper: Fixed issue where swapping assignments on a conflict could drop the assignment instead of swapping it in certain scenarios.
    - Control Mapper navigation now works properly in all Canvas space modes.
    - Unity Editor, native input: Fixed crash when a critical exception was thrown during initialization and then subsequently re-importing scripts or DLLs in the project.
    - Fixed exceptions thrown when recompiling during Play mode introduced in recent update.
    - WebGL builds no longer log erroneous error message saying native input could not be initialized.
    - Enabling and disabling the Rewired Input Manager with OnGUI enabled in Settings no longer causes multiple OnGUIHelper components to be added to the Rewired Input Manager.
     
  32. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,495
    Rewired 1.1.18.0 supports Bolt 1.4.0 now.
     
    MrG likes this.
  33. marcos

    marcos

    Joined:
    Oct 18, 2009
    Posts:
    592
    Legend! Thank you @guavaman !
     
    guavaman likes this.
  34. IceBeamGames

    IceBeamGames

    Joined:
    Feb 9, 2014
    Posts:
    167
    Hey @guavaman

    I was wondering if there was a simple way to disable input modifiers in the control mapper?

    I reason is that I have icons for each mapped key in game and don't really want to produce an entire new set of icons for every combination of ctrl+A shift+: etc. etc.
     
  35. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,495
    No. If an option exists, it would appear in the inspector.

    Use the ActionElementMap keyCode and modifierKey1, modifierKey2, and modifierKey3 to display glyphs for keyboard keys. You should not have to make a single icon for every combination of keys. Display up to 4 icons in succession for modified keys.
     
  36. zapposh

    zapposh

    Joined:
    Nov 12, 2016
    Posts:
    117
    Just updated to Rewired 1.1.17.0 (no sign of 1.1.18.0 yet on the asset store).

    I now have the following errors:
    Assets/Rewired/Integration/UnityUI/RewiredStandaloneInputModule.cs(191,27): error CS0117: `Input' does not contain a definition for `mousePresent'
    Assets/Rewired/Integration/UnityUI/RewiredStandaloneInputModule.cs(342,38): error CS0117: `Input' does not contain a definition for `touchSupported'
    Assets/Rewired/Integration/UnityUI/RewiredStandaloneInputModule.cs(406,42): error CS0117: `Input' does not contain a definition for `touchCount
    Assets/Rewired/Integration/UnityUI/RewiredStandaloneInputModule.cs(407,41): error CS0117: `Input' does not contain a definition for `GetTouch'
    Assets/Rewired/Integration/UnityUI/RewiredStandaloneInputModule.cs(463,38): error CS0117: `Input' does not contain a definition for `touchCount'
    Assets/Rewired/Integration/UnityUI/RewiredStandaloneInputModule.cs(464,37): error CS0117: `Input' does not contain a definition for `GetTouch'
    Assets/Rewired/Integration/UnityUI/RewiredStandaloneInputModule.cs(483,26): error CS0117: `Input' does not contain a definition for `touchCount'

    Deleted the Rewired folder. Re-installed. Same problem. First time this happens.
    I don't know if I can somehow roll-back because now the project does not compile.
    Unity 2018.2.0f2
     
  37. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,495
    You have some global class in your project called "Input" that is causing the compiler to think that class should be used instead of UnityEngine.Input. This has nothing to do with upgrading Rewired. Rename the global Input class wherever it exists in your project. Every script out there that uses UnityEngine.Input will break, not just RewiredStandaloneInputModule.cs.
     
  38. zapposh

    zapposh

    Joined:
    Nov 12, 2016
    Posts:
    117
    Surprising it did not matter for the last 3 months. Renamed the input class, reinstalled rewired and now all is good, thanks.
     
  39. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,495
    The only way that's possible is if the RewiredStandaloneInputModule was not installed. Something must have prevented it from being installed or you deleted it in your previous installation. When you updated it, it automatically installed it again.
     
  40. alteredmatter

    alteredmatter

    Joined:
    Sep 14, 2016
    Posts:
    26
    Hello @guavaman,
    we're working on the remapping options for our game with Rewired (latest version available at the store right now, 1.1.17.0), and we're getting an odd issue and we don't know if it's something we're doing wrong.

    Basically, its seems that when listening to this:
    Code (CSharp):
    1. InputMapper.Default.InputMappedEvent += OnInputMapped;
    the axisContribution in the InputMapper.InputMappedEventData object we receive in our "OnInputMapped()" is always positive, even when it is defined as negative.

    We have an UI element with a custom script that we use to configure the action to remap in the Inspector (with some parameters of actionID, axis contribution, axis range, etc.). When clicking on that button, we call the InputMapper to remap the action linked to it (allowing axes and the other options) like this:
    Code (CSharp):
    1.  
    2. //...
    3. keyToChange = new InputMapper.Context() {
    4.        actionId = myActionID,
    5.        controllerMap = myActions[0].controllerMap,
    6.        actionRange = myAxisRange,
    7.        actionElementMapToReplace = myActions[0]
    8. };
    9. //...
    10. InputMapper.Default.Start(keyToChange);
    But it seems that we are always receiving a positive contribution on the callback, even if we can check that the actionElementMapToReplace is correctly set.

    As an example, we have the axis action "Move Vertical", with its positive/negative contributions as "Move Up"/"Move Down". We see that the actionElementMapToReplace we pass to the InputMapper is set to "Move Down" with a Negative axisContribution, but we later read a "Move Up" action.

    Is there something we could be missing?

    EDIT: seems that we see this problem when the myAxisRange is set to Full. If we set the myAxisRange to Negative, the axisContribution we read later is Negative too. But when setting it to Full it always returns a Positive axisContribution, even if it was defined as Negative before.
     
    Last edited: Jul 23, 2018
  41. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,495
    That's how it's supposed to work.

    Context.actionRange denotes the range of the input field the user is configuring:
    The range of the Action's value to map input to. For example, for an axis-type Action, should user input be mapped to the full range of the Action or just one side of the Action (+/-)?

    By setting Context.actionRange, you're telling Input Mapper to listen for a full-axis assignment. Any axis you press while listening will return an ActionElementMap with a full-axis assignment and axisContribution will be irrelevant so set to positive. A full-axis assignment does not have an axis contribution. It is a full axis so therefore has a contribution of positive and negative and uses the invert field. Only button and split axis assignments use axisContribution to determine the element's contribution the final Action value.
     
  42. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,495
    Rewired 1.1.18.0 is available on the Unity Asset Store!
    A nice addition in the version is Controller Template Maps. They are used to convert back and forth between a Controller Map which maps Actions to Controller elements and a Controller Template Map which maps Actions to Controller Template elements. The only use for this at present is to convert Controller bindings to Controller Template bindings so you can save and load them. This is only useful if you want to save generic bindings for all Gamepads for example and do not want to use the default method where every different Gamepad's bindings can be saved / loaded individually. I think the original method is better, but this version can be useful on certain platforms such as Nintendo Switch so remapping controls on one Joy-Con type filters down to the others without the user having to remap them again for each type. You cannot directly bind Actions to Controller Template Maps as the Player still uses Controller Maps individual to the Controller being used for binding.
     
  43. alteredmatter

    alteredmatter

    Joined:
    Sep 14, 2016
    Posts:
    26
    Thanks for the explanation, it make sense to us now. In this case we were working with this axis action "move vertical", but configuring the keyboard remapping. We were working with a general remapping ui for all controllers, and testing both gamepad and keyboard at the same time (that's why we had this set as full range, and hence the confusion), but we should clearly set these ranges correctly for the different gamepad/keyboard cases. Thanks!
     
  44. _eternal

    _eternal

    Joined:
    Nov 25, 2014
    Posts:
    263
    Ran into an issue with the Event System just now. I'm not sure if it's a bug or just a mistake on my part, but repeatDelay isn't working correctly.

    My Input Module component looks like this:

    Unity_2018-07-24_10-46-35.png

    And here's what happens when I hold a direction down in the pause menu: https://my.mixtape.moe/rzzkcv.webm

    So if I hold a direction without any other input, the Event System works as expected. It pauses for 3 seconds and then starts looping inputs 10 times per second. However, if I press one direction and then another, the repeat delay doesn't work. The Event System immediately starts repeating inputs, as you can see in the webm.

    I didn't change the repeatDelay field anywhere in my project, and in general I haven't tweaked the Event System much so I'm not sure what the issue is.
     
  45. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,495
    That's why Rewired's Control Mapper has 3 fields per axis-type Action and the full-axis field is greyed out for the Keyboard:

     
  46. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,495
    I just tested and I cannot reproduce this. What version of Rewired are you using?

    Edit: Wait, I found it. You can't press opposite directions. You only get the issue if you press a direction 90 degrees from the first direction. So if you start by pressing down, the 2nd press has to be left or right to get the issue.
     
    Last edited: Jul 24, 2018
  47. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,495
    It's a bug, but it's Unity's bug. It happens the same with the Unity StandaloneInputModule and it's due to their code when implementing the repeat delay:

    https://bitbucket.org/Unity-Technol...tSystem/InputModules/StandaloneInputModule.cs

    Code (csharp):
    1. // Line 381:
    2. /// <summary>
    3. /// Process keyboard events.
    4. /// </summary>
    5. protected bool SendMoveEventToSelectedObject()
    6. {
    7. float time = Time.unscaledTime;
    8.  
    9. Vector2 movement = GetRawMoveVector();
    10. if (Mathf.Approximately(movement.x, 0f) && Mathf.Approximately(movement.y, 0f))
    11. {
    12. m_ConsecutiveMoveCount = 0;
    13. return false;
    14. }
    15.  
    16. // If user pressed key again, always allow event
    17. bool allow = input.GetButtonDown(m_HorizontalAxis) || input.GetButtonDown(m_VerticalAxis);
    18. bool similarDir = (Vector2.Dot(movement, m_LastMoveVector) > 0);
    19. if (!allow)
    20. {
    21. // Otherwise, user held down key or axis.
    22. // If direction didn't change at least 90 degrees, wait for delay before allowing consequtive event.
    23. if (similarDir && m_ConsecutiveMoveCount == 1)
    24. allow = (time > m_PrevActionTime + m_RepeatDelay);
    25. // If direction changed at least 90 degree, or we already had the delay, repeat at repeat rate.
    26. else
    27. allow = (time > m_PrevActionTime + 1f / m_InputActionsPerSecond);
    28. }
    29. if (!allow)
    30. return false;
    31.  
    32. // Debug.Log(m_ProcessingEvent.rawType + " axis:" + m_AllowAxisEvents + " value:" + "(" + x + "," + y + ")");
    33. var axisEventData = GetAxisEventData(movement.x, movement.y, 0.6f);
    34.  
    35. if (axisEventData.moveDir != MoveDirection.None)
    36. {
    37. ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, axisEventData, ExecuteEvents.moveHandler);
    38. if (!similarDir)
    39. m_ConsecutiveMoveCount = 0;
    40. m_ConsecutiveMoveCount++;
    41. m_PrevActionTime = time;
    42. m_LastMoveVector = movement;
    43. }
    44. else
    45. {
    46. m_ConsecutiveMoveCount = 0;
    47. }
    48.  
    49. return axisEventData.used;
    50. }
    It persists as of at 2018.2.0f2. I suggest you report it to Unity. I will see if I can find a solution.

    Debugging and working around bugs in dependencies has taken up sooooo much time over the last 4 years of Rewired's existence, I just cant't believe it still. This is nothing compared to Windows at least. That was collectively solid months of time with all the breaking bugs they introduced in drivers, etc. over the years. But they're only one of dozens...
     
    Last edited: Jul 24, 2018
  48. _eternal

    _eternal

    Joined:
    Nov 25, 2014
    Posts:
    263
    Oh, wow. Thanks for debugging anyway. I'll report it to Unity and we'll see what happens.
     
  49. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,495
    After having messed with this for a while, I'm back to my original conclusion -- this is the designed behavior. The source code commenting shows it:

    Code (csharp):
    1. // Otherwise, user held down key or axis.
    2. // If direction didn't change at least 90 degrees, wait for delay before allowing consequtive event.
    3. if(similarDir && m_ConsecutiveMoveCount == 1) { // this is the 2nd tick after the initial that activated the movement in this direction
    4.     allow = (time > m_PrevActionTime + m_RepeatDelay);
    5.     // If direction changed at least 90 degree, or we already had the delay, repeat at repeat rate.
    6. } else {
    7.     allow = (time > m_PrevActionTime + 1f / m_InputActionsPerSecond); // apply input actions per second limit
    8. }
    It seems to me they are trying to balance between having something that acts like a keyboard repeat for keys and D-Pads but remains responsive when using stick axis movements that are not on perfect up/down/left/right directions to allow you to move around the fields to some degree freely after the repeat delay has expired. So it's not a strict repeat delay.

    The one actual bug I did find in their logic was with regard to GetButtonDown handling. I did my testing using the keyboard to reproduce the problem using Unity's StandaloneInputModule. You were using a joystick. You probably wouldn't see this issue on Unity's input system if using a joystick because on one difference -- Rewired can query the GetButtonDown state of a joystick axis which factors into this equation causing it to execute code that would normally only have been executed in Unity's version for a keyboard key or a button press triggering the movement. Unity's code effectively treats keys and joysticks differently because of that difference where Rewired using the same code would yield a different result with a joystick. With keyboard input, they'd behave identically and Unity's system would exhibit the problem also.

    Replace Rewired/Integration/UnityUI/RewiredStandaloneInputModule.cs with this one which attempts to fix this problem as well as a couple of other related problems. It's possible that this change will result in other artifacts I haven't discovered however.
     

    Attached Files:

    Last edited: Jul 24, 2018
  50. aer0ace

    aer0ace

    Joined:
    May 11, 2012
    Posts:
    1,511
    Apologies if this has been asked before. I understand why I'd use Map Categories, but is there any documentation on using Action Categories? If not, how are they used or what are they used for? The most I can reason to use it for would be for organizational purposes, perhaps to display to the user...