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,876
  2. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    399
  3. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,458
    That is nice to have Stadia platform support already!
     
  4. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,876
  5. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    723
    Hi @guavaman, I've just come across a weird (and very annoying) bug that seems to be related to Rewired. Basically it's an issue (in 2019.1.5f1) when suddenly my keyboard stops working in the editor. Can't type or rename anything. Keyboard works fine in all other current apps.

    It's like all the key press events are eaten away by something. Please note that this does NOT happen at runtime, just when working normally in the editor. I'm talking normal interaction in the editor, not in-game issues.

    The reason I believe it could be related to Rewired is that the issue goes away when I close the Rewired editor window (it's usually docked in a tab in my layout). Would you mind having a look at this please?

    Update:
    When I close the Rewired editor window I indeed regain my keyboard for normal Unity editor activities but if I then reopen the Rewired editor window I cannot type anything in it (ie. renaming an action). So I still have to close down Unity and relaunch it. Which is, of course, rather annoying.
     
    Last edited: Sep 14, 2019
  6. Mojo-Game-Studio

    Mojo-Game-Studio

    Joined:
    Sep 18, 2015
    Posts:
    63
    Hi, Does this asset support oculus quest controllers?
     
  7. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,876
  8. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,876
    1. I need to know what platform this is. Unity Editor runs on 3 platforms.
    2. I cannot reproduce this on 2019.2.5f1 Windows.
    3. Rewired does nothing that could possibly affect the editor's ability to detect keyboard keys. Absolutely zero native code runs in the editor outside of Play mode.
    4. The only possible thing one could do to prevent keyboard keys from functioning in the editor would be to call event.Use() on keyboard events so they are used before the editor processes them. Rewired never does this. You can see this by pressing W or E in the Rewired editor and you'll see the Unity tools change in the upper left.
    5. Any change in behavior can only possibly have come from a change in Unity. They broke something and it should be fixed on their end. Rewired's editor code works in every other versions of Unity from 4.3 to 2019.3. What you're seeing is only a symptom of the real issue underneath.
    I have to assume that your issue is either caused by some innocuous and unrelated function call made by Rewired triggering something deeper in the Unity editor revealing a bug (like calling Repaint in OnGUI), or it's simply a coincidence and the action of closing the window is triggering something else in Unity that is clearing out whatever is causing the bug.

    I have experienced something very similar to what you are describing where changing names of objects in the hierarchy fails for an unknown reason. When I try to type a letter, it just commits instead. I can however change names consistently in the inspector instead. This has been happening probably since the new prefab system update. (I am using 2018.4.8f1.) It is not always consistent though. Sometimes renaming in the hierarchy panel works, sometimes it doesn't. I haven't found a cause or solution, but it's not related to having the Rewired editor open as I almost never have it open in the project I'm currently working on.
     
    Last edited: Sep 14, 2019
    Seith likes this.
  9. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    723
    You're right, it sounds more like a Unity bug at this point. Currently the fix is to right-click anywhere in the editor and then the keyboard events are back to normal. Thanks!
     
  10. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,876
    That's interesting and a good find. Please report it to Unity.
     
  11. JoMaHo

    JoMaHo

    Joined:
    Apr 2, 2017
    Posts:
    94
    Hi!
    I have ran into an issue. I´m on mac, Unity 2019.2.0f1. I ported a functioning project from 2018.2.3, with a Steelseries Nimbus controller (due to AR Foundation requirements). It had mapped all buttons and sticks, all working fine. I updated Rewired to latest 1.1.28.0 after utdating the project to 2019.2.0f1.

    Now some buttons work, not the sticks, R2, R1. D-pads work, X,Y,B,A, L1,L2 also Seems like values are not read from the script. I have double cheked the joystick mappings and tripple checked the reference in the script:

    Code (CSharp):
    1. // MyCharacter.cs - A simple example showing how to get input from Rewired.Player
    2.  
    3. using UnityEngine;
    4. using System.Collections;
    5. using Rewired;
    6.  
    7. [RequireComponent(typeof(CharacterController))]
    8. public class JoyControlBizzi : MonoBehaviour {
    9.  
    10.     public int playerId = 0; // The Rewired player id of this character
    11.  
    12.     //public float moveSpeed = 3.0f;
    13.     //public float axisTest = 0.0f;
    14.     private Player player; // The Rewired Player
    15.     private CharacterController cc;
    16.  
    17.  
    18.     public float leftAxisX = 0.0f;
    19.     public float leftAxisY = 0.0f;
    20.     public float rightAxisX = 0.0f;
    21.     public float rightAxisY = 0.0f;
    22.     public bool dpadRight ;
    23.     public bool dpadLeft;
    24.     public bool dpadUp;
    25.     public bool dpadDown;
    26.     public bool lookAtCamera = false;
    27.     public bool togglePlane = false;
    28.     public bool menuButt;
    29.     public bool l1 = false;
    30.     public bool l2 = false;
    31.     public bool r1 = false;
    32.     public bool r2 = false;
    33.     public bool Y = false;
    34.     public bool X = false;
    35.     public bool A = false;
    36.     public bool B = false;
    37.  
    38.  
    39.     void Awake() {
    40.         // Get the Rewired Player object for this player and keep it for the duration of the character's lifetime
    41.         player = ReInput.players.GetPlayer(playerId);
    42.  
    43.         // Get the character controller
    44.         cc = GetComponent<CharacterController>();
    45.     }
    46.  
    47.     void Update () {
    48.         GetInput();
    49.  
    50.  
    51.                     }
    52.  
    53.     private void GetInput() {
    54.         // Get the input from the Rewired Player. All controllers that the Player owns will contribute, so it doesn't matter
    55.         // whether the input is coming from a joystick, the keyboard, mouse, or a custom controller.
    56.  
    57.         leftAxisX = player.GetAxis("MoveX"); // get input by name or action id
    58.         leftAxisY = player.GetAxis("MoveY");
    59.         rightAxisX = player.GetAxis("LookX"); // get input by name or action id
    60.         rightAxisY = player.GetAxis("LookY");
    61.  
    62.         dpadRight = player.GetButton("DpadRight");
    63.         dpadLeft = player.GetButton("DpadLeft");
    64.         dpadUp = player.GetButton("DpadUp");
    65.         dpadDown = player.GetButton("DpadDown");
    66.  
    67.         menuButt = player.GetButton("Menu");
    68.  
    69.         X = player.GetButton("Menu");
    70.         Y = player.GetButton("Y");
    71.         A = player.GetButton("LookAtCamera");
    72.         B = player.GetButton("B");
    73.  
    74.         l1 = player.GetButton("L1");
    75.         l2 = player.GetButton("L2");
    76.         r1 = player.GetButton("R1");
    77.         r2 = player.GetButton("R2");
    78.  
    79.  
    80.  
    81.     }
    82.  
    83.  
    84.  
    85.  
    86.     }
    87.  
    In the Input manager debugger it reads all the values from all input sourcs for the Nimbus, so it is nothing wrong withe the controller.

    Here are my mappings:



    Any suggestions?

    EDIT: I did a iOS test buld, and there it reads all the buttons correctly. Semmes to ba an MacOS issue then....

    SOLVED: Udated to 2019.2.5, and now all is good!
     
    Last edited: Sep 17, 2019
  12. AlterVorrin

    AlterVorrin

    Joined:
    Oct 11, 2017
    Posts:
    4
  13. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,876
    If you are using Native input, updating Unity will have no effect whatsoever on input values. The only way that would be possible is if you are not using Native input and are using Unity input.
     
  14. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,876
    You can't. That function is designed the way the way the documentation states. Actions in Rewired can always be queried as both a button or an axis. If you want that, you will have to make your own function that iterates through all Actions and skips either Axis-type actions or checks every mapping to see if it's assigned to a physical button depending on the behavior you're after.

    Player.GetAnyButtonXXX acts on Actions. Actions can be queried as both button and axes.
    Controller.GetAnyButtonXXX. acts on physical controller elements, not Actions.
     
  15. mthawley

    mthawley

    Joined:
    Sep 7, 2018
    Posts:
    50
    Hi. I have set up 2 Map Enabler rules (Default and UI) and assigned these to the Player under the Map Enabler helper. I want to assign the UI map to ControlMapper (and future menus when they are created). Could you please explain how to do this? Cheers.
     
  16. AlterVorrin

    AlterVorrin

    Joined:
    Oct 11, 2017
    Posts:
    4
    @guavaman : oh I see, so maybe I can just use `Controller.GetAnuButton*` instead, thank you.

    Imho, the documentation is slightly misleading there; the sentence ` This also applies to axes being used as buttons` to me implies that axes are not by default used as buttons, I think it'd be clearer if it stated 'This will also consider axis changes as button presses' or something in that direction.
     
  17. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,876
  18. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    302
    @guavaman I'm starting to setup UI that dynamically changes depending on the last active controller type.

    I've used the `AddLastActiveControllerChangedDelegate` to subscribe to the event, but the event is never called for me. Player 1 has maps for both Keyboard / Mouse and Joystick and both are working, but when switching between the 2 types of input, I don't seem to get an event raised.

    Any thoughts on what I'm doing wrong? Thanks
     
  19. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,876
    There are two separate AddLastActiveControllerChangedDelegate functions in Rewired. One in Player.ControllerHelper and one in ReInput.ControllerHelper. Which one are you using?

    There is no way the last active controller would not be changing unless a dominant controller has some button or axis that is always stuck on and therefore causing that controller to be considered the active controller. Have you logged what the active controller is?

    https://guavaman.com/projects/rewir..._ControllerHelper_GetLastActiveController.htm

    https://guavaman.com/projects/rewir..._ControllerHelper_GetLastActiveController.htm

    If those functions show the controller is changing and you're not receiving the event, then there must be some problem with how you subscribed to the event, something unsubscribing from it, or some code within the callback that's preventing it from reaching the point where it does what you're expecting it to do. Have you logged the event being called at the very top of the callback to ensure it's not being called?

    Have you looked at what values the controller's buttons and axes are returning?

    https://guavaman.com/projects/rewired/docs/Troubleshooting.html#debug-information
     
    Last edited: Sep 18, 2019
  20. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    302
    @guavaman Thank you so much for the guidance. I finally realized that I was a single index off on the Player that I was getting from the Players list, thus resulting in the issue I was having. Thank you again good sir :D
     
  21. virgiliu

    virgiliu

    Joined:
    Apr 4, 2015
    Posts:
    36
    Hi. I was experiencing slow-downs when using Rewired in a project of mine. I thought it's existing code causing issues, so I created an empty project and imported Rewired. The slow-down (about 12sec) when entering play mode or when playing a build is still there. You can view example here:


    Is there any way to reduce the Rewired load time?
     
  22. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,876
    virgiliu likes this.
  23. Arkade

    Arkade

    Joined:
    Oct 11, 2012
    Posts:
    588
    Hi, Still loving Rewired. Have a, well maybe a misunderstanding or maybe a bug?
    Touch controls joystick ”scale stick range” doesn't do what I'd hope it would.

    I built my touch controls at 800x480 landscape. Configured a touch region with ”move to touch position” and ”hide when idle” so player can control from anywhere on left side of phone.
    Tested controls and joystick feels good.
    Ensured all the transforms & graphics scale (although I'm having difficulty with the thumb stick still). Switched to 1920x1080 and see images (transforms) correctly scaled (including parent 'touch controls' indicated in tooltip).

    Expectation:
    Joystick thumb stick needs to be moved same proportion of 'base' at higher resolution as at lower res.

    Actual:
    Thumb is now constrained to only a tiny fraction of 'base'. This makes controls much more fiddly.

    Workaround:
    Since manually increasing 'stick range' fixes I'm wondering if I need to write something to scale 'stick range' myself.

    Obviously either I'm misunderstanding intent, I'm doing something wrong or something is going wrong. I find it suspicious that I can't seem to get the thumb stick transform to scale properly but that could be RectTransforms catching me out again.

    Demo:
    I've included the touch controls in the WebGL build to show the problem in action -- notice how zone size stays the same regardless of resizing the window:

    https://arakade.itch.io/plunderingplatforms

    (Obviously they're also in the Android build but that's harder for you to experiment with.)

    Any thoughts appreciated.
     
  24. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,876
    Scale Stick Range has no purpose other than to account for parent object Transform scale. That is -- changing the Scale value in the Transform on GameObjects above the joystick GameObject. It is not useful or required for making the joystick range scale when the canvas itself scales bigger or smaller on its own for different screen resolutions. This is already implicit. All values in Touch Controls are based on Canvas pixels, not screen pixels, so they automatically scale with the Canvas. The only time you would use Scale Stick Range is if some GameObject above the joystick (not the Canvas itself) is scaled because that scale has to be accounted for in order to convert the local scaled pixels to Canvas pixels. All my testing shows that everything is working correctly with scaled and non-scaled objects. If this is not working, you must have some kind of setup that is not accounted for in the algorithm I use to go from local scaled pixels to Canvas pixels.
     
    Last edited: Sep 26, 2019
  25. ryfenton

    ryfenton

    Joined:
    Feb 18, 2014
    Posts:
    5
    Anyone know what's the best way to loop over actions and controllers to list:

    A) Which controllers actually have assigned actions (bonus for controllers that are attached but without active action assignments) - even if they are only using the default template.

    B) The assigned actions for each controller,

    and/or

    C) For each action, which controllers and which buttons are currently assigned to them.

    I'm trying to write out a general text config file as a backup for in-game configuration on my test build, and can find some skeleton data in ControllerMaps, InputActions, Controllers, and so on - but no way to properly associate them with eachother without building lots of coorelation of IDs on my own - and it just seems like there must be something I'm missing.

    To do that, I'd like to just be able to write a header section with the list of controller names, loop over the actions, list a bunch of action names followed by controller names and button names with some loose formatting around them.

    Then on program start use a script to update the ReWired config to match, along with my own game config stuff, and go.

    I'd also just like to be able to write and skin my own UI interface for inputs, so I'll logically need that same data access for that once I'm there - but just a quick & dirty config file for now until that's stable, then the config file for backup.

    Anyway - any clues on how to best loop over the InputActions/Controllers/Maps/etc. to get that stuff?
     
  26. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,876
    It sounds like you are essentially trying to expose the Rewired Editor at runtime. The contents of the Rewired Input Manager "database" are not exposed for dumping at runtime. That is not how the system is intended to work. The Rewired Input Manager is designed to be configurable only at edit-time and cannot be modified at runtime, so changes you make in your front-end cannot be pushed into the Rewired Input Manager. You cannot get a list of all the joystick definitions through the public API, nor can you get a list of all the Controller Maps contained in the Rewired Input Manager. If you really want this information, you're going to have to hack it and use undocumented functions that were designed specifically only for internal use, some of which are internal methods and are obfuscated.

    All runtime configuration modification (user mappings) is handled through saving/loading the data to an external file/database through XML or JSON.

    There are many examples showing how to work with Controller Maps and bindings, modifying them, and displaying information contained in them:
    https://guavaman.com/projects/rewired/docs/HowTos.html#managing-controller-maps-runtime
    https://guavaman.com/projects/rewired/docs/HowTos.html#controller-mapping-screen
    https://guavaman.com/projects/rewired/docs/Examples.html#simple-control-remapping
    https://guavaman.com/projects/rewired/docs/Examples.html#control-remapping-1
    https://guavaman.com/projects/rewired/docs/ControlMapper.html
    https://guavaman.com/projects/rewired/docs/Troubleshooting.html#debug-information
    https://guavaman.com/projects/rewired/docs/HowTos.html#display-glyph-for-action
    https://guavaman.com/projects/rewired/docs/UserDataStore.html#playerprefs
     
  27. ryfenton

    ryfenton

    Joined:
    Feb 18, 2014
    Posts:
    5
    Makes sense - I'd much rather roll my own UI rather than use a canned one, even if it is somewhat skinnable and nicely tested. Just my preference/style - to have a consistent/automatable/testable user interface that will update as I improve stuff.

    From browsing as much of the documentation as I could, that seemed to be the case as I read that the controller details were left unexposed.

    I suppose managing the XML/JSON flat file DB would make more maintainable sense - though I may have to update my code if I want to cope with eventual version changes and replacing text in them as needed, I find parsing easier to update than undocumented function signatures with DotFuscate scrambing or whatever.

    Is there any convenient or informal community documentation or anything on those files? I can poke around in them - just nice to see if anyone else has had any experiences along those lines first!

    Can I reset the whole Rewired API in any way to have it reflect changes as I need? Or, short of that, is there any good way of having code execute before the Rewired scripts run, that isn't just forcing execution order on the project as a whole?

    Also - thanks for responding so late in your timezone like that (according to the timestamp) - honestly no need to work too late on my account though! This is all just curiosity from me on what time I need to scope out for this part of my project while I'm doing crude mini-prototypes.
     
  28. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,876
    Rolling your own in-game UI for controller remapping definitely doable. You are not required to use Control Mapper:
    https://guavaman.com/projects/rewired/docs/HowTos.html#controller-mapping-screen

    Creating a control remapping screen is not the same as trying to re-create the Rewired Editor. They serve completely different purposes. You don't need to get a list of all supported Joystick definitions in order to build a remapping screen.

    I think you are still not understanding the system.

    Rewired has two sources of Controller Map data:
    1. Rewired Input Manager
    2. Saved user mappings.

    They serve entirely different purposes.

    Rewired Input Manager:
    Developer-defined default Controller Maps.

    Saved user mappings:
    User-defined mappings created at runtime.

    When Rewired initializes, Controller Maps are loaded for Players based on the settings the in the Players page of the Rewired Input Manager. For Joysticks, Controller Maps are not loaded until the Joystick is assigned to the Player.

    At any point, saved user maps can be loaded and replace the default Controller Maps.

    This is how the system is intended to be used:
    1. Developer creates default mappings in the Rewired Input Manager for desired supported controllers so the user can just "plug and play."
    2. Developer provides the user a control remapping system so they can change their mappings in-game which are saved to XML or JSON.
    3. Developer sets up UserDataStore so the user's saved controls are loaded on start.

    Mappings can be reset to the defaults at any time. All of this is shown in the controller remapping examples.


    XML and JSON are not saved to files unless you choose to do so and implement it yourself. Data is collected and returned as an XML or JSON string by functions in the API. This can then be saved to whatever data storage system you want. You can see how this is saved to PlayerPreferences in the included UserDataStore_PlayerPrefs:
    https://guavaman.com/projects/rewired/docs/UserDataStore.html#playerprefs

    Not sure what your goal here is. Resetting Rewired would serve no purpose. User data is to be loaded over default data on start and on controller assigned, or whenever you choose. This is all shown in the examples.

    It's not late in my time zone. I'm on Pacific time, US. But I do tend to answer support questions any time of day or night.
     
    Last edited: Sep 27, 2019
  29. Maeslezo

    Maeslezo

    Joined:
    Jun 16, 2015
    Posts:
    114
    Hello,

    I am using VR with Rewired. I have seen that several VR devices are defined in Joystick maps.
    Because there are so many VR devices out there and it is so laborious to test them, is there any kind of input emulator that I can use?

    Similar to the Android Emulator Device, but for inputs like VR

    I know this is not actually a Rewired question, but maybe someone can give me a hint.

    Thank you
     
  30. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,458
    There is custom controllers.

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

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,876
    I have no information to give you on this topic. I don't know if anything like this exists and have never looked for anything like it.
     
  32. ryfenton

    ryfenton

    Joined:
    Feb 18, 2014
    Posts:
    5
    Alright - I'm looking through ControlRemappingDemo1.cs, and trying to pick out the lines that do the actual assignment of user map elements... and I'm not able to pick out anything obvious so I can make a test UI using the same methods.

    It seems that we're expected to only handle input mapping indirectly, by having a button associated with a Rewired.InputMapper, then work around whatever the user may have done by systematically refreshing the UI with ReInput.mapping.ActionsInCategory to re-display those same buttons - with no real ability to manage anything more than that.

    No way to assign it to a key of my choice - but only through runtime user action with this example at least.

    So, at least going by this example, if I wanted to, say, have a grid layout for buttons and actions - where say a/b/x/y buttons were always in separate columns, and a selection just flipped assignments around with one selection - I don't know if I can do that with this logic.

    The InputMapper class seems to assume user input, and just lets you populate stuff for that, doesn't let you just tell it a value to set in any way - it's got to be through listening to runtime user input.

    Is there any other method of assigning user control mappings in code?
     
  33. Maeslezo

    Maeslezo

    Joined:
    Jun 16, 2015
    Posts:
    114
    Actually it exists
    https://github.com/matzman666/OpenVR-InputEmulator

    Now, I have to make it work :D
     
  34. LavapotionNiklas

    LavapotionNiklas

    Joined:
    Mar 1, 2017
    Posts:
    4
    We are evaluating the beta for 2019.3.0b4, but the builds are failing with error messages like these:

    "
    [Rewired_Core]Rewired.ComponentControls.Effects.TouchInteractableTransitioner' has an extra field '_transitionColorTint' of type 'UnityEngine.UI.ColorBlock' in the player and thus can't be serialized (expected '_syncFadeDurationWithTransitionEvent' of type 'System.Boolean')"

    Do you have a solution for this, or is there a beta or something that we could use? Or is the only option to wait?

    Thanks in advance!
     
  35. Heinrix

    Heinrix

    Joined:
    Nov 9, 2014
    Posts:
    3
    Hi

    Sorry if I'm asking this in the wrong place but wasn't sure where else to post.

    I'm creating a custom inspector for my character controller and this character controller makes use of [ActionIdProperty(typeof(RewiredConsts.Action))] public int actionButton; when selecting the buttons for each action in the inspector window.
    When making my own inspector editor script how to do I make the Action drop down menu appear or is my only option to just use it as a normal int?
    e.g. EditorGUILayout.IntField("Label", target.int);

    I hope this makes sense.

    Thanks very much for any advice.
     
  36. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,876
    https://guavaman.com/projects/rewired/docs/KnownIssues.html#assembly-errors-2019-2

    This is at the top of the Documentation page as well.

    See this also:
    https://guavaman.com/projects/rewired/docs/KnownIssues.html#assembly-errors-2019-3-alpha-beta
     
  37. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,876
    I don't know. The ActionIdProperty is a Unity Property Attribute which is part of the Property Drawer system. I didn't write the system and there's nothing special or specific about Rewired's use of the system. I would guess you would use EditorGUILayout.PropertyField like you would always use for all fields unless you have a specific reason to make an explicitly typed field.
     
    Last edited: Oct 1, 2019
    Heinrix likes this.
  38. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,876
    Input Mapper was created much later than the general API in response to constant and universal complaints that the remapping API was too complicated and nobody could understand it. The ControlRemappingDemo was retrofitted to use Input Mapper instead of using the general API. Input Mapper is nothing more than a wrapper around the general API, all of which is exposed. Input Mapper does all the work, listens for, and creates the bindings based on user input. All of Control Mapper's code still uses the general API and was not retrofitted to use Input Mapper.

    All control mapping examples regardless of whether or not it is done through the general API or Input Mapper are based on the concept that the user will activate a specific controller element to bind to an Action, that element is detected by polling, and the binding is created. If you want to do your mapping by selecting controller elements from a drop-down list, you are going to have to gather the appropriate information from the controller to display the list of elements and create the bindings manually.

    Remapping is nothing more than interacting with the fundamental building block classes that are involved in input:
    Player
    ControllerMap
    ActionElementMap
    Controller

    Every function you need to do anything you want with regard to changing bindings is in those classes:
    https://guavaman.com/projects/rewired/docs/api-reference/html/T_Rewired_Player_ControllerHelper.htm
    https://guavaman.com/projects/rewir...Rewired_Player_ControllerHelper_MapHelper.htm
    https://guavaman.com/projects/rewir...red_Player_ControllerHelper_PollingHelper.htm
    https://guavaman.com/projects/rewired/docs/api-reference/html/T_Rewired_ControllerMap.htm
    https://guavaman.com/projects/rewired/docs/api-reference/html/T_Rewired_ActionElementMap.htm
    https://guavaman.com/projects/rewired/docs/api-reference/html/T_Rewired_Controller.htm
    https://guavaman.com/projects/rewired/docs/api-reference/html/T_Rewired_Keyboard.htm
    https://guavaman.com/projects/rewired/docs/api-reference/html/T_Rewired_Mouse.htm
    https://guavaman.com/projects/rewired/docs/api-reference/html/T_Rewired_Joystick.htm
    https://guavaman.com/projects/rewired/docs/api-reference/html/T_Rewired_CustomController.htm

    Mapping-related information available in the Rewired Input Manager:
    https://guavaman.com/projects/rewired/docs/api-reference/html/T_Rewired_ReInput_MappingHelper.htm

    Creating a mapping is nothing more than creating or changing ActionElementMaps (bindings) in ControllerMaps for Controllers contained in Players. Read the Controller Maps documentation to understand how this system works.

    There is no step-by-step or how-to documentation on this topic. It has always been considered an advanced topic because of the complexity and only examples are provided (Control Mapper, etc.) as documentation. Input Mapper is the prescribed way to handle user mapping and is far simpler to use.

    The recommended way to present a UI for mapping is Action-centric, not Controller-element-centric like you are describing. Actions are static, controller elements are not and vary depending on which controller is attached.

    If you want this UI to be consistent across controllers, you will definitely have problems with this regardless of what system you use. A/B/X/Y buttons are controller elements. Every single controller has different buttons. And in terms of element indices/id's, no two controllers are guaranteed to have the same element ids for these buttons if the buttons even exist on the controller. You will have to do one of the following: 1) use Controller Templates for binding, converting from the Controller Template id of the element to the Controller element id 2) create different column layouts for each controller you want to support or 3) manually create your own table of mappings of general controller element id to specific controller element id (exactly what Controller Templates do). Making a controller-element-centric UI that works with all controllers is going to be difficult no matter the route you choose. (Controller Template UI example.)

    If you don't care about having a consist UI across controllers and just want to list the controller elements a controller has, that's simple. Loop through all axes and buttons on the controller and get the display name of it from the ElementIdentifier.
     
    Last edited: Oct 1, 2019
  39. ryfenton

    ryfenton

    Joined:
    Feb 18, 2014
    Posts:
    5
    Cool - I'll roll through those, and see if I can make a crude set of functions for assigning values to a user map - then either try and post what I can get working here if you want to have a start to offer future users an easier path towards a customizable controls UI, or else ask questions if I can't solve them after digging through everything, of if it seems there's just not enough exposed to solve the puzzle from my end.
     
  40. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,876
    Read the changes I just made to the response also at the end before you responded.

    "Easier customizable controls UI" is completely relative. It already is easy -- for the vast majority of use cases. Simple Control Remapping shows a simple UI in a 200 line C# script using Input Mapper. This can easily be adapted to a wide range of UI's including graphical UI's that show controller elements, etc. Your use case as I understand it is a very non-standard use case (no-polling for input), and nothing will ever be easy for such custom use cases. Another person will come along with a completely different way they want to use the system.

    Control Mapper itself is also easy-to-use and highly customizable including built-in skinning and localization systems. I think I have put way more than enough effort into this aspect of the software already, offering far, far more out of the box in terms of runtime mapping than any other system out there for input. No amount of "more" will ever be enough to satisfy extremely user-specific use cases.

    Every single thing Input Mapper, Control Mapper, and every other mapping example uses is exposed. If something seems like it isn't exposed, it likely means it doesn't exist.
     
    Last edited: Oct 1, 2019
  41. ryfenton

    ryfenton

    Joined:
    Feb 18, 2014
    Posts:
    5
    Makes sense - I'm working on testing with .CreateElementMap and 'replace' variants, as part of an existing map, and was able to google for some working examples.

    That way, as you say, I can do things like create a dropdown menu for controls, or the grid example if I wanted, have anything I'd need work.

    The first example I was able to find was an appropriate use scenario: A hotbar for dynamically set hotkeys for in-game actions.

    https://github.com/stimmedcow/Outwa...ar/5. ControlMappingPanel-InitMappings-New.cs

    Forgive my dumbness: I try and pick up first on 'best practices' recommended by code new to me, sanity check with a few examples, and make sure I won't hit any obvious roadblocks when adapting a new code set. In this case, the examples I was trying out only used the inputMapper class to do everything, so there wasn't an obvious path to getting everything I wanted done.

    At least with searching for 'ElementMap', there wasn't anything in the Rewired code for anything beyond user polling buttons as mechanisms for a UI - which is cool, but exactly why I'd have questions. Creating an element map just seemed like creating a container for associations, not the actual result I wanted on first glance, and without examples to fall back on using it anywhere, I didn't see a path to assigning keys to actions in script other than user polling.

    With this, I should be able to create my own configurations as needed, update user maps on startup, and make any UI required for future controllers, without being limited to buttons as the only mechanism.
     
  42. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,876
    The Control Mapper source code shows usage of the general API instead of Input Mapper. I can send you the old code to the ControlRemapping1 example from before it was converted to Input Mapper if you want. I never even considered anyone wanting to create a remapping UI that didn't use the polling method to determine what the user wanted to remap.

    But in general, polling does nothing but give information about what the user pressed/moved. After that, it's all the same -- create an ActionElementMap that binds to whatever the user pressed. You can substitute your own values for this step instead of using the polled values and achieve the results you're looking for.
     
  43. LavapotionNiklas

    LavapotionNiklas

    Joined:
    Mar 1, 2017
    Posts:
    4
  44. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    399
    Hi @guavaman

    If I want to manually replace the keycode of an ActionElementMap from some custom save data, is this the correct method to use?

    ControllerMap.ReplaceElementMap()

    Replacing just the keyCode and leaving everything else the same?

    Thanks!
     
  45. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,876
    It is one way to do it. There is not just one way of doing anything. You can also just change the keycode:
    https://guavaman.com/projects/rewir..._Rewired_ActionElementMap_keyboardKeyCode.htm
    https://guavaman.com/projects/rewired/docs/api-reference/html/P_Rewired_ActionElementMap_keyCode.htm
     
    flashframe likes this.
  46. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    399
    Thanks that's helpful :)
     
  47. tcz8

    tcz8

    Joined:
    Aug 20, 2015
    Posts:
    290
    @guavaman Just had a problem were my gamepad was no longer working and realized I had a 2nd joystick connected which bumped the gamepad's ID so all the mapping were messed.

    Is there any way around this? Like make all joysticks work for a single player? This way the player can just pickup whatever gamepad in reach and it works?

    I RTFM but didnt find an obvious setting, do I have to use the Joystick Auto-Assignement settings?
     
  48. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,876
    Yes. This is all over the documentation because this is such a common oversight:
    https://guavaman.com/projects/rewired/docs/Controllers.html#joystick-auto-assignment
    https://guavaman.com/projects/rewired/docs/Troubleshooting.html#controller-doesnt-work
    https://guavaman.com/projects/rewired/docs/BestPractices.html#controller-assignment

    Note: One common issue that arises is when you connect multiple controllers and want a single Player to be able to use any of the connected controllers. Based on the default settings, Rewired will assign only one controller per-Player. In order to allow auto-assignment of multiple Joysticks to the same Player, Max Joysticks Per Player must be raised to a value greater than 1. All these settings are configurable and have descriptions as to their function.
     
  49. HashbangGames

    HashbangGames

    Joined:
    May 7, 2011
    Posts:
    39
    I have a silly problem. I have corgi engine + rewired. I am also using the touch controls integration. I'm on Unity 2019.6.f1.

    I've setup a single virtual joystick and two buttons A & B. A shoots and B jumps. For the most part everything works as expected. Except when I jump and my virtual joystick is pointed in any direction it also shoots.

    I don't see any setting that is doing this. All the mappings look correct, any thoughts on what could be causing my jump button to also trigger the shoot when moving in a direction?

    Also note that if I jump without touching the virtual joystick it does not shoot.
     
  50. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,876
    A bunch of wild guesses.
    1. Disable the button GameObject and see if the stick is still making it shoot.
    2. Disable any Touch Region connected to the button.
    3. Check your shooting code.
    4. Make sure you don't have anything mapped to tap or other events on the Joystick inspector that would make it shoot.
    5. Do not parent the Button GameObject underneath the Joystick GameObject.