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,631
    Are you using the Unity editor on Windows or OSX?

    I believe there is a logic error in the #if directives when using the Unity editor on OSX and Linux and switching to a different standalone build target. Try changing the GetPlatformInitializer function in Rewired/Internal/Scripts/Misc/ExternalTools.cs to:

    Code (csharp):
    1. public object GetPlatformInitializer() {
    2. #if UNITY_5_PLUS
    3. #if (!UNITY_EDITOR && UNITY_STANDALONE_WIN) || UNITY_EDITOR_WIN
    4.             return Rewired.Utils.Platforms.Windows.Main.GetPlatformInitializer();
    5. #elif (!UNITY_EDITOR && UNITY_STANDALONE_OSX) || UNITY_EDITOR_OSX
    6.             return Rewired.Utils.Platforms.OSX.Main.GetPlatformInitializer();
    7. #elif (!UNITY_EDITOR && UNITY_STANDALONE_LINUX) || UNITY_EDITOR_LINUX
    8.             return Rewired.Utils.Platforms.Linux.Main.GetPlatformInitializer();
    9. #elif UNITY_WEBGL && !UNITY_EDITOR
    10.             return Rewired.Utils.Platforms.WebGL.Main.GetPlatformInitializer();
    11. #else
    12.             return null;
    13. #endif
    14. #else
    15. #if UNITY_WEBGL && !UNITY_EDITOR
    16.             return Rewired.Utils.Platforms.WebGL.Main.GetPlatformInitializer();
    17. #else
    18.             return null;
    19. #endif
    20. #endif
    21. }
    This error would not show up in the Windows editor when building to OSX or Linux because of the order if the if statements.
     
    Last edited: Jan 23, 2019
  2. Zeitcatcher

    Zeitcatcher

    Joined:
    Dec 11, 2012
    Posts:
    21
    This fixed it! Thanks!

    Yeah, I am working on macOS, and Unity uses Macs for Cloud Build, which explains why other people in the thread didn't have any local issues (assuming they were on Windows), but still had this error with Cloud Build.
     
  3. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    So now it makes sense that Cloud Build wasn't building correctly. Time for another update... Thanks!
     
  4. Grazer2

    Grazer2

    Joined:
    Jun 20, 2011
    Posts:
    86
    Hello,

    The problem: I have a grid-like button-menu the user needs to navigate using the left stick of a gamepad. It frequently occurs that, when the user intends to navigate "right" by moving the stick to the right side, he accidentally invokes an additional "up" navigation after the proper right navigation. Imo this is because the sensitivity of the stick may be too high. I.e. he moves the stick to the right, but also slightly upwards using a natural thumb-motion and the slight (unintended) up-motion triggers the up-navigation.

    My idea: I would thus like to increase the deadzone of the stick, so that left/right/up/down are detected only when the stick is moved far enough into that direction.

    Implementation details: To detect the navigation I am currently using Rewired and its "GetButtonDown" method. In the rewired input manager I have defined 4 actions (right, up, left, down) that I mapped to the Left Stick X and Y axes with axis range = positive for the right and up navigation, and axis range = negative for the left and down navigation.

    TL;DR: How to increase the Left Stick Deadzone when using Rewired & Unity?

    Thanks,

    Jürgen

    P.S.: Or is there another way altogether?
     
  5. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,601
  6. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    You changing the dead zone instead of allowing the user to do it for their individual stick isn't going to help and would cause you more problems than it's worth. It's a matter of the TYPE of dead zone. All recognized controllers with sticks default to a radial dead zone -- dead zone threshold depends on the magnitude of the combined 2D axis length, not the individual X/Y axes. Changing the dead zone type isn't the solution either because I'll assume you don't want to change the dead zone type to axial because the rest of your game wouldn't be able to get the smoother values from the radial dead zone.

    You have multiple ways of dealing with this:
    1. Don't use GetButtonDown and process the axis values yourself like is done in the RewiredStandaloneInputModule.
    2. Change the the Button Dead Zone (button-down threshold) in the Input Behavior.
     
  7. guavaman

    guavaman

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

    Please see Updating Rewired before updating.

    1.1.22.2:

    Bug Fixes:
    - Fixed issue causing compiler errors in OSX and Linux editors when building to Windows build target. This same issue also affected Unity Cloud Build.
    - Changed meta files on Rewired_DirectInput.dll to get around a bug in Unity 5.x where Windows libraries were attempting to be included in OSX and Linux Standalone build targets causing an exception.
     
  8. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,832
    I've update Rewired to the latest version. I'm getting two warnings when first entering playmode in the editor:

    1.
    Rewired: You cannot change AxisRange of a non-Axis mapping.
    UnityEngine.Logger:LogWarning(String, Object)
    Rewired.Logger:LogWarningNow(Object, Boolean)
    Rewired.Logger:LogWarning(Object, Boolean)
    Rewired.Logger:LogWarning(Object)
    Rewired.ActionElementMap:set_axisRange(AxisRange)
    Rewired.Data.Mapping.ControllerMap_Editor:mPAGXLPolFYdIrTOSjcWRbkEHAQb(Func`2, ControllerMap, HardwareControllerMapIdentifier, HardwareJoystickMap, Boolean)
    Rewired.Data.Mapping.ControllerMap_Editor:cwGiSnaBLyUJgHKhFjqMjlsKDfB(Func`2, HardwareControllerMapIdentifier, HardwareJoystickMap, Boolean)
    Rewired.Data.UserData:YAlTjJLDyEswGVLhwNZOPdomehM(HardwareControllerMapIdentifier, ControllerMap_Editor, HardwareJoystickTemplateMap, HardwareJoystickMap, Int32, Int32)
    Rewired.Data.UserData:YyyVPduPPDlWldSlDfNzfSNlWHL(HardwareControllerMapIdentifier, Int32, Int32)
    Rewired.Data.UserData:YyyVPduPPDlWldSlDfNzfSNlWHL(Joystick, Int32, Int32)
    Rewired.MappingHelper:GetJoystickMapInstance(Joystick, Int32, Int32)
    Rewired.MappingHelper:GetControllerMapInstance(Controller, Int32, Int32)
    Rewired.Data.UserDataStore_PlayerPrefs:AddDefaultMappingsForNewActions(Player, List`1, ControllerType, Int32) (at Assets/Rewired/Internal/Scripts/DataStorage/UserDataStore_PlayerPrefs.cs:1114)
    Rewired.Data.UserDataStore_PlayerPrefs:LoadControllerMaps(Int32, ControllerType, Int32) (at Assets/Rewired/Internal/Scripts/DataStorage/UserDataStore_PlayerPrefs.cs:491)
    Rewired.Data.UserDataStore_PlayerPrefs:LoadPlayerDataNow(Player) (at Assets/Rewired/Internal/Scripts/DataStorage/UserDataStore_PlayerPrefs.cs:411)
    Rewired.Data.UserDataStore_PlayerPrefs:LoadAll() (at Assets/Rewired/Internal/Scripts/DataStorage/UserDataStore_PlayerPrefs.cs:383)
    Rewired.Data.UserDataStore_PlayerPrefs:Load() (at Assets/Rewired/Internal/Scripts/DataStorage/UserDataStore_PlayerPrefs.cs:206)
    Rewired.Data.UserDataStore_PlayerPrefs:OnInitialize() (at Assets/Rewired/Internal/Scripts/DataStorage/UserDataStore_PlayerPrefs.cs:295)
    Rewired.Data.UserDataStore:Initialize()
    Rewired.ReInput:ljkWIkNgSefDKvoRQWyxzOSuCer(InputManager_Base, Func`2, ConfigVars, ControllerDataFiles, UserData)
    Rewired.InputManager_Base:Initialize()
    Rewired.InputManager_Base:Awake()


    2.
    Rewired: UserDataStore_PlayerPrefs loaded all user data from XML.
    ***IMPORTANT:*** Changes made to the Rewired Input Manager configuration after the last time XML data was saved WILL NOT be used because the loaded old saved data has overwritten these values. If you change something in the Rewired Input Manager such as a Joystick Map or Input Behavior settings, you will not see these changes reflected in the current configuration. Clear PlayerPrefs using the inspector option on the UserDataStore_PlayerPrefs component.
    UnityEngine.Debug:LogWarning(Object)
    Rewired.Data.UserDataStore_PlayerPrefs:Load() (at Assets/Rewired/Internal/Scripts/DataStorage/UserDataStore_PlayerPrefs.cs:209)
    Rewired.Data.UserDataStore_PlayerPrefs:OnInitialize() (at Assets/Rewired/Internal/Scripts/DataStorage/UserDataStore_PlayerPrefs.cs:295)
    Rewired.Data.UserDataStore:Initialize()
    Rewired.ReInput:ljkWIkNgSefDKvoRQWyxzOSuCer(InputManager_Base, Func`2, ConfigVars, ControllerDataFiles, UserData)
    Rewired.InputManager_Base:Initialize()
    Rewired.InputManager_Base:Awake()

    For #2 I have cleared the playerPrefs and verified that the registry is cleared of keys but still get the warning when first entering playmode.
    Thanks.
    Unity 2017.4.18f1
     
  9. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    Nothing at all was changed in the UserDataStore_PlayerPrefs code.

    There is no way possible either message would be logged if PlayerPrefs is cleared. The code checks whether or not the key exists in PlayerPrefs. If the key it's looking for does not exist, the method returns and would never reach the code that is being executed. ((PlayerPrefs.HasKey is returning True on the specified key and data is being loaded). Both of these messages indicate your PlayerPrefs is not cleared and still contains data and that it is loading that data. How are you clearing PlayerPrefs? Use the button in the inspector on the UserDataStore_PlayerPrefs component to clear it in the editor. Note that this does not clear build PlayerPrefs. Builds store PlayerPrefs data separately from the editor project.

    Are there any other messages logged that data is being saved?

    The first message indicates that a mapping was saved for an axis but that the element type is a button. What controller is connected to the system at the time this message is logged?
     
    Last edited: Jan 24, 2019
  10. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,832
    1. Logitech Cordless Rumblepad 2 (control mapper reports it as F710).
    I've isolated it down to "Left Shoulder 2" and "Right Shoulder 2" elements being assigned in "[T] Gamepad Template" joystick map. These are physical buttons on the controller.
    rewirededitor.png
    (Usage of these buttons is working as expected in the editor and game)

    2. Before I explain more details, let me ask what is the purpose of the "Clear PlayerPrefs using the inspector option on the UserDataStore_PlayerPrefs component." in the warning message? Is it simply telling me how I should go about clearing the PlayerPrefs? Or is Rewired telling me I need to clear the PlayerPrefs for some reason?
    I interpreted the message as Rewired is instructing me to clear playerprefs for some reason.


    Thanks.
     
  11. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    Thanks for the information.

    The warning message exists because of the number of people who get confused when they make changes to the Rewired Input Manager mappings and those changes don't appear when they start playing their game because the saved XML data is overwriting whatever changes they just made. This is documented here and here. The warning message is not telling you to clear PlayerPrefs. It is informing you that it just loaded data from XML so you will be aware that you are using saved settings and not the defaults in the Rewired Input Manager. Here is the message:

    Rewired: UserDataStore_PlayerPrefs loaded all user data from XML.
    ***IMPORTANT:*** Changes made to the Rewired Input Manager configuration after the last time XML data was saved WILL NOT be used because the loaded old saved data has overwritten these values. If you change something in the Rewired Input Manager such as a Joystick Map or Input Behavior settings, you will not see these changes reflected in the current configuration. Clear PlayerPrefs using the inspector option on the UserDataStore_PlayerPrefs component.


    This has been a very difficult concept to get across to people that saved user data is entirely separate from Rewired Input Manager defaults (what you set in the Rewired Editor) and that loaded save data overrides the defaults. The warning is there (and mandatory) to make sure the user is aware data is loaded when testing in the editor. It is not logged in the build.

    As for the Logitech Rumblepad and the Gamepad Template, that would explain the message. Code was added at some point a long time ago to "fix" the problem of users adding new Actions to the Rewired Input Manager and making new bindings with those Actions after saved user data already exists. They wanted their new bindings to automatically just show up along with the loaded saved user data. The system I came up with saves the list of known Action Ids when user data is saved. The next time data is loaded, as long as it finds some data, it checks whether any new Actions were added to the system. If they were, it will examine the default mappings for any connected devices and see if there are any new bindings that contain those new Actions. It will merge those Actions into the loaded XML bindings unless it finds a mapping conflict. This is where the message you are seeing is coming from. It is 1) finding saved XML data. 2) finding new Actions that did not exist when the data was last saved. 3) trying to merge the new bindings into the existing XML data. 4) setting an AxisRange on the binding that is invalid for the Button binding. (May well be due to the fact that the Gamepad Template saves triggers as Axes with an AxisRange of Positive while your Logitech Rumblepad defines triggers as buttons which have no AxisRange or a default of Full.). The warning is not coming from the UserDataStore_PlayerPrefs code. It's coming from the Controller Map as the new binding is being created. The only solution is for me to just get rid of the warning. But that does not explain why this code is executing in the first place. This code will never execute unless it indeed finds saved XML data in PlayerPrefs at the keys it's looking for.
     
    ArachnidAnimal likes this.
  12. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,832
    Thanks for the explanations. There is no issue here afterall. It was just a misinterpretation of the intent of the warning message.
    Because I failed to fully explain the entire process in my original post:
    Cleared PlayerPrefs using the button on the inspector. PlayerPrefs is cleared. Enter playmode. Now Rewired creates the "XXX_ControllerAssignments" registry entry. Exit playmode. Re-enter playmade. Only NOW the warning is displayed on the second time entering playmode.
    (The warning is not displayed the first time entering plamode because , like you explained, the playerprefs is cleared after pressing the button)

    Thank you for the support and explanations.
     
    guavaman likes this.
  13. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    EDIT: This issue has been fixed in Rewired 1.1.22.3.

    It has been brought to my attention that the Rewired Editor does not work when editing Rewired Input Manager prefabs in Unity 2018.3 because of the new prefab workflow. Prefabs must be opened before they can be edited in the new workflow, therefore editing any prefab without previously explicitly opening it from the inspector will cause the Rewired Editor to lose connection to the prefab when you make any change in the editor such as typing in a text field or changing some value (the object reference to the component on the prefab becomes null). This affects the following scenarios:

    Having the Rewired Editor window already open, then selecting a prefab to edit:
    The data will be loaded and the editor will appear to work normally, but once you make any change, the editor will lose connection to the prefab and the interface will go blank.

    Pressing the "Launch Rewired Editor" button on a Rewired Initializer:
    The button opens the linked prefab in the editor. However, the same problem happens. The prefab has not been "opened" and therefore the object reference to it will become null the moment any data is changed. The interface will go blank. This button cannot be used anymore.

    The only way to properly edit a prefab is to select the prefab, then click "Open" button in the inspector, and only then click "Launch Rewired Editor." You have to do this every single time you want to edit the Rewired Input Manager settings on a prefab.

    The new workflow has essentially broken the interface for prefab editing in Rewired. I am investigating how to deal with this, but I suspect it's going to involve redesigning the workflow in some way. TBA.
     
    Last edited: Feb 5, 2019
    Testeria likes this.
  14. tcz8

    tcz8

    Joined:
    Aug 20, 2015
    Posts:
    504
    @guavaman I've got a little question for you:

    What's the best way to add padding on top and bottom of each InputGridFieldButton?

    The only way I got the result I wanted was (while in play mode) to open the control mapper all the way down to the "FieldLayoutGroup" (see attached picture) and to add 2 in the top and bottom padding of it's "Horizontal Layout Group" component. How can I make this permanent? I assume the "FieldLayoutGroup"s are created in code but I couldn't find where. If you can point me the way Im sure I can figure it out. (Would be nice if the padding was configurable in the theme)

    Before I go, I wanted to say that Rewired completely solved all the problems I was having with our previous input solution, thank you for making such a professional product! Oh, and the controll mapper... that thing just saved me so much time! Thank you!
     

    Attached Files:

    Last edited: Jan 25, 2019
  15. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    All you have to do is search ControlMapper.cs for "FieldLayoutGroup" and it will take you to where that is created. But I do not recommend editing the source code because your changes will be lost every time you update Rewired. However there is no easy way to add a padding by copying and editing the button prefab. This is probably something where I'm going to have to change the code and add another inspector option.

    I'm glad to hear Rewired has been valuable to you! Thanks!
     
  16. tcz8

    tcz8

    Joined:
    Aug 20, 2015
    Posts:
    504
    Thank you, found were to add the padding.
     
  17. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
  18. Testeria

    Testeria

    Joined:
    Aug 15, 2013
    Posts:
    18
    Hey, I'm new with rewired, got few questions.

    1. Is there somewhere in docs info how gamepad template buttons translate to standard xbox/nintendo/sony buttons? (ie: "Bottom row 1" is x,y, a,b L, LZ, square, triangle?) or should I test it by try and fail technic? :)

    2. Is there a way to debug raw controller input? With "run in edit mode" I can see all the buttons and axes (both with XInput and Direct Input mode) but they never show any effect (ie. time pressed is always 0 even with buttons that work during normal play)

    3. One of my test controllers work partially - only left stick input is processed. Should I use unknown controller for this kind of problems?

    4. What is the easiest way to process stick input into radians/degrees and how precise it is?

    5. What is the best way to implement stick input gestures (ie. 360 degrees round move left or right)? Any help from rewired for this? :)

    Thanks and sorry if I misunderstand anything, It is the first time I work with controller input and it is somewhat overwhelming...
     
  19. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    Please read all the documentation sections under the heading Concepts. This is considered required reading for understanding Rewired. This is in the Controller Templates page:

    http://guavaman.com/projects/rewired/docs/ControllerTemplates.html#gamepad-template

    If you are viewing this using the Debug Information tool in the Unity Editor, always click into the Game window before doing your tests. If the inspector window is the focused editor window, all input will be blocked and you will see no results in the window.

    View live low-level joystick information:
    Debug Information -> Controllers -> Joysticks -> THE JOYSTICK -> Buttons / Axes

    View live Action values:
    Debug Information -> Players -> THE PLAYER -> Actions -> THE ACTION CATEGORY -> THE ACTION

    The absolute lowest level information you can get is through the Assets/Rewired/DevTools/JoystickElementIdentifier tool. That is only used for creating controller definitions for the most part and rarely used by end users.

    What kind of controller is it? If it is not recognized (not listed here for the platform / input source), it is an Unknown Controller.

    View live low-level joystick information to determine if this controller is returning any values for the other elements:
    Debug Information -> Controllers -> Joysticks -> THE JOYSTICK -> Buttons / Axes

    If it's not returning any values, check it using the Assets/Rewired/DevTools/JoystickElementIdentifier tool. If it still isn't returning any values, the controller cannot work with Rewired for an unknown reason.

    You don't work with sticks in Rewired because Rewired is primarily an Action-based system, not controller-based. You can process any two Actions you want into a Vector2, either manually, or by using the convenience function Player.GetAxis2D.

    It does not convert the value to an angle. If you want to do that, use Unity's standard methods for that:
    Vector2.SignedAngle.

    Rewired does not provide anything for interpretation or application of input values. It does not include a gesture recognition system. Rewired provides the input values and it's up to your scripts to process them however you see fit.
     
  20. Testeria

    Testeria

    Joined:
    Aug 15, 2013
    Posts:
    18
    Thank You! I thought that I checked all the docs but apparently missed this page. Need to read it again from start to end this time.

    I feel silly now. That solves most of my problems.

    It's QSmart Nintendo Switch/PC XInput controller, it's recognized as xbox360forWindows. I see debug window now, must made some mistake with mappings.

    Vector is enough, thanks. Still not fully undertanding Rewired and how things are done here.


    yes, I can handle this - just wanted to be sure not to repeat existing functionality.

    Thanks for very nice extension, it is really fun to learn controller input with it - and docs is superb comparing to most other assets. :D
     
    guavaman likes this.
  21. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    They do have Tornado spinners that work really nicely and already have USB connectors. The price is about $99 which is really good.

    https://tornadospinner.com

    They have really nice gallery of different arcade style control setups that @guavaman would like too.

    https://tornadospinner.com/gallery
     
    Last edited: Jan 29, 2019
  22. Steve-Tack

    Steve-Tack

    Joined:
    Mar 12, 2013
    Posts:
    1,240
    Though I could pay $12 per visit at my local retro arcade and play all of the Tempest I could stomach. :D Which actually isn't very much as it turns out, haha.
     
  23. Kiupe

    Kiupe

    Joined:
    Feb 1, 2013
    Posts:
    528
    Hello,

    I'm trying to trigger a custom controller event button when a swipe is performed. To do so I used a gesture asset that handle the swipe detection. When a swipe is detected I save that information.

    Here are the code to listen to the custom controller button and the callback functions

    Code (CSharp):
    1. _player.AddInputEventDelegate(OnMoveLeftHandler, UpdateLoopType.Update, InputActionEventType.ButtonJustPressed, KumikiForestRewiredConsts.Action.Exploration.MoveLeft);
    2.             _player.AddInputEventDelegate(OnMoveRightHandler, UpdateLoopType.Update, InputActionEventType.ButtonJustPressed, KumikiForestRewiredConsts.Action.Exploration.MoveRight);
    Code (CSharp):
    1. private void OnMoveLeftHandler(InputActionEventData eventData)
    2.         {
    3.             Debug.Log("[KumikiForestGameSequenceController]OnMoveLeftHandler");
    4.         }
    5.  
    6.         private void OnMoveRightHandler(InputActionEventData eventData)
    7.         {
    8.             Debug.Log("[KumikiForestGameSequenceController]OnMoveRightHandler");
    9.         }
    Then the code to listen when inputs are updated
    Code (CSharp):
    1. ReInput.InputSourceUpdateEvent += ReInput_InputSourceUpdateEvent;
    And the callback function
    Code (CSharp):
    1.  
    2. void ReInput_InputSourceUpdateEvent()
    3.         {
    4.             if (_customController != null && justSwipe)
    5.             {
    6.                 switch (swipeDirection)
    7.                 {
    8.                     case GestureController.DIRECTION.LEFT:
    9.                         Debug.Log("\tSet MOVE LEFT");
    10.                         _customController.SetButtonValueById(KumikiForestRewiredConsts.CustomController.PadController.Button.MoveLeft, true);
    11.                         break;
    12.                        
    13.                     case GestureController.DIRECTION.RIGHT:
    14.                         Debug.Log("\tSet MOVE RIGHT");
    15.                         _customController.SetButtonValueById(KumikiForestRewiredConsts.CustomController.PadController.Button.MoveRight, true);
    16.                         break;
    17.                 }
    18.                
    19.                 justSwipe = false;
    20.             }
    21.         }
    22.  
    23.  
    The first left and right swipes do work correctly, meaning that at the end the OnMoveLeftHandler and OnMoveRightHandler methods are called. But after that they are not called anymore.
    The debugs (SET MOVE LEFT / SET MOVE RIGHT) inside the ReInput_InputSourceUpdateEvent methods are displayed, meaning the code that set the custom controller button values are reached. But it won't trigger the input event.

    Any idea why ? I naively tried to set button values to false before set it back to true but it did not change anything.

    Thanks
     
  24. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    A Custom Controller is like any other Controller. It will not produce input in a Player unless all the following is true:
    1. The Controller is enabled.
    2. The Controller is assigned to the Player.
    3. Controller Map(s) exist that binds Controller elements to Actions.
    4. Those Controller Maps are loaded in the Player and enabled.
    5. The Action Element Bindings on the Controller Map are enabled.
    As always, Debug Information is the most important tool for finding out what's wrong.
     
  25. Kiupe

    Kiupe

    Joined:
    Feb 1, 2013
    Posts:
    528
    I will read about Debug Information. But like a said, everything work fine for the first gesture - and I used this custom controller for other inputs and can assure you that 1. to .5 are correctly set :)
     
  26. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    It is because you are never setting the button value to false. Custom Controller element values are exactly what you tell them to be. They do not auto-reset to zero. You would be able to see this using the Debug Information tool. You would see the value of the button in the controller is always True.
     
  27. Kiupe

    Kiupe

    Joined:
    Feb 1, 2013
    Posts:
    528
    Hi,

    Actually I made several tests setting the button value to false. Because it did not worked out, I decided to not bother you with all my code attempts. One of those test was to check if the button value was already equal to true, if so, set it to false and wait the next time the method is called to actually set it back to true. But, I will use the Debug Information tool and hope to find out what is really happening.
     
  28. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    Setting the CustomController button to False and Then true again on the same frame when justSwipe == true will not work. Action down/up values are calculated based on the difference of the input element's value on the previous and current frames, in this case the Custom Controller button. Calculation of Action values happens after InputSourceUpdateEvent (which is reason the event exists -- so you can set element values before Actions are calculated.)

    You need to set the value of the CC button to false every frame that you aren't sending True values as a result of the justSwipe event. Now the button will only be on for a single frame and ButtonJustPressed will return True for that frame every time.

    Code (csharp):
    1. void ReInput_InputSourceUpdateEvent()
    2. {
    3.     if (_customController == null return;
    4.     if(justSwipe)
    5.     {
    6.         switch (swipeDirection)
    7.         {
    8.             case GestureController.DIRECTION.LEFT:
    9.                 Debug.Log("\tSet MOVE LEFT");
    10.                 _customController.SetButtonValueById(KumikiForestRewiredConsts.CustomController.PadController.Button.MoveLeft, true);
    11.                 break;
    12.        
    13.             case GestureController.DIRECTION.RIGHT:
    14.                 Debug.Log("\tSet MOVE RIGHT");
    15.                 _customController.SetButtonValueById(KumikiForestRewiredConsts.CustomController.PadController.Button.MoveRight, true);
    16.                 break;
    17.         }
    18.  
    19.         justSwipe = false;
    20.     }
    21.     else
    22.     {
    23.         _customController.SetButtonValueById(KumikiForestRewiredConsts.CustomController.PadController.Button.MoveLeft, false);
    24.         _customController.SetButtonValueById(KumikiForestRewiredConsts.CustomController.PadController.Button.MoveRight, false);
    25.     }
    26. }
     
    Last edited: Feb 1, 2019
  29. Cramonky

    Cramonky

    Joined:
    Apr 1, 2013
    Posts:
    186
    Hey,

    I am working with adding the ability to remap controls, and I have a question about remapping when it comes to controllers. For my game, all players (up to 4) will always have the same input mappings for keyboard, mouse, and controllers. I've had to do a little finagling to make it so that users only have to change the mapping in one place and have it applied to all players. I've done it this way just to keep things simple for users.

    But, it looks like the only way to replace inputs on controllers is if there is a controller currently assigned to the player. This causes a problem for me since, if a player doesn't have a controller connected at the time a mapping is changed, that player will not get the updated mapping.

    Is there a way to do this? Perhaps I need to hook into a controller connected event and sync the inputs there? Thanks in advance.
     
  30. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    That's exactly what you have to do for multiple reasons:

    1. You cannot change bindings on Controller Maps in the Rewired Input Manager at runtime which are the bindings Rewired will load for each Player when connecting a new Joystick.
    2. See the sections entitled IMPORTANT and Persistent currently enabled Controller Map Category here. This applies to changed bindings as well as the enabled state. All editing of Controller Maps happens only to the live Controller Map instances that exist in the Player at the time of the change.
    3. Old Controller Maps for Joysticks a Player owned previously in a game session are retained for future reconnections. There would not be updated when you change mappings while the Joystick is not connected.

    User mappings have to be loaded from XML or JSON. You are better off saving/loading mappings for the Template in this situation: Then load the mappings for all Players on ReInput.ControllerConnectedEvent. You will also have to do it if you manually assign a Joystick to another Player because the Player does not load the Controller Maps for a Joystick until it is actually assigned.
     
  31. Cramonky

    Cramonky

    Joined:
    Apr 1, 2013
    Posts:
    186
    I see, thanks for the info, I'll check it out.
     
  32. Kiupe

    Kiupe

    Joined:
    Feb 1, 2013
    Posts:
    528
    Thanks for that. I did set the value to false as expected (not in the same frame) but did not know that I had to do that every frame.

    Thx
     
  33. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    You don't have to do it every frame. You do have to do it at least once after you set it to true if you want it to become false again. It will stay in the last state you set it to. But your if structure has to be set up so that you set the value to false for any button that didn't just get activated by justSwipe.
     
  34. Srokaaa

    Srokaaa

    Joined:
    Sep 18, 2018
    Posts:
    169
    Hey,

    I working on a game where player moves on a hexagonal grid so the Player has 6 directions to choose from. How would I go about mapping joystick input to this? Can I map it somewhere to one of the 6 directions so that I can get this just form ReInput class or should I just calculate it every time I call ReInput.GetPlayer(<playerId>).GetAxis2D("<axisName>)?
     
  35. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    No. This kind of input processing is beyond the input system's responsibility. It gives you the values, you use them for something. The implementation would be the same for directional input coming from any input system. You'd do it like reading any directional value and using it for any other purpose.

    The first thing that comes to mind is to make a Vector2 out of them, find the angle, and snap it to the nearest one.
     
  36. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    Rewired 1.1.22.3 is now available on the Unity Asset Store.

    Please see Updating Rewired before updating.

    1.1.22.3:

    Changes:
    - Changed editor code to properly handle Unity 2018.3.0+ new prefab system workflow.
    - Added Open Prefab button to Rewired Editor when editing a prefab instance.
    - Control Mapper: Added Input Row Padding inspector option.
    - Control Mapper: Added Input Row Field Spacing inspector option.

    Bug Fixes:
    - Fixed incorrect D-Pad mappings in Thrustmaster FireStorm Dual Power mapping in Gamepad Template.
    - Fixed issue causing buttons to sometimes trigger a "false, true, false" sequence on OSX when using Sony DualShock 4 controller connected via USB, Native input, Fixed Update enabled in Rewired Input Manager update loop settings, and Enhanced Device Support enabled.
     
  37. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    Rewired now supports IL2CPP on Windows and Mac standalone platforms.
     
    jason_yak and Kolyasisan like this.
  38. Kolyasisan

    Kolyasisan

    Joined:
    Feb 2, 2015
    Posts:
    397
    Oh my! What a nice thing to discover. Thanks for notifying!
     
  39. Ward101

    Ward101

    Joined:
    Mar 22, 2016
    Posts:
    52
    Simple question, but I'm not finding an easy solution.
    I've an Axis action, where I register as an event like this:

    Code (CSharp):
    1. operatorPlayer.AddInputEventDelegate(OnInputUpdateOperador, UpdateLoopType.Update, InputActionEventType.Update, "PLatform_Turn");
    2.  
    As I don't want to trigger the event on every update (as I've many other registrations), I would like to get the event launched just when the axis changes value. Hence, I'm changing to:

    Code (CSharp):
    1. operatorPlayer.AddInputEventDelegate(OnInputUpdateOperador, UpdateLoopType.Update, InputActionEventType.AxisActive, "PLatform_Turn");
    2.  
    The problem is that I cannot detect the axis going back to 0.
    Which is the best way to register an Axis to get just when the axis is active, but also detect when it returns to 0.
    The issue with InputActionEventType.AxisInactive is that I'm getting the event fired whenever the axis value is 0, and keeps firing it, till axis changes.

    Tried InputActionEventType.ButtonJustReleased , and works, but only if I release the joystick after Axis value surpasses 0,5

    Thanks for your help!
     
  40. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    There is no AxisValueChanged event. Joystick axes are absolute axes, which means they return the same value every frame they're active and need to be processed every frame regardless of whether or not the value changes. If you only process changes, you will get no value when, for example, the user is holding the stick all the way in one direction.

    One way to do what you want through events is to use both AxisActive and AxisInactive together, which is essentially the same as polling the axis. You could also just get the Update event on the Action without specifying an event type and poll the axis value from within the callback.
     
    Last edited: Feb 5, 2019
  41. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    That was fast. Thanks for the update on the 2018.3 prefab.
     
    f1chris likes this.
  42. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    You're welcome.

    Yeah, I'm a bit shocked. My last 2 or 3 updates have been approved next day. I suspect the Unity Asset Store has started automating submission approvals.
     
  43. Ward101

    Ward101

    Joined:
    Mar 22, 2016
    Posts:
    52
    Thanks for your replay! I fond a better workaround, that may be helful, depending on the user configurations.
    I created a new Input Behavior, where I configured Button Dead Zone to 0.0001 (or a very small val, each shoud find a suitable).
    I assigned it just to some specific actions I want to have this specific behavior.
    And finally, added the delegates as shown below.
    On OnInputUpdateOperadorAxis I process the events based on the input event type.
    This way, I'm just getting the notif when the Axis is != 0, or when reaches to 0 (or almost 0), but only once, and not on every Update.

    You must be carefull if you assign also the keyboard (any key), to control the axis, you won't have desired results.

    Code (CSharp):
    1.  operatorPlayer.AddInputEventDelegate(OnInputUpdateOperadorAxis, UpdateLoopType.Update, InputActionEventType.AxisActive, "Platform_Turn");
    2.  operatorPlayer.AddInputEventDelegate(OnInputUpdateOperadorAxis, UpdateLoopType.Update, InputActionEventType.ButtonJustReleased, "Platform_Turn");
    3.  operatorPlayer.AddInputEventDelegate(OnInputUpdateOperadorAxis, UpdateLoopType.Update, InputActionEventType.NegativeButtonJustReleased, "Platform_Turn");
    4.  
    5. ...
    6. ...
    7. ...
    8.  
    9. private void OnInputUpdateOperadorAxis(InputActionEventData data)
    10. {
    11. ...
    12. ...
    13.                    switch (data.eventType)
    14.                     {
    15.                         case InputActionEventType.AxisActive:
    16.                             Debug.Log("AxisActive " + axisVal);
    17.                             break;
    18.                         case InputActionEventType.ButtonJustReleased:
    19.                             Debug.Log("ButtonJustReleased " + axisVal);
    20.                             break;
    21.                         case InputActionEventType.NegativeButtonJustReleased:
    22.                             Debug.Log("NegativeButtonJustReleased " + axisVal);
    23.                             break;
    24.                     }
    25.  
     
    Last edited: Feb 6, 2019
  44. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    Interesting workaround. It sounds like what you really want is AxisActive and something in effect of AxisJustBecameInactive.

    I'm curious why using AxisActive and AxisInactive is insuffucient for your use case.

    Code (csharp):
    1. if(data.eventType == InputActionEventType.AxisActive) {
    2.     // do something with the axis value
    3. } else if(data.eventType == InputActionEventType.AxisInctive && data.GetAxisPrev() != 0f) {
    4.     // Just became inactive
    5. }
    Or more simply using just the Update callback with no event type specified:

    Code (csharp):
    1. float axisValue = data.GetAxis();
    2. if(axisValue != 0f) {
    3.     // do something with the axis value
    4. } else if(data.GetAxisPrev() != 0f) {
    5.     // Just became inactive
    6. }
     
  45. Cramonky

    Cramonky

    Joined:
    Apr 1, 2013
    Posts:
    186
    Hey again,

    I'm having some trouble with ReInput.mapping.GetJoystickMapInstance. I was wanting to use it to display my joystick mappings using the Xbox One controller names, however the JoystickMap and ActionElementMaps I'm getting don't have any names populated. All of the elementIdentifierIds are correct, though. I'm using the Xbox One GUID from the RewiredControllerElementIdentifiers CSV.
     
  46. Ward101

    Ward101

    Joined:
    Mar 22, 2016
    Posts:
    52
    What you propose was my first approach, and is usually enought.
    On my app I've many axis, each launching events on each update (and I'm having more than 100FPS). Hence, I'm getting many many unneded hits (most of the time axises are 0) .
    THat's what I was trying to avoid, as I'm on an optimization phase.

    THanks!
     
  47. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    The problem is your optimization isn't going to reduce the number function calls at all. By adding event handlers for ButtonJustReleased and NegativeButtonJustReleased, you've just shifted the burden onto Rewired's internal code to check for these two extra conditions and send you the events for every axis. Ultimately, the number of function calls has actually increased by doing this versus using my last example which results in 1 event callback and 2 function calls per axis. Your version results in 3 event callbacks, plus at least 1 function call to get the axis value, plus the internal checks for ButtonJustReleased and NegativeButtonJustReleased.
     
  48. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    What version of Rewired are you using? And which GetJoystickMapInstance overload?
     
  49. quitebuttery

    quitebuttery

    Joined:
    Mar 12, 2011
    Posts:
    329
    I'm having a problem with the remapper. I'm using the SimpleControlRemapping example as the basis for my remapping system--but it doesn't really seem to work very well. I added a button to load the defaults, which simply does this:

    player.controllers.maps.LoadDefaultMaps(selectedControllerType);
    RedrawUI();

    This works once per session. When it does, after you click this button and it restores the settings, but none of the controls can be remapped after this. Pressing buttons does nothing on the remapping screen. I have to restart the game, or in the Editor shut down the editor and restart it.

    Is there anything I can do to get the default maps to work? I'm considering tearing out Rewried and using the new input system in 2018.3 since this is a critical feature of my game.

    Also, if I save the mapping, when I click the cancel button after changing bindings to load the last saved map, nothing happens, unless I restart. This is how I try to load the previously saved maps.

    ReInput.userDataStore.Load();
    RedrawUI();
     
    Last edited: Feb 7, 2019
  50. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    Then you're storing references to Controller Maps and/or Action Element Maps that no longer exist. There is nothing about loading the default maps that would make them unmodifiable. Controller Maps and Action Element Maps are objects. Storing a reference to an object or to an id that points to an object which no longer exists because it's been replaced by loading the defaults, then trying to act on those objects will definitely lead to you seeing no changes being made.

    You can see exactly what is happening by looking at what is loaded live in Debug Information:
    http://guavaman.com/projects/rewired/docs/Troubleshooting.html#debug-information

    You can see every single Controller Map and Action Element Map, the id's of them, and all bindings live. Use this to debug your code.

    Do whatever you think is best if you think this will solve your issues. Hundreds of games have been published with Rewired and have working controller remapping. Thanks.
     
    Last edited: Feb 7, 2019