Search Unity

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,625
    Activate on Swipe In is not necessary and not the right solution. Something is preventing the joysticks from working correctly. Again, I suggest you test my demo scenes. They should work. If they do, you have a problem in some setup. If they don't, Unity broke something.
     
  2. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    There's no ETA. I will get it out as soon as I can. It's a huge job to test everything on all platforms and fix/workaround new Unity bugs.
     
  3. InvincibleCat

    InvincibleCat

    Joined:
    Dec 23, 2014
    Posts:
    83
    Sound good!

    Thank you so much for your hardwork! You made my life so much easier and speed-up my workflow drastically :)
     
  4. AppBite

    AppBite

    Joined:
    Jul 5, 2012
    Posts:
    79
    How well is Rewired working for people with 2 x Nintendo Joy-Cons on Windows? Is it able to deal with the -0.7, 0.7 diagonal hat values and see the sticks as 8 way?

    I'm trying to understand the Actions from the docs, when you turn the controller vertical have people been able to take "Controller.Hat.buttonUpRight" and make it "UpLeft" within their own code? In theory that doesn't look too hard.

    How hard is it to build up the input settings to account for some of the inputs coming from controller L and some from controller R as separate devices? Are they seen as 2 players? Do people code around that with something like
    playerA.GetButtonDown("TriggerL") + playerB.GetButtonDown("TriggerR") ?

    Thanks,
    Scott
     
  5. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    https://guavaman.com/projects/rewired/docs/SupportedControllers.html

    fewafaew.png

    *20 Joy-Con sticks on non-Switch platforms return digital hat values. Analog stick values, gyro, vibration, and other special features not available. Controller layout is based on the horizontal orientation.

    Hats are always 8-directional. I don't know what -0.7, 0.7 problem you are referring to. The vast majority of joysticks report something like 0.7, 0.7 at diagonals, not 1.0, 1.0.

    There is no such thing as a "Dual Joy-Con" on Windows. Each device is a device and is treated exactly as any other device.

    Whether someone wants to implement their own Vertical/Horizontal swappable handling of the controller elements is up to them. How hard that is is depends entirely on your programming skill level. One could choose do this in any number of ways.

    You can always try out any feature by downloading the 100% fully functional trial.
     
    Last edited: Aug 15, 2020
    KarlKarl2000 likes this.
  6. ramonster1986

    ramonster1986

    Joined:
    Aug 14, 2016
    Posts:
    5
    Last edited: Aug 15, 2020
  7. AppBite

    AppBite

    Joined:
    Jul 5, 2012
    Posts:
    79
    Thanks. You might want to mention the 8-directional thing, not everyone is a controller expert and knows "hats are always 8-directional". What I've seen doing my research on Unity Input vs InControl vs Rewired is people having problems with the diagonals. I could see the 0.7 values in the debug included with the Unity Input System and wanted to know if Rewired would return something like "UpRight" for the 0.7 value or return nothing at all.

    I did download the demo and at first I didn't think it worked. The GamepadTemplateUI scene showed nothing happening, UnityJoystickElementIdentifier no input values showed on screen. It wasn't until I tried the EightPlayers scene did something happen.
    I then went back to UnityJoystickElementIdentifier and noticed it was listing 2 controllers, a disconnected PS4 controller (that hadn't been connected for a day) and the Joy-Con. Once I hit + to change Joystick Id to 2 the Joy-Con it worked and I got values on the screen. Is this a limitation of the Demo? Is there a way to preference active controllers over disconnected ones? (The ControlMapperDemo scene also had the DualShock first, but it did allow me to navigate with the Joy-Con.)

    Thanks.
     
  8. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    There is no such thing as an "inactive" controller. If your PS4 controller is appearing to the system, that means for all Rewired is able to tell from the HID information provided by Windows, it is connected. Rewired can't tell the difference. Something wrong is happening at the driver/system level if this is happening. Problems like this are almost always due to installing tools like DS4Win, VJoy, or other drivers/mapping systems. Rewired even includes extra non-standard, custom checks to try polling the Bluetooth system and detect if a controller is actually connected with whatever means are available to do so. If it's appearing to Rewired, then it's considered connected by all means available to check this sort of thing.

    I do not believe it's necessary or appropriate that I provide a definition for a Hat switch in my explanation of the Nintendo Joy-Con limitations when used on Windows. Hat switches have been a standard component in PC controller hardware for over 30 years. Most have 4-8 physical directions, while some may have more than 4 physical directions, you can always detect at least 8 directions out of those 4 buttons like a Dpad unless the hardware physically prevents you from pressing two at once. The point of the warning is to tell you they do not appear to the system as analog joystick axes and cannot return analog values, only digital values like a Hat switch / Dpad.
     
    Last edited: Aug 15, 2020
  9. AppBite

    AppBite

    Joined:
    Jul 5, 2012
    Posts:
    79
    Well the PS4 controller hadn't been paired via Bluetooth since the day before & my PC had been turned off overnight, that is what I meant by "inactive". In the Bluetooth manager the PS4 controller wasn't showing green, the only green/paired controller was the JoyCon L. I don't have DS4Win or VJoy installed.

    The "EightPlayers" scene detected the JoyCon as "Player1" and the white capsule fired its bullet fine. The "UnityJoystickElementIdentifier" saw the PS4 controller as first and thus no data on screen. It wasn't until I noticed the "Press +" bit in the text, that I manually switched it to the next Id: and then I could see the readout from the JoyCon. Seems to suggest there is something within the "EightPlayers" scene which preferences the "active" controller (one that sending input?) over the "inactive" (unpaired) controller. I'm guessing the Joystick Auto-Assignment but the options appear the same between both scenes.

    Thanks,
    Scott
     
  10. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    There is nothing in Eight Players that has any control over what controller is assigned to what Player. Controllers are assigned in the order they are sorted by ReInput.controllers.Joysticks and then assigned to those players. The sorting order of ReInput.controllers.Joysticks is not identical to the low-level Raw Input Joystick Element Identifier you are looking at. There is no way to detect "active" and "inactive" controllers. Rewired is already using all the means it has to be able to determine if the HID device is valid or not and your DS4 should already be getting filtered out, but clearly its not so false information is being reported to Rewired by the Windows HID and Bluetooth APIs. There's nothing you can do to fix this from within Unity or within Rewired. Any fix would have to happen outside Rewired at the Windows / driver level.
     
  11. KarlKarl2000

    KarlKarl2000

    Joined:
    Jan 25, 2016
    Posts:
    606
  12. Roman-Ilyin

    Roman-Ilyin

    Joined:
    Oct 9, 2013
    Posts:
    29
    Hello.

    I am using the native Unity input system.
    Could you tell me how to do the same with Rewired?

    Code (CSharp):
    1.  
    2. public class GroundHandler : MonoBehaviour, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler
    3. {
    4.     public event System.Action<Vector3, PointerEventData.InputButton> PointerClick;
    5.     public event System.Action<GroundHandler> PointerOverChanged;
    6.  
    7.     public bool ZeroHandler;
    8.  
    9.     public void OnPointerClick(PointerEventData eventData)
    10.     {
    11.         if (PointerClick != null && (eventData.position - eventData.pressPosition).magnitude < 5)
    12.             PointerClick(eventData.pointerCurrentRaycast.worldPosition, eventData.button);
    13.     }
    14.  
    15.     private static GroundHandler Selected;
    16.  
    17.     public void OnPointerEnter(PointerEventData eventData)
    18.     {
    19.         Selected = this;
    20.         if (PointerOverChanged != null)
    21.             PointerOverChanged(Selected);
    22.     }
    23.  
    24.     public void OnPointerExit(PointerEventData eventData)
    25.     {
    26.         if (Selected == this)
    27.             Selected = null;
    28.         if (PointerOverChanged != null)
    29.             PointerOverChanged(Selected);
    30.     }
    31.  
    32.     public void Init()
    33.     {
    34.         GroundController.Instance.InitHandler(this);
    35.     }
    36. }
    37.  
    Code (CSharp):
    1.  
    2. public class GroundController
    3. {
    4. public System.Action<Vector3, PointerEventData.InputButton> PointerClick;
    5.  
    6. private void OnPointerClick(Vector3 worldPoint, PointerEventData.InputButton mouseButton)
    7.     { ... }
    8. }
     
  13. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    If you're referring to putting down money for Rewired, never do this unless you have tried it and it works for your needs. That's the whole purpose of the free, 100% functional trial.

    https://guavaman.com/rewired/trial

    Neither of those controllers is listed here:
    https://guavaman.com/projects/rewired/docs/SupportedControllers.html

    All the information you need to know is on that page including these paragraphs:

    All other controllers not listed above
    Any controller which does not have a hardware definition will be usable only through user mapping or by mapping actions to numbered axes and buttons in the Unknown Controller map. These unrecognized controllers can only be supported if you provide your users a way to remap their controls, such as by using the included Control Mapper or by creating a custom control remapping screen. If you do not provide users with a way to map their controls, only the above listed recognized controllers will be usable. If you do provide your users a way to map their controls, virtually any controller will be usable.

    You can also create your own controller definitions to add extended support for more controllers, but the process can be involved, especially if you want to support all platforms. (See Creating new controller definitions for more information.) However, be advised that not all controllers are candidates for controller recognition. (See Can I add support for this controller? for more information.) Instead of adding a new controller definition yourself, I recommend that you send me the controller you wish to add a definition for and I will add it Rewired to be included in subsequent updates. And of course, I'll mail it back. :) You can contact me through the support form on the website.
     
  14. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    Exactly the same. Rewired does not change the Unity UI system. Events sent to UI controls by the RewiredStandaloneInputModule are exactly the same.
     
    Roman-Ilyin likes this.
  15. sSuite

    sSuite

    Joined:
    Sep 28, 2014
    Posts:
    17
    Hey! I'm getting some bizarre behavior with the InputMapper. I have 4 elements in a joystick map mapped to the UIHorizontal and UIVertical actions (one positive & one negative of each, naturally). These are intended to be mapped onto the d-pad. This all works great so far. The issue is that when trying to use InputMapper to remap these inputs, the correct element is removed, but the positive element always receives the new mapping.

    So for example, let's say I want to remap UI Left to the A button for some reason. The d-pad left button mapping (which is the default) is cleared, and UI Right receives a new mapping for the A button. It doesn't delete the previous UI Right mapping, so now d-pad right and A both correspond to UI Right. The same happens when trying to map to UI Down.

    It's definitely happening inside of the InputMapper somehow -- the starting ActionElementMap correctly recognizes that its axisContribution is negative, and then after passing it into the InputMapper context & getting a new mapping, the new ActionElementMap has a positive axisContribution.

    Am I making a silly mistake somewhere or is this an actual bug? Thanks!

    EDIT: just in case this is helpful, here are the relevant code snippets, though it's pretty boilerplate:

    This is where I start the mapping:
    Code (CSharp):
    1. Debug.Log(
    2.         "A: "+previous_map.axisContribution);
    3.  
    4.         // begin listening for input
    5.         Debug.Log("listening");
    6.  
    7.  
    8.         joystick_inputmapper.Start(
    9.             new InputMapper.Context() {
    10.                 actionId = previous_map.actionId,
    11.                 controllerMap = gamepad_map,
    12.                 actionRange = action.axis_range,
    13.                 actionElementMapToReplace = previous_map
    14.             }
    15.         );
    16.  
    17.         // disable controls until we're done
    18.         controller_manager.rewired_player.controllers.maps.SetAllMapsEnabled(false);
    And here's the success callback function:
    Code (CSharp):
    1.  
    2.     void input_successfully_mapped (InputMapper.InputMappedEventData data) {
    3.         Debug.Log("success!");
    4.         Debug.Log("replaced "+data.actionElementMap.actionDescriptiveName);
    5.         Debug.Log("B: "+data.actionElementMap.axisContribution);
    6.  
    7.  
    8.  
    9.         string xml_string = data.inputMapper.mappingContext.controllerMap.ToControllerTemplateMap<IGamepadTemplate>().ToXmlString();
    10.         controller_manager.set_gamepad_mappings(xml_string);
    11.      
    12.         joystick_inputmapper.Stop();
    13.         controller_manager.global.controller_changed.Invoke();
    14.     }
    Under these weird circumstances, this prints "A: Negative" and "B: Positive"
     
    Last edited: Aug 21, 2020
  16. JamesPoppyWorks

    JamesPoppyWorks

    Joined:
    Aug 19, 2020
    Posts:
    4
    Howdy @guavaman!

    I am running into an issue with assigning "B" for Joystick Input to an action in-game. What appears to be happening when the user wants to reassign an action from the Gameplay category to the "B" Button, that the menu closes as if we hit back. As a test, I unmapped "UICancel" from the "B" Button's menu mapping and I was then able to assign "B" to an action in-game.

    I have a feeling that I should be using the Screen Control Actions from the Control Mapper prefab to actually navigate Menus using the controller, but I'm not really comprehending how these actions work, or if I'm even barking up the wrong tree.

    Thanks for any assistance you can provide!
     
  17. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    Axis Contribution only applies to split axis bindings or button bindings. A binding with a Full Axis range will always have an Axis Contribution of Positve as a default because the value is meaningless for a full axis binding. I can only guess that action.axis_range is AxisRange.Full. The Action Range property tells it the user's intention on what part of the Action he is mapping. That's why all Rewired examples show a full axis field and a positive and negative field.
     
  18. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    I can't reproduce anything like that. Try the Control Mapper demos. Pressing the UI cancel button doesn't close the Control Mapper UI. If this is happening, then you have set something up to close the menu/window/whatever with UI cancel. If you have set Screen Close Action to UI Cancel, this would not close the UI when making a binding to that button.
     
  19. gaterooze

    gaterooze

    Joined:
    Jul 17, 2019
    Posts:
    16
    If an action defined as an Axis (say horizontal motion) but uses keys, is there a way to have one key cancel the previous one, equivalent to the Unity Input "Snap" setting? i.e. hold A to move left, then you hold D to move right while still holding A, D should override A and start moving right. At the moment they cancel each other out and no movement occurs. I confirmed this is not a keylocking issue as it works with Unity Input.
     
  20. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    https://guavaman.com/projects/rewired/docs/RewiredEditor.html#InputBehaviors

    Digital Axis Snap and Digital Axis Instant Reverse. These were designed to mimic those Unity settings.
     
  21. gaterooze

    gaterooze

    Joined:
    Jul 17, 2019
    Posts:
    16
    Fantastic, thanks so much. Oh, I don't have those options, that explains why I couldn't find them :D I'll update to latest.

    Edit: I see, I need to first enable Digital Axis Simulation.
     
  22. gaterooze

    gaterooze

    Joined:
    Jul 17, 2019
    Posts:
    16
    Sorry to bother you again, but I have tried both settings (independently and combined) and while the behavior is better, it's not quite what is expected - now it doesn't cancel the other direction out (good), but it doesn't override it either.
     
  23. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    Those are the only options that affect how multiple opposing keys when pressed together function. If they don't do what you want, then it's not supported. Testing in 2019.1.0f2 and Unity 2020.1.0f1, Unity's legacy input manager Snap setting works exactly like "Digital Axis Snap". What you are describing you want doesn't happen on either version of Unity according to my tests I just did. Pressing an opposing key does not negate and invert the previously held key's value. The value of the first key pressed is maintained even when the opposing key is pressed. If you hold left and then press right before the value reaches -1, the value will halt at -.0.5 or similar until one key is released. The Snap setting doesn't do anything but reset the axis value to 0 instantly when an opposing key is pressed after having released the first key effectively clearing the axis. Unity has no equivalent of "Digital Axis Instant Reverse."

    I don't know how you are getting the results you are, but I cannot reproduce them in Unity. If you are using their new input system, that probably works differently.
     
    Last edited: Aug 21, 2020
  24. KarlKarl2000

    KarlKarl2000

    Joined:
    Jan 25, 2016
    Posts:
    606
    Thanks for the great response!! Ok I'll check out all the links and get back to you if I have any further questions!

    I'll see what I can do about sending you the mayflash fight stick! I haven't bought it myself just yet ! :oops:
     
  25. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    Yes. Id is not an Index.

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

    This can fail on all 3 arguments that are ids.
     
  26. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625

    It's just luck that it works. It's not correct.

    Code (csharp):
    1. public void LoadMap(
    2.    ControllerType controllerType,
    3.    int controllerId,
    4.    int categoryId,
    5.    int layoutId
    6. )
    Controller Id -- the id does not mean the index of the joystick attached. If you plug and unplug many joysticks, you will get many different id's. The moment you have a joystick beyond id 5, it will fail.

    Category Id -- If your categories happen to be sequential and 0-6 it will work, but delete those categories and make 6 more. Now the id's go from 6-11. Your code fails.

    Layout id - Same as category id, but more complicated. Each Controller type has its own set of layouts. Layout 0 for Keyboards is not the same thing as Layout 0 for Joysticks. Again, if you happen to have only have 6 layouts in each category and did not delete any of them, it will just so happen to work.

    Load Default Maps loads the Controller Maps for that Player you designated in the Rewired Input Manager to be loaded in the Player on Start on the Players page. If you did not designate any Controller Maps to be loaded on start, none will be loaded. If the map already exists in the player, the enabled state will be retained, otherwise it will be set to the Enabled state you set on the Players page.

    This function does work. It's the same function used by Control Mapper's "Restore Defaults" button.
     
  27. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    I read and answered your question. Read my response again.

    You asked:
    Any reason off the top of your head why LoadDefaultMaps wouldn't work, even though just hard looping through all the maps and issuing a LoadMap does work?

    I answered:
    Load Default Maps loads the Controller Maps for that Player you designated in the Rewired Input Manager to be loaded in the Player on Start on the Players page. If you did not designate any Controller Maps to be loaded on start, none will be loaded. If the map already exists in the player, the enabled state will be retained, otherwise it will be set to the Enabled state you set on the Players page.

    There is no other possible reason why LoadDefaultMaps wouldn't work.
     
    iansnyder likes this.
  28. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    And calling LoadDefaultMaps when a Joystick is disconnected will not cause those defaults to be loaded the next time that Joystick is reattached. LoadDefaultMaps, like all other manual map management functions, acts only on the currently attached, assigned controllers in the Player. It does not clear histories of joysticks that were previously attached, just like calling SetMapsEnabled will not enable/disable maps on controllers not currently connected and assigned to the Player.
     
  29. Erveon

    Erveon

    Joined:
    Sep 15, 2019
    Posts:
    13
    Hi, I created a new input action and when I try to poll it it doesn't work unless I clear the PlayerPrefs.
    I need it to work without clearing existing data because I don't want to have to wipe people's keybinds and other data.
    Is there any way to do this?
     
  30. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    There is already code in UserDataStore_PlayerPrefs to attempt to allow merging of new Actions into old saved maps provided there are no conflicts. If this isn't working in your case, I suggest you replace UserDataStore_PlayerPrefs with a system you design where you can manage the saved bindings and modify them as necessary for the changes you make to your game. PlayerPrefs has too many limitations to make a robust data management system.

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

    Management of saved user data is up to the developer. If you have special needs beyond the basic use cases, you should extend and replace the UserDataStore_PlayerPrefs component with a new UserDataStore component that meets your specific needs.
     
  31. InertialDrift

    InertialDrift

    Joined:
    Jan 3, 2018
    Posts:
    12
    Hey @guavaman, I'm doing input remapping stuff and unfortunately because of the way our ui works it was easier to do it manually than to use your drop in solution (we aren't using any of Unity's menu event system stuff). It's all working fine except that if you choose to remap an item and then remap it to the key it was already mapped to then the elementIdentifierName is blank. You have to remap it to a different button and back again before it will show that input in the elementIdentifierName again.

    Here's a small testcase I made to test out this issue. Listening is triggered by my pause action, it remaps my back action and just displays the currently mapped key in a text field.
    Say back is initially mapped to "B", remapping it to "A" works fine, but if you start listening and then remap it to "B" when it was already "B" then obj.actionElementMap.elementIdentifierName is "" and so is the value in the text display. Am I missing a step here or something that is causing this?


    Code (CSharp):
    1. public class RemapTest : MonoBehaviour
    2.     {
    3.         private InputMapper _inputMapper;
    4.  
    5.         public TMP_Text Text;
    6.  
    7.         public void OnEnable()
    8.         {
    9.             _inputMapper = new InputMapper();
    10.             _inputMapper.InputMappedEvent += InputMapped;
    11.             _inputMapper.StoppedEvent += Stopped;
    12.             ReInput.players.GetPlayer(0).controllers.AddController(ReInput.controllers.Keyboard, true);
    13.             UpdateDisplay();
    14.         }
    15.  
    16.         private void Stopped(InputMapper.StoppedEventData obj)
    17.         {
    18.             Debug.Log("Stopped");
    19.         }
    20.  
    21.         private void InputMapped(InputMapper.InputMappedEventData obj)
    22.         {
    23.             Debug.Log($"Mapped to {obj.actionElementMap.elementIdentifierName}");
    24.         }
    25.  
    26.         private void UpdateDisplay()
    27.         {
    28.             var elementMap = GetElementMap();
    29.             Text.SetText(elementMap.elementIdentifierName);
    30.         }
    31.  
    32.         private static ActionElementMap GetElementMap()
    33.         {
    34.             var map = GetMap();
    35.             var maps = map.AllMaps;
    36.             foreach (var actionElementMap in maps)
    37.             {
    38.                 if (actionElementMap.actionId == Action.Back) return actionElementMap;
    39.             }
    40.             return null;
    41.         }
    42.  
    43.         private static ControllerMap GetMap()
    44.         {
    45.             var player = ReInput.players.GetPlayer(0);
    46.             var controllerHelper = player.controllers;
    47.             var controller = ReInput.controllers.Keyboard;
    48.             var map = controllerHelper.maps.GetMap(controller, Category.Default, 0);
    49.             return map;
    50.         }
    51.  
    52.         public void Update()
    53.         {
    54.             if(_inputMapper.status == InputMapper.Status.Idle) UpdateDisplay();
    55.             var player = ReInput.players.GetPlayer(0);
    56.             if (!player.GetButtonUp(Action.Pause)) return;
    57.  
    58.             Debug.Log("Start listening");
    59.             var context = new InputMapper.Context();
    60.             context.actionId = Action.Back;
    61.  
    62.             context.controllerMap = GetMap();
    63.             context.actionElementMapToReplace = GetElementMap();
    64.  
    65.             _inputMapper.Start(context);
    66.         }
    67.     }
     
    Last edited: Aug 23, 2020
  32. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    After going through your code and setting up and performing this test and doing it myself, I cannot reproduce it. Then it hit me. Your Rewired is outdated. Update it.

    1.1.34.1:

    Bug Fixes:
    - Fixed bug when replacing an Action Element Map keyboard key binding with the same keyboard key causing ActionElementMap.elementIdentifierName to return a blank string. Bug was introduced in 1.1.33.0.

    Current version is 1.1.35.3.
     
  33. InertialDrift

    InertialDrift

    Joined:
    Jan 3, 2018
    Posts:
    12
    Nice, thanks! I'd assumed the issue must have been on my end because I couldn't reproduce the issue with your simple sample. Hopefully the update should sort it. I'd been avoiding updates to anything because we are so close to shipping but it should be fine to update rewired just for the PC version which is the only place we support remapping.
     
  34. JamesPoppyWorks

    JamesPoppyWorks

    Joined:
    Aug 19, 2020
    Posts:
    4
    I don't know if this was the "right" fix, but what I ended up doing was listening for the ControlMapper's onInputPollingStarted/Ended Events to toggle the Menu Map Configuration off and on respectively so that pressing "B" mapped the action to "B" instead of firing UICancel and closing the window.
     
  35. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    I wouldn't suggest doing it that way. I would suggest you find out what script is closing Control Mapper when it receives the UICancel event or watches the value of the UICancel Action. Control Mapper does not do this.
     
  36. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,747
  37. io-games

    io-games

    Joined:
    Jun 2, 2016
    Posts:
    104
    Is it slow?
    upload_2020-8-24_16-43-34.png
     
  38. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    AcidArrow likes this.
  39. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
  40. guavaman

    guavaman

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

    See Updating Rewired.

    1.1.36.0:

    Changes:
    - Added Unity 2020 support.
    - Added UWP ARM64 native library (Unity 2019+, untested).
    - Removed GUILayer on cameras in examples to stop errors reported in Unity 2019+
    - Rewired Editor: Copying an Action Category that contains Actions and copying those Actions now copies the sort order of the Actions.
    - Changed Player input event system to allow modifying the event listeners inside an event callback without causing issues.
     
    Bartolomeus755 and Grumpy-Dot like this.
  41. NathanielAH

    NathanielAH

    Joined:
    Jul 22, 2013
    Posts:
    100
    Is there a Rewired Discord server? J/W.

    -N.
     
  42. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    No.
     
    NathanielAH likes this.
  43. io-games

    io-games

    Joined:
    Jun 2, 2016
    Posts:
    104
  44. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    The ^ operation's performance impact is not significant. Rewired has had the same obfuscation ever since it was released. (Well actually, it has less.)
     
    Last edited: Aug 26, 2020
  45. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    Never been an issue with Rewired performance since 2014. A very happy customer and it works with everything. The best way to use flight controllers by the way.

    I did notice that flight controllers are hard to find since Microsoft launched or rather relaunched it flight simulation software. Of course we can never have enough flight controllers. :)
     
    guavaman likes this.
  46. Holy-Manfred

    Holy-Manfred

    Joined:
    Nov 30, 2013
    Posts:
    15
    I am having a problem with reassigning keyboard keys using my own custom remapping UI. Basically I have a window that lets the player remap keys for certain actions. For example: 'Close Window' is mapped to ESCAPE and the player can use the UI to change it to 'BACKSPACE' or something similar.
    This does work well and everything appears to be updated correctly. When I log the according ActionElementMap.keyCode it shows the correct new key assigned for the action. Furthermore when I close the game and restart it every key assignemtn is saved/loaded correctly.

    However, my code seems only to be reacting to the old (default) key set for the action and not the new key. My calls of

    Code (CSharp):
    1. if (Player.GetButtonDown("my_action_name"))
    2. {
    3. }
    only trigger when I press the old default key and not the new one, although the ActionElementMap.keyCode shows the new key being set.
    Are there any steps I am missing here, like refreshing/reloading a mapping after changing keys?
     
  47. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    There are no extra steps. Controller Maps exist in one place -- in the Player. If you change the Controller Map in the Player, you are changing the same Controller Map that is used to determine the Action value. Loading saved Controller Maps loads them into the Player. The value that is returned when you call Player.GetButtonDown is based on the Controller Maps that are currently loaded into the Player.

    As with all issues involving any runtime objects in Rewired, the only way to debug the problem is to use Debug Information to see exactly what is happening at run time:
    https://guavaman.com/projects/rewired/docs/Troubleshooting.html#debug-information

    Controller Maps and Action Element Maps are there visible for you to view and see exactly what is and isn't happening to solve your problem.
     
  48. Holy-Manfred

    Holy-Manfred

    Joined:
    Nov 30, 2013
    Posts:
    15
    Thank you, the debug tools are very helpful.
    It turns out that I mapped the action to the wrong ControllerMap. It was mapped to the 'Default' keyboard map category, instead to the one which is currently active. It does work when I use the correct ControllerMap, like so:

    Code (CSharp):
    1. map = m_RewiredPlayer.controllers.maps.GetMap(ControllerType.Keyboard, 0, "MyCategory", "Default");
    However I am not sure how to get the correct ControllerMap to give to the InputMapper for a given action. I have an InputAction I want to change, but how would I get the category string I need to pass to GetMap? I could possibly have multiple keyboard map categories and only one of the might use the specifc action I want to change.
     
  49. InertialDrift

    InertialDrift

    Joined:
    Jan 3, 2018
    Posts:
    12
    Hey @guavaman, I was debugging an issue and I have a workaround but I wanted to let you know about it in case you wanted to make a change to prevent it from happening.

    I was having an issue with a controller (specifically a dualshock 4, though I didn't test it with anything else) not being available for controller engagement after being disconnected and reconnected during the game.
    I have auto assign turned off. When controllers are connected I assign them to System and then I have a user engagement script that checks for inputs to assign them to players.

    Here is a test script I was using to reproduce this in an empty scene. You just need this, a text display for it to display the number of joysticks assigned to system and player1, a basic rewired input manager with auto assign disabled and some sort of input defined/enabled for System and a UserDataStore_playerPrefs component.

    Code (CSharp):
    1. public class ControllerAssignTest : MonoBehaviour
    2.     {
    3.         private bool _initialised;
    4.  
    5.         public TMP_Text TextDisplay;
    6.  
    7.         public void OnEnable()
    8.         {
    9.             Initialise();
    10.         }
    11.  
    12.         public void Initialise()
    13.         {
    14.             if (_initialised) return;
    15.  
    16.             foreach (var controller in ReInput.controllers.Controllers)
    17.             {
    18.                 AssignController(controller);
    19.             }
    20.  
    21.             ReInput.ControllerConnectedEvent += ControllerConnected;
    22.             _initialised = true;
    23.         }
    24.  
    25.         private void ControllerConnected(ControllerStatusChangedEventArgs args)
    26.         {
    27.             Logging.Log("Controller Connected");
    28.             AssignController(args.controller);
    29.         }
    30.  
    31.         private void AssignController(Controller controller)
    32.         {
    33.             Logging.Log($"System Controllers {ReInput.players.SystemPlayer.controllers.Joysticks.Count}");
    34.             ReInput.players.SystemPlayer.controllers.AddController(controller, true);
    35.             Logging.Log($"System Controllers {ReInput.players.SystemPlayer.controllers.Joysticks.Count}");
    36.         }
    37.  
    38.         public void Update()
    39.         {
    40.             var systemPlayer = ReInput.players.SystemPlayer;
    41.             var player = ReInput.players.GetPlayer(0);
    42.             TextDisplay.SetText($"Controllers assigned to System: {systemPlayer.controllers.Joysticks.Count}\nControllers assigned to Player: {player.controllers.Joysticks.Count}");
    43.  
    44.             if (!systemPlayer.GetAnyButtonUp()) return;
    45.  
    46.             player.controllers.AddController(systemPlayer.controllers.GetLastActiveController(), true);
    47.         }
    Start the scene, the controller is assigned to System. Press a button so that the controller is assigned from system to player 1. Disconnect the controller, reconnect the controller. Sometimes you see System show a controller count of 1 frame before it goes to 0 and therefore no controller inputs can be detected to assign it back to player1.

    The issue doesn't occur if you remove the datastore component from the scene. I presume the controller is being removed by "player.controllers.ClearControllersOfType(ControllerType.Joystick);" in LoadJoystickAssignmentsNow and not getting assigned back, but I didn't dig any further than that. My workaround currently is just to delay adding the controller to system by 1 frame using a coroutine and that's fine for me, but I just wanted to make you aware in case anyone else runs into this. Also, I am running the most up to date version (1.1.36) of Rewired now so it shouldn't be that either.

    If anything about what I'm doing here is dumb then let me know!
     
  50. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    You are the one who determines which Controller Map categories and layouts are loaded or active at any time. You must keep track of this information somewhere. That's going to be a difficult problem if you have a bunch of different categories in various layouts loaded at once and are allowing the same action to be mapped to any of these controller maps. You are much better off using a single map category for specific Actions, and if you're using multiple Layouts, only ever have one layout loaded at any time for a particular map category.