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:
    3,833
    I don't have anything like DS4Win installed and I still get the RI.HID error nearly every time I start Unity, even the latest 2018 beta. I think they got rid of this issue in some 5.x or maybe even 4.x version a long time ago, but it's definitely back. It likely isn't the same issue because Rewired doesn't throw this HID error ever on my machine, unless Unity is just trying to open some other non-controller system devices that Rewired isn't.

    I did used to have DS4Win installed on my old dev machine and never saw this HID error with it. But who knows if they've changed something to open the HID device in exclusive mode or something.
     
  2. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,833
    Glad to. It's always been about making it easy for you to do whatever you want with input.

    One of the coolest things about Controller Templates vs the standard way of thinking about a "Controller Type" is that one Controller can implement as many Controller Templates as you want. Take this example:

    If these were 3 separate Controller Templates.
    • Flight Stick Template
    • Throttle Template
    • Flight Pedals Template
    Your Controller would implement all 3 and you could just work with the Template you're interested in:

    Code (csharp):
    1. controller.GetTemplate<IFlightStickTemplate>();
    2. controller.GetTemplate<IThrottleTemplate>();
    3. controller.GetTemplate<IFlightPedalsTemplate>();
    One caveat here though is that for the Action-mapping part of this equation, only the first compatible Template found that has a Controller Map defined for it in that category/layout will be used to generate the Controller Map. Multiple separate maps defined for different Templates in the same category/layout will not merge into a single Controller Map. That might be something I'd consider changing, though there would be difficulties with clashes such as in the case of the HOTAS template which also implements pedals, throttles, stick, etc... Just thinking out loud.
     
    Last edited: May 10, 2018
  3. jmdeb

    jmdeb

    Joined:
    Jul 28, 2017
    Posts:
    11
    Thanks a lot for this complete reply!
    One last think, promise! ;) : what would you suggest to do the 'inverse': react to the first key/mouse/gamepad event to go out of 'sleep'?
    Thanks again for your great support!
     
  4. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,833
    Both of those examples already show that.
     
  5. LitchiSzu

    LitchiSzu

    Joined:
    May 14, 2016
    Posts:
    17
    @guavaman Just wanted to say thank you for your work in fixing the issue with input not working in editor when the game view is not focused!
    May not sound like a big thing, but these past days being on 2018.1 with issue were really annoying and it's really nice to see it fixed that quickly! (eventhough the source of the issue wasn't Rewired itself)
    Our team really appreciate it!
     
    guavaman likes this.
  6. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,833
    I made a mistake in the last update. The constant for the Rewired version was accidentally set to 1.1.3.0 instead of 1.1.13.0. I've submitted the new update already (with a couple of additions and changes). Hopefully it will be approved quickly. Registered users can download the update now. If you'd like early access to updates, contact me here.

    Please see Updating Rewired before updating.

    Release Notes:

    1.1.14.0:

    API Changes:
    - Added ReInput.ControllerHelper.controllerCount.
    - Changed ReInput.ControllerHelper.Controllers return type to IList from IEnumerable.
    - Deprecated ReInput.MappingHelper.GetFirstJoystickTemplateElementIdentifier method.

    Controller Definitions:
    - Microsoft Xbox 360 Controller, Linux Native: Added mapping for wireless controller on Arch Linux.
     
  7. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,449
    Like @Steve-Tack I find the HOTAS template to work just fine for 99% of things I work with.

    Helicopters are just more exciting with Puma.

    This is really nice visual input mapping in X-plane 11 for the Puma which is really nice.

    https://www.helisimmer.com/news/pro-flight-trainer-puma-visual-config-coming-to-x-plane-tow-brakes

    I am just amazed at how much helicopter sticks are around but with low production makes them fairly pricey. It really makes the Puma the best overall package for the price.

    http://www.maxflightstick.com/store/
     
    guavaman likes this.
  8. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,449
    That will be very handy. Hope they can release this update tomorrow.
     
  9. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,833
    Just FYI, this means all Controllers of all types including the keyboard and mouse.
     
  10. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,833
    That's some amazing hardware!
     
  11. RedToasty

    RedToasty

    Joined:
    Nov 24, 2014
    Posts:
    9
    Hi, I purchased last night and I'm having issues adding the library to my build. I build an Android via IL2CPP. The exporting process will get to the point of building the IL2CPP bits and stalls, never to complete the build. I left it going overnight, just to confirm it wasn't just a long build.

    I've not hooked anything up, literally just importing the unitypackage and rebuild, zero issues before, I make multiple builds per day. Remove it and it'll build again.

    I've tried both 2018.1.0f2 and 2018.2.0b3 and tried clearing my library, no joy. I've tried removing ARM64 and building just ARMv7, switching between .net 2.0 and 2.0 subset, nothing seems to help. My project isn't huge, WebsocketSharp is the only other sizable library in there. I rely heavily on running native code, via DllImports and I've found performance to be at it's best on the 2018 builds via IL2CPP, so changing anything around isn't really any option.

    Any ideas? Thanks!
     

    Attached Files:

  12. RedToasty

    RedToasty

    Joined:
    Nov 24, 2014
    Posts:
    9
    I should also add, I'm using Rewired 1.1.3.0, on Windows 10. Minimum Android API 5.0, targeting Android 8.0 (O). Although given it's not got through the IL2CPP stage, I'm not sure the Android API will make much difference.

    As a quick test I deleted the Rewired folder, keeping just the Rewired_Core.dll in my plugins folder and calling a couple of methods on it, to stop it stripping. The builds are still stalling. Without the method calls it strips it and builds fine. I'm not sure what it doesn't like about it.
     
    Last edited: May 11, 2018
  13. Thermos

    Thermos

    Joined:
    Feb 23, 2015
    Posts:
    51
    Hi,

    I'm here to report a bug.

    ElementIdentifierName of keyboard ActionElementMap always return null(null, not empty string), this happens since i upgrade to 1.1.3.0.U2018.
     
  14. IceBeamGames

    IceBeamGames

    Joined:
    Feb 9, 2014
    Posts:
    116
    Hey @guavaman. Sorry about the last post. I'll remove the discussion.

    I'm also experiencing a new bug. I'm attempting to get GetFirstElementMapWithAction on the player's controller and it isn't returning the very first action element.

    Here is element 0, which is move horizontally.

    joystick_maps.jpg

    I'm not getting the correct element identifier back, and instead I'm getting D-Pad Right, which is further down (element 11).

    Here is the call:
    Code (CSharp):
    1. ActionElementMap actionElementMap = player.controllers.maps.GetFirstElementMapWithAction(controller, actionId, true);
    Also, when I first open up the joystick maps editor window, the first element action category is "Default" and the action window is blank until I click the second entry and then the first again. Could be related?

    joystick_map_incorrect.jpg

    Its probably something I've done when updating the version of rewired?
     
  15. GfK

    GfK

    Joined:
    Aug 15, 2014
    Posts:
    107
    I'm getting some oddness since upgrading to Rewired 1.1.3.0.U5.

    I'm using a Playstation DS4 with DS4Windows - everything was fine until just now when I upgraded Rewired.

    Problem is, when I connect the DS4 and run my game, the L2 trigger didn't work (it's meant to make the player move sideways, to the left). I disconnected and reconnected the DS4, at which point L2 behaved exactly like it was R2, moving the player to the right.

    Tested the DS4 in Windows Game Controller Setup, and in DS4Windows, and both triggers are working as expected.

    So I plugged in my regular Xbox One controller, and both triggers worked correctly.

    Back to the DS4, L2 was dead again! Logically you'd point the finger at DS4Windows here, but, given that everything worked fine with the older version of Rewired, I'm not so sure DS4Windows is to blame...

    Ideas?

    [edit] This is strange:
    ds4.png

    In Rewired debug info with my DS4, the number in brackets for Axes 4/5 (L2/R2) defaults to -1.000, and goes gradually up to 1.000 as I press either trigger. With the Xbox One controller (which works fine), all values default to 0.000 and go up to 1.000.
     
    Last edited: May 11, 2018
  16. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,833
    This is a bug in the NDK 13b compiler. It does not occur with newer NDK versions. I have already talked with Unity about it due to failure in Rewired 1.1.12.1. They tracked it down to the NDK version. It is random. I cannot predict which builds will fail on NDK 13b. One time I build, it will work, another time I build it will fail. It sounds like 1.1.13.0 failed while 1.1.12.2 did not. 1.1.14.0 and 1.1.14.1 do not fail. (The only possible way I can guarantee every version of Rewired, Trial and Release, works with Android IL2CPP is to test build on Android IL2CPP with NDK 13b every single time I make an update which I have no other choice but to do from now on.)
     
    Last edited: May 11, 2018
  17. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,833
    Thanks. It is fixed. I will upload the update today. If you want it immediately, contact me here.
     
  18. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,833
    Player.ControllerHelper.MapHelper.GetFirstElementMapWithAction has not changed at all in any recent update.

    The search order of ControllerMap.GetFirstElementMapWithAction is not guaranteed or even likely to be the order you see the elements in the Rewired Editor. Rewired stores element mappings in separate Buttons and Axes lists. Buttons are searched by the base Controller Map before Axes are searched by the sub-class ControllerMapWithAxes. Therefore, if you have an Action mapped to a Button and an Axis, it will always return the Button first. You have Move Up/Down/Left/Right mapped to both the Left Stick and the D-Pad, therefore it will always return the D-Pad first. You must not have had the D-Pad mapped before and therefore were receiving the Left Stick as the first. Even if they somehow would stay in order, you'd have problems after user remapping because the elements would no longer be in the order you expect. Even if you search ControllerMap.AllMaps manually and just take the first, you will find the Buttons listed first before the Axes. There is no preservation of editor order of Action Element Maps in the live data.

    The "GetFirst" methods are just for convenience and assume that you only have an Action mapped once or only care about one of them without specifically wanting it to be a particular element. If you need that, then you can't use the "GetFirst" methods. There are a ton of other methods that can be used to find the Action Element Maps you want in the Controller Map. There are also other convenience methods in the Player.ControllerHelper.MapHelper class.

    If you specifically want the Axis mappings to have higher priority, you can search the Axes list first, then the Buttons list.
     
  19. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,833
    No. What you are describing is the fact that you do not have a "Default", "Default" Controller Map defined and therefore it is blank. When you select "Game", it loads the "Game", "Default" Controller Map.
     
  20. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,833
    This is a Gamepad Template problem that arose due to all the changes to the Controller Template system. The L/R triggers were changed from Buttons to Axes in the Template map and that had the effect of not doing the proper mapping conversion for the triggers when the real Controller Map was generated if binding to opposite sides of an Axis-type Action. This isn't specific to the DS4. It would affect any non-XInput gamepad with analog triggers.

    I really hate the fact that I cannot push updates to the Asset Store immediately and have to wait for their approval process every time. Contact me here to get the update immediately.

    You are looking at the raw value. This is the way the devices work at the low level and the reason Rewired includes all these controller definitions to make all the wide variety of elements and return values return something that makes sense.
     
    Last edited: May 11, 2018
  21. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,833
    Rewired 1.1.14.1 is now available for registered users. Please contact me here to get early access to updates.

    Please see Updating Rewired before updating.

    Release Notes:

    1.1.14.1:

    Bug Fixes:
    - Fixed issue in Gamepad Template causing L/R triggers to map incorrectly when bound to individual poles of an Axis-type Action on some gamepads introduced in 1.1.13.0.
    - Fixed issue ActionElementMap.elementIdentifierName on Keyboard Maps returning null introduced in 1.1.13.0.
     
    Last edited: May 11, 2018
  22. RedToasty

    RedToasty

    Joined:
    Nov 24, 2014
    Posts:
    9
    Typo in your support link by the way :)
     
  23. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,449
  24. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,833
  25. Doghelmer

    Doghelmer

    Joined:
    Aug 30, 2014
    Posts:
    112
    A quick question - How do I completely revert the Rewired settings for a particular game on Mac? To be more specific, this would be the Mac equivalent of going into Regedit and deleting my settings for that game.
     
  26. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,833
    Rewired stores nothing unless you are using UserDataStore_PlayerPrefs which is a component used on Control Mapper. If you are using that, like the name of the component says, it uses PlayerPrefs. The only way to clear the data is to wipe PlayerPrefs.

    PlayerPrefs.DeleteAll

    Or you can delete PlayerPrefs manually. The PlayerPrefs documentation tells you where it's stored on each platform:

    On macOS PlayerPrefs are stored in ~/Library/Preferences folder, in a file named unity.[company name].[product name].plist, where company and product names are the names set up in Project Settings. The same .plist file is used for both Projects run in the Editor and standalone players.
     
  27. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,833
    Announcement:
    If you have contacted me at the support form at http://guavaman.com/rewired#support and did not receive a reply within 1 day, please check your spam folder. If you still do not see a response, contact me again and I will re-send the email to you using a different email address. I have been having a number of Gmail and Googlemail users not receive my support email responses and they assume I did not respond. This is not the case. I respond to 100% of support requests, almost always on the same day the request was sent.
     
  28. Sendatsu_Yoshimitsu

    Sendatsu_Yoshimitsu

    Joined:
    May 19, 2014
    Posts:
    666
    This is probably a silly question, but since it can be easy to accidentally skunk up Rewired's configuration I wanna be sure: I want to share my project with a second developer via source control; I'm using Windows 8, my partner's on OSX. As long as we've both bought the asset and are operating on the same version of Unity, does he need to take any special steps before pulling? Or will the same default setup work on both operating systems?
     
  29. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,833
    Rewired has to be installed in order to create the Unity input manager entries used on any Unity fallback platform, if native input is disabled, or if mouse/keyboard is supported through the use of Unity input. If you are pulling the entire project directory including the ProjectSettings folder, it will work. There are no differences between OSX, Windows, and Linux editor data whatsoever. Obviously, you must have visible .meta files enabled and copy those as well.
     
  30. Sendatsu_Yoshimitsu

    Sendatsu_Yoshimitsu

    Joined:
    May 19, 2014
    Posts:
    666
    Awesome, thanks for confirming! :)
     
  31. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,833
    Rewired 1.1.4.1 is now available on the Unity Asset Store.

    Please see Updating Rewired before updating.

    Release Notes:

    1.1.14.1:

    Bug Fixes:
    - Fixed issue in Gamepad Template causing L/R triggers to map incorrectly when bound to individual poles of an Axis-type Action on some gamepads introduced in 1.1.13.0.
    - Fixed issue ActionElementMap.elementIdentifierName on Keyboard Maps returning null introduced in 1.1.13.0.

    1.1.14.0:

    API Changes:
    - Added ReInput.ControllerHelper.controllerCount.
    - Changed ReInput.ControllerHelper.Controllers return type to IList from IEnumerable.
    - Deprecated ReInput.MappingHelper.GetFirstJoystickTemplateElementIdentifier method.

    Controller Definitions:
    - Microsoft Xbox 360 Controller, Linux Native: Added mapping for wireless controller on Arch Linux.
     
  32. PsyDev

    PsyDev

    Joined:
    Sep 30, 2015
    Posts:
    31
    I'm seeing an issue where input is being dropped. Some key presses are not being reported by Rewired, but are being detected by Unity. It seems to be when frame rate gets really low. Rewired is integrated with UFPS, but I don't think that is related, as it looks like the vp_Input.GetButtonDown() calls get overriden by the Rewired integration and forwarded to Rewired player.

    With this code:
    Code (CSharp):
    1.     void Update()
    2.     {
    3.         if(Input.GetKeyDown(KeyCode.F))
    4.         {
    5.             Debug.Log("InputTest: F");
    6.         }
    7.  
    8.         if(vp_Input.GetButtonDown("ActionMappedToF"))
    9.         {
    10.             Debug.Log("InputTest:  rewired action F");
    11.         }
    12.     }
    13.  
    you see the F presses in the debug log but sometimes not the Rewired ones.

    I start to see it as soon as the framerate drops below 30 fps, and it gets worse the lower the frame rate.

    Is this a known issue? Is there a way I can ensure all key presses are captured?
     
  33. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,833
    1. What platform is this?
    2. What version of Rewired are you using?
    3. What is your Primary Input Source set to in Rewired Editor -> Settings -> PLATFORM?
    4. Is Use Native Keyboard enabled in Rewired Editor -> Settings -> PLATFORM?

    All of these settings make a tremendous difference on what may or may not be happening here because of how differently every code path works.

    Rewired has been written to never miss button presses, even going to the extent of having separate threads to poll for input from joysticks on input sources that require polling (as opposed to events).

    However, when querying GetButtonDown for an Action, this will not repeat ButtonDown events in successive sequential frames if the frame rate is low enough that the key is being pressed as fast or faster than the frame rate. This is because ButtonDown events are calculated from the previous value compared to the current value for the current update loop in question (Update, Fixed Update, OnGUI, etc.). If the frame rate is 10 fps, if you press a button 5 times in a row at a speed of 10x / sec, it will only report the first ButtonDown event and subsequent frames will simply report Hold events. This is because the value of the previous frame was ON, the value of the current frame is ON, so there is no ButtonDown event generated. It will not miss a ButtonDown press when pressed at any arbitrary time at any point even if the frame rate is 1fps. The only time it will not generate ButtonDown events is during rapid pressing at low framerates.

    Polling Input.GetKeyDown is essentially directly polling the keyboard device for events. Unity keeps track of input events only on the Update loop, not Fixed Update or any other, so ButtonDown and ButtonUp only work in Update.

    Polling Player.GetButtonDown is not a direct-device polling -- it is polling a "virtual element" that is created from a combination of any arbitrary number of buttons, axes, and virtual elements all together. Rewired calculates the ButtonDown and ButtonUp events for this Action each frame for each of the enabled update loops.
     
    Last edited: May 17, 2018
  34. Daft_Hunk

    Daft_Hunk

    Joined:
    Nov 15, 2016
    Posts:
    15
    Hello ! I have a little (and maybe dumb, sorry if it is) question about remapping at run-time.

    I'm using Rewired in my game and I allow the user to rebind is keys in a custom config menu.
    Quite everything works fine after some tweaking but thanks to the documentation it was quite easy.

    However, I want the user to be allowed to clear a mapping by pressing a specific key, so I use this callback and made this piece of code :
    Code (CSharp):
    1. // Called by InputMapper when a controller element is activated while polling
    2.     bool OnIsElementAllowed(ControllerPollingInfo info)
    3.     {
    4.         // Ignore the Space key on the keyboard
    5.         if (info.keyboardKey == KeyCode.Delete)
    6.         {
    7.             if (context != null && context.controllerMap != null && context.actionElementMapToReplace != null)
    8.                 context.controllerMap.DeleteElementMap(context.actionElementMapToReplace.id);
    9.             inputMapper.Stop();
    10.             return false;
    11.         }
    12.  
    13.         // Allow all other controller elements
    14.         return true;
    15.     }
    It's working fine for keyboard mapping but not for mouse mapping, did you have another idea for achieving the same goal ?
    Thanks in advance :)
     
  35. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,833
    If I understand what you're trying to do, this is absolutely the wrong approach. That callback does not exist for any other purpose other than to allow you to filter out input you want to ignore while polling for bindings.

    If you want to clear a binding, you do not do it during polling. This is a completely separate process and does not involve Input Mapper at all. Clearing a binding is a process you do on the Controller Map at any time. Input Mapper exists to poll for input and create the mappings. It does not do any other binding management.

    You would call ControllerMap.DeleteElementMap to delete the ActionElementMap you no longer want bound do anything. You would usually fire off this deletion from a UI button click/activation. However, if you want this to fire off based on some other key/button on some device, use Rewired's Action system like you would for handling any other input. Create an Action for clearing the binding, assign that to some Keyboard, Mouse, or Joystick Map, and then to a Player. Read the input from the Player and fire off the deletion.

    There is documentation on Managing Controller Maps at Runtime here.
     
  36. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,833
    If you're looking for information on how to hard-code inputs to controller elements instead of using the Actions system, you'll find that here.

    Code (csharp):
    1. if(ReInput.controllers.Mouse.GetButtonDown(0)) Debug.Log("Left Button Clicked");
    2. if(ReInput.controllers.Keyboard.GetKeyDown(KeyCode.Delete)) Debug.Log("Delete Pressed");
     
  37. minad2017

    minad2017

    Joined:
    Dec 1, 2016
    Posts:
    9
    hi,i have a question about the controller mapper.
    Currently I am testing Rewired in a trial version.
    I confirmed the operation of the controller mapper and found that the keyboard setting was not displayed and the problem was hit.
    name of the set key is not displayed in the UI.
    Mouse and joystick are displayed without problems.
    I tried it with Unity 2017.2 and 2018.1 but the same symptoms were seen.
    Is there a solution?
     

    Attached Files:

  38. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,449
    Have you tried one of the Control Mapper demo scenes?

    I just tried the Rewired example and it worked as expected. The demo is located here for reference.

    Rewired\Extras\ControlMapper\Examples\ControlMapperDemo\ControlMapperDemo_1PlayerSimple.unity

    NOTE: This is my system setup
    Windows: 8.1 PRO (64-bit)
    Unity: Unity 2017.2 (Windows 64-bit)
    Rewired: 1.1.14.1.Unity 2017

    ====
    What version of the Rewired Trial are you using?
    What operating system are you using?
     
    Last edited: May 17, 2018
  39. minad2017

    minad2017

    Joined:
    Dec 1, 2016
    Posts:
    9
    I tried "ControlMapperDemo_1PlayerSimple" but the same symptoms were seen.
    The version of Rewired that I am using is "1.1.14.0.U2018 (Trial Version)".
    Windows10(64bit)
    Unity2017.2.0f3

    "1.1.14.2.U2017 (Trial Version)" a it worked without problem. It worked without problems with Unity 2017, 2018.
    Apparently it seems to be a bug in Rewired U2018 version.
     
  40. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,833
    Update to the current version of Rewired. This was a bug in 1.1.13.0.

    1.1.14.1:

    Bug Fixes:
    - Fixed issue in Gamepad Template causing L/R triggers to map incorrectly when bound to individual poles of an Axis-type Action on some gamepads introduced in 1.1.13.0.
    - Fixed issue ActionElementMap.elementIdentifierName on Keyboard Maps returning null introduced in 1.1.13.0.
     
  41. zornor90

    zornor90

    Joined:
    Sep 16, 2015
    Posts:
    169
    Hey, excited that we can make the input manager a prefab! When I try to create a rewired input manager, either through the Create menu or the Rewired window, it gives this error:
    upload_2018-5-18_11-34-43.png

    And then my prefab is empty:
    upload_2018-5-18_11-34-55.png

    Any ideas? I'm using 2017.4.2
     
  42. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,833
    It's not going to work. Exact same code works in Unity 4.x and 5.x. I'm going to have to change the code to make this function work in Unity 2017.
     
  43. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,833
    Rewired 1.1.4.2 is now available on the Unity Asset Store.

    Rewired 1.1.4.3 is now available for registered users to download immediately. If you'd like to register to receive early access to updates, contact me here.

    1.1.14.3:

    Changes:
    - Updated SDL2 Windows library to version 2.0.8.

    Bug Fixes:
    - Create Rewired Input Manager (Prefab) no longer throws an exception in Unity 2017+.

    1.1.14.2:

    Changes:
    - Rewired Editor: Appended the word "Template" to Controller Templates in the joystick list for clarity.
    - Some included dev tools now use Unity UI to display information on-screen.
    - Added system to allow for Android version-dependent controller mappings.

    Controller Definitions:
    - Sony DualShock 4, Android: Added additional product name matching variations for wired mode connections in some versions of Android.
    - Sony DualShock 4, Android: Added variant for Android Oreo+.
     
  44. vivalavida

    vivalavida

    Joined:
    Feb 26, 2014
    Posts:
    85
    Hi @guavaman ,
    Is there a way to get values of 'half- axis'?

    I have a car whose speed(forward and backward) is being controlled by just vertical axis.
    I have mapped a Logitech racing wheel's accelerator and brake
    to contribute positively and and negatively to the vertical axis.

    Is there a way to know if both are being pressed down at the same time?

    Alternatively, I could set up two different axes, but if I'm able to get positive and negative contributions it'll make life easier.

    Thanks.

    Edit: I was hoping/assuming 'Positive Name' and 'Negative Name' under Action properties would give these values
     
  45. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    395
    You can use GetButtonDown(axis) and GetNegativeButtonDown(axis)

    http://guavaman.com/projects/rewired/docs/HowTos.html#get-input-polling-player
     
    guavaman likes this.
  46. vivalavida

    vivalavida

    Joined:
    Feb 26, 2014
    Posts:
    85
    Sweet, had no clue about this,
    ... is it possible to get the amount the axis is pressed?
    Mainly since I'm using the racing wheel accelerator and brake, it'll feel more natural.

    For now I've created a duplicate for the map elements(ie my inputs) and mapped them to two new actions.
    but I'll have to manually duplicate all my inputs..

    Anyway, thanks so much.
     
  47. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    395
    Would have to defer to @guavaman on that one, as I’m not sure how Rewired deals with both the negative and positive sides of an axis being pressed at once. Have you tried polling for the Axis value while pressing both buttons? What does it output? I presume it just gives you the combined value. Not sure if you can query individual contributions.
     
    guavaman likes this.
  48. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,833
    I don't understand what advantage there would be to this approach.
    • GetAxis returns a single floating point value.
    • If you map two different elements to each pole of an Action, the will both contribute to the Actions's total value.
    • The value of the Axis is calculated from all component elements that are mapped.
    • Axis values are cumulative if the source is a Relative axis.
    • If you map two physical axes to each side of an Axis-type Action and press both fully at the same time, they will cancel each other out and you will get a result of 0.
    You cannot query only what is mapped to the individual poles Action and ignore other contributors on the other pole of the Action. The Axis value of the Action is a single floating point value calculated from all contributing sources. Sources mapped to either pole contribute to the total value.

    So ultimately, what you want to do is this:

    Accelerator = Speed +
    Brake = Speed -

    Be able to know:
    • Only the Accelerator part of this Axis without the Brake negation applied.
    • Only the Brake part of this Axis without the Accelerator applied.
    • The combined Accelerator + Brake value.
    No. You can't do that. The only way you can do this is with 2 separate Actions that you combine yourself after the fact to determine the speed. This is the right approach to the problem. See below.

    So you can do something like show a brake light when the brakes are pressed but still handle this as a single Speed Action?

    This is the wrong approach to your problem. The Action system exists so you can assign user-intent to input. You cannot combine your accelerator and brake into a single Speed Action and maintain the individual intents of Accelerate and Brake. Using separate Actions allows you to know the intent of the user to Accelerate and/or Brake at any time, combine and them into your result. You have far more control using this approach because you can decide how much the brakes negate the acceleration value -- maybe the brakes are going out and they're not working well so they don't slow the car down at the same rate as the accelerator increases it. Maybe you want slamming the brakes while accelerating to start a drift/slide.

    Avoid trying to use Rewired to determine things that should be handled by your game code. Rewired should be used strictly for getting input to know the intent of the user. It should not be used to push input directly into in-game results. It should not be used to determine a character's inertia, determine whether your player is allowed to jump or fire (permissions), set speeds of objects directly by increasing input sensitivity, or other such game-related concepts. These are all incorrect uses of the input system. Keep input separate from the interpretation and use of that input and you will have much more control of what is happening. This topic in the FAQ addresses some of this.
     
    Last edited: May 20, 2018
    vivalavida likes this.
  49. vivalavida

    vivalavida

    Joined:
    Feb 26, 2014
    Posts:
    85

    I agree wholly with what you've said,
    However, In my case I purely needed the values for presentation purposes, without using it inside my 'game-logic'.

    I'm using unity's standard asset car, which moves purely based on horizontal and vertical axes, I didn't want to tweak around that code, having access to the values 'half-axes' (computed from all sources) would have been nice to implement the visual feedback (ie the accelerator and brake movement on the 3D model).

    For now I've had to duplicate all inputs and make them contribute to additional actions that only aid in visual feedback.
    I believe having access to half-axes might be helpful in certain simple scenarios(I could also be 100% wrong).

    Also, could you please explain the purpose of negative buttons?(I am currently assuming that they are exactly what I'm looking for minus the face that they give only bool values)

    On a parting note, I really appreciate rewired, it has made life a whole lot easier especially since we work with so many platforms. And appreciate time time and effort put in to reply to all forum posts.
    Thanks @guavaman
     
  50. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,833
    Thanks for the explanation.

    I think the core issue here is that you're using a Unity car script that wasn't designed to allow you to do what you're trying to do. You want to use a single Speed Action because Unity's script only takes a single floating point value to control its movement speed. So that limits you to a single floating point value. However, at the same time you want to use two separate values so you can show users on-screen whether the accelerator, brake, or both are being pressed. These two things are at odds. If you were using just the Unity script and Unity input as they set it up, you couldn't do it.

    You can easily do what you want using 2 Actions and a bit of code:

    Code (csharp):
    1. float accelerate = player.GetAxis("accelerate");
    2. float brake = player.GetAxis("brake");
    3. float speed = accelerate - brake;
    4. // Pass speed to the Unity script
    5. // Use accelerate and brake to show your UI
    This is not something I will be adding. The use cases are so minimal and it messes with the concepts of Actions and that an Axis is a single floating point value. It essentially duplicates the functionality of 2 separate Actions while trying to keep them on the same single Action, really for no real reason except to live within the limitations of the Unity script which wasn't designed to handle 2 values while still being able to access the 2 values separately.

    In the case of only needing half the value of an axis, of course you can easily do it using the code:

    Code (csharp):
    1. float value = player.GetAxis(actionid);
    2. if(value < 0) // do something negative
    3. else if(value > 0) // do something positive
    But this does not fulfill the requirement that the contributing positive and negative values be separate and do not negate each other in the case of pressing both at the same time, essentially turning the Axis into two separate virtual values instead of a single value. That's exactly what creating two separate Actions would achieve and is much more straightforward logically.

    They're explained here:
    http://guavaman.com/projects/rewired/docs/HowTos.html#button-press-types

    Negative Buttons:

    Each of the methods above also has a corresponding Negative Button method which is named the same except with NegativeButton in place of Button. These serve to allow you to use axes as buttons and will trigger when the negative side of the axis is activated while the standard Button version will trigger only when the positive side of the axis is activated. However, it is usually easier to just map each pole of the axis to a seperate Action (split axis) so that each Action can just be queried with GetButton.

    ---------

    Negative buttons are not what you're looking for either. In your scenario, it would not be able to tell you whether the brake is being pressed at the same time as the accelerator either because the "button" state is calculated by the total value of the Action's axis. Brake + Accelerator = 0, total value = 0, Button value = False, Negative Button = False.

    Thanks!
     
    Last edited: May 21, 2018
    vivalavida likes this.