Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Rewired - Advanced Input for Unity

Discussion in 'Assets and Asset Store' started by guavaman, Sep 25, 2014.

  1. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,852
    Awesome! Thanks for the update. I'm glad it was able to help you. If you use Native input on OSX, I recommend you update to 1.1.5.1 on the website because of a bug that affects Xbox 360 controllers. Let me know if you need the download URL if you want it.
     
  2. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,454
    Glad that makes your code cleaner. You should grab 1.1.5.0 which is the latest version of Rewired. The Unity asset store still only has Rewired 1.1.4.1 currently.
     
  3. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,454
    I was not expecting you to map the racing wheel template. :) I will send it to you when I have finished mapping.

    There is something mapped for the HOTAS template but it appears to have some issues. I need to dig into that some more for testing.
     
    guavaman likes this.
  4. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,454
    The daily Rewired updates keep on coming. :cool: Already at Rewired 1.1.5.1 wow.
     
  5. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,852
    It's because of bugs introduced in 1.1.4.0 due to some significant changes that had to be made for Unity 2017 and some other threading optimizations that ended up affecting different platforms differently Everything is stable again on 1.1.5.1. I don't think there will be any more updates related to these issues. I just wish the Asset Store would approve 1.1.4.2 so I could upload 1.1.5.1.
     
    Last edited: Jul 31, 2017
    Dwight_Everhart likes this.
  6. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,852
    1.1.4.2 was approved by the Asset Store so I've uploaded 1.1.5.1. Hopefully it gets approved quickly.
     
  7. broesby

    broesby

    Joined:
    Oct 14, 2012
    Posts:
    112
    Any plans on supporting the Gear VR controller. Or is it already supported? Couldn't figure it out.. ;-)
     
  8. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,852
    There are no plans to support it. As a general rule, Rewired does not implement and wrap 3rd party SDK's. Gear VR is used through the Oculus API. All controllers that require an SDK can only be supported through Custom Controllers. Even if support were added for it, motion control would just be exposed through a Controller Extension which wouldn't really be anything more than wrapping the Oculus API and exposing the same values. Motion controls are generally not well-suited to the Player-Action paradigm anyway unless you write a script for a Custom Controller and watch to gestures making them trigger buttons on a Custom Controller.
     
    Last edited: Aug 1, 2017
  9. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,852
    Dwight_Everhart likes this.
  10. Riderfan

    Riderfan

    Joined:
    Jan 10, 2013
    Posts:
    484
    Hi there.

    I've poked around the documentation and I'm fairly sure the answer to this question is No, but need to ask anyway.

    Is there a way to make ReInput.controllers.GetControllers(ControllerType.Joystick); return just standard game controllers?

    I ask because we're getting customers with oddball input devices, like guitars, claiming that those devices are interfereing with the normal controllers.

    Our suggestion, un-plug those devices, is apparently (based on the responses to that suggestion) quite offensive as some other titles can apparently deal with these devices being plugged in and connected.

    thanks
     
  11. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,852
    No. A guitar controller is a standard game controller. There is no distinction. Rewired only considers HID devices that report themselves as Gamepad or Joystick. And assuming Windows with Use XInput enabled, XInput devices.

    There would be no possible way to ignore these devices short of creating a blacklist of devices to ignore.

    What does interfering mean? If they're saying it takes the place of their normal controller, then you have joystick auto-assignment Max Joysticks Per Player set to 1 joystick:
    http://guavaman.com/projects/rewired/docs/Controllers.html#joystick-auto-assignment

    Comparing other games to Rewired is not helpful because a huge number of games on Windows ONLY support XInput devices. If you want to only support XInput devices on Windows, change the primary input source to XInput. This will disable Raw Input / Direct Input and only support the limited set of XInput gamepads. You will lose support for a tremendous number of joysticks, flight controllers, and racing wheels.
     
  12. Riderfan

    Riderfan

    Joined:
    Jan 10, 2013
    Posts:
    484
    This is an XBox title and we have to manage input devices slightly differently.

    The problem is that some players have one standard controller and one guitar. The guitar, when active, is reporting itself as a controller that can be used by a second player. - which I suppose it could be, but it would be fairly awkward.

    The suggestion we made was to simply unplug the guitar dongle, but apparently that was a bad suggestion.
     
  13. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,852
    Rewired on Xbox One gets the list of controllers from UnityEngine.Input.GetJoystickNames() which only returns a string name. It's possible there's some kind of controller type available through the Xbox One SDK, but this information isn't exposed through UnityEngine.Input or the UnityEngine.XboxOne classes. It's possible it is exposed in the string name returned by GetJoystickNames, but there's no code in Rewired to ignore devices with specific strings. If you want to do it yourself, check the Joystick.hardwareName property. That's the only information available on the device.
     
  14. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,454
    guavaman likes this.
  15. SVC-Games

    SVC-Games

    Joined:
    May 21, 2013
    Posts:
    110
    I've just upgraded to Unity 2007.1 p2, and suddenly "Ignore Input When App Not In Focus" doesn't seem to work when disabled. I use it disabled so I can test frame by frame inputs, but now no matter if it's disabled, it just behaves as if it was enabled.

    Could you please into it? I upgraded to the latest version of ReWired but I still have that problem :p
     
  16. Shredsauce

    Shredsauce

    Joined:
    Apr 4, 2016
    Posts:
    23
    How do I get the action id from an action name at runtime?
     
  17. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,852
    • What platform?
    • Editor or build?
    • What device type? Mouse and keyboard always ignore input in the editor.
     
  18. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,852
    Last edited: Aug 5, 2017
  19. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,852
    After doing a bunch of testing, I've discovered it's nothing to do with Unity 2017.1p2. It's because in 1.1.4.0 I added a check of Application.runInBackground as an additional factor in determining whether input should be allowed. If the application is not running in the background, no Unity scripts are updating anyway. Problem is, I've discovered that Unity completely ignores this setting in the editor, merrily running in the background regardless of what you set it to. Builds respect it. So Unity reports Application.runInBackground = false in the editor because you have it set to that (even though it's actually updating) so Rewired blocks input. Change your setting in the Player settings of Unity and it will start working again.

    runinbackground.png

    The only way this can just work automatically again is if I make it ignore this setting in the editor. Everything is just a bunch of trial and error when dealing with the Unity editor. In my view, this a Unity bug because it really should report the actual value of Application.runInBackground = true when queried in the editor because it runs in the background, not just whatever the user has it set to.
     
    Last edited: Aug 5, 2017
    Dwight_Everhart likes this.
  20. SVC-Games

    SVC-Games

    Joined:
    May 21, 2013
    Posts:
    110
    Wow, thanks for the in-depth reply. I'll try as soon as I can and report the results. I agree that it looks like something Unity is doing wrong, nice catch!
     
  21. Vapid-Linus

    Vapid-Linus

    Joined:
    Aug 6, 2013
    Posts:
    58
    If I want to use the Switch's JoyCons on PC (I can connect them with bluetooth), are their Joystick Maps supported or PC or do I need to treat them as unknown controllers?

    And is it possible to access their gyro on PC?
     
    Last edited: Aug 7, 2017
  22. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,852
    They are on the Supported Controllers page which shows which platforms they work on:
    http://guavaman.com/projects/rewired/docs/SupportedControllers.html

    Mapping the Dual Analog Gamepad Template works and so does mapping the individual controllers.

    No. On non-Switch platforms, the analog stick also acts as a hat. (values of -1, 0, and +1 only). Also no vibration.
     
  23. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,852
    @makeshiftwings @Morchen

    Unity has responded to the bug report I made about the dynamic assembly loading bug in .NET 4.6 experimental backend. Here's their response:

     
    Dwight_Everhart likes this.
  24. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,300
    Sweet. I got an email saying they were trying to get the fix into 2017.1.p4.

    For now I've turned off native input in the Rewired manager and it's working, but I'd really prefer to be able to turn it back on, so hopefully p4 will be out soon.
     
  25. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,852
    Okay, good. I was wondering what they meant by the fix will also be available in 2017.1 releases and that explains it.
     
  26. commodore

    commodore

    Joined:
    May 30, 2012
    Posts:
    36
    Is there anything special I have to do to get a dualshock 3 controller working in Firefox on a Mac? It used to work with Unity's input and cInput.

    Edit:

    It seems to Recognize that there is a controller. However, the following code prints two different things

    Code (CSharp):
    1.      foreach(Joystick joystick in ReInput.controllers.Joysticks) {
    2.          Debug.Log(joystick.name);
    3.      }
    In the editor: Sony DualShock 3

    In the WebGL build: PS3 GamePad

    Edit again: Reading through the thread it looks like I'm going to have to remap the controllers manually
     
    Last edited: Aug 8, 2017
  27. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,852
    The documentation tells you which controllers work by automatic recognition:
    http://guavaman.com/projects/rewired/docs/SupportedControllers.html#webgl

    Dual Shock 3 is not a recognized controller on WebGL and must be mapped manually.
     
  28. Vapid-Linus

    Vapid-Linus

    Joined:
    Aug 6, 2013
    Posts:
    58
    Can the Rock Band 4's PS4 guitar "Stratocaster"'s whammy bar and tilt/gyro be accessed using Raw Input? I do not believe it would be possible with XInput but am unsure about Raw Input or Direct Input.

    I have it connected to Windows using Bluetooth and Windows's game controller settings can only see the buttons, not the whammy bar or tilt input though.
     
  29. Shredsauce

    Shredsauce

    Joined:
    Apr 4, 2016
    Posts:
    23
    Can Move Right and Move Left be disabled on the Controller side the same way Horizontal is disabled for Keyboard?
     

    Attached Files:

  30. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,852
    I doubt it. I bought the Rock Band Xbox One guitar and it didn't work correctly on either Raw or XInput. The HID data is not there. Buttons wouldn't work depending on what was being held down and the whammy bar didn't work at all. It would need a Windows driver to work correctly.
     
  31. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,852
    No you cannot make those fields greyed out. The only reason the keyboard Horizontal field is greyed out is that it's a full-axis Action field on a button which is not possible to map. You can only make them disappear. The inspector options:
    http://guavaman.com/projects/rewired/docs/ControlMapper.html#inspector-input-field-options

    Note the very important warnings.
     
  32. neshius108

    neshius108

    Joined:
    Nov 19, 2015
    Posts:
    86
    Hello @guavaman,

    First of all: great stuff! I have just had the chance to mess around with the tool and I have to say it is amazing!
    I have a question: is it possible to retrieve the KeyCode/Joystick Button/Etc. to which a specific action is mapped to?

    Say, by default, "Jump" is mapped to <Space>. All great and good.
    But what if the player changes it to <Ctrl>. How can I see, at runtime, which one is mapped to that specific action?

    The idea is that I want to have messages precisely indicating the current key to press (Ctrl) and not the default one that is currently not valid anymore (Space). Is this kind of thing supported? (please.please.please.please!)
     
  33. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,454
    @guavaman

    Somewhat off topic ... did you see the announcement about Atari's Tempest 4000? I am curious what controllers will be supported. On the Atari Jaguar it did have support for a rotary controller but it was hidden. It would be great if it supported the Toronado spinner ( http://tornadospinner.com/ ). There are some nice screen shots of the different control panels that customers have built with the spinner. ( http://tornadospinner.com/gallery/).

    The Atari Tempest 4000 announcement for reference:

    https://hypedgamer.com/atari-jeff-minter-announce-tempest-4000/
     
  34. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,852
    This is covered in the How To's documentation:
    http://guavaman.com/projects/rewired/docs/HowTos.html#get-element-name-for-action
    http://guavaman.com/projects/rewired/docs/HowTos.html#display-glyph-for-action
    http://guavaman.com/projects/rewired/docs/HowTos.html#display-glyph-for-active-elements

    You won't be able to use Rewired well without understanding the Controller Map system:
    http://guavaman.com/projects/rewired/docs/ControllerMaps.html

    There are included examples that show runtime remapping of controls which also show what elements are mapped to Actions:
    http://guavaman.com/projects/rewired/docs/ControlMapper.html
    http://guavaman.com/projects/rewired/docs/Examples.html#simple-control-remapping
    http://guavaman.com/projects/rewired/docs/Examples.html#control-remapping-1
     
    Last edited: Aug 13, 2017
  35. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,852
    I hadn't heard they were making another Tempest. That's great news. I'm sure the controller types supported would depend on the platforms it's being released on. I did notice the Tornado Spinner says it's compatible with Android. I imagine it probably returns relative axis data as a mouse. If that's the case, as long as they programmed it to work with a mouse and read the axes as delta values instead of the absolute position, the spinner should just automatically work.

    Tempest 2000 was definitely a must-have on the Atari Jaguar. Thanks for sharing!
     
  36. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,852
    Is anyone here using an Oculus Rift with Rewired on Raw Input mode? With Rewired enabled, do you get anything for headtracking via either:
    1. InputTracking.GetLocalRotation().....
    2. OVRPlugin.GetNodePose(OVRPlugin.Node.EyeCenter, sp).ToOVRPose().orientation
    If not, does it work in Direct Input mode?

    I already know the almost certain cause if it doesn't work with Raw Input enabled, which would be a serious limitation of the Windows RawInput API.

    Edit: Oculus Rift ordered...

    Update: There is no issue with Oculus Rift and Rewired. Please see this post for details.
     
    Last edited: Aug 22, 2017
  37. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,454
    @guavaman,

    I found this article on how to recalibrate some of the Saitek gear (e.g. X-55 Hotas, etc.) by modifying the registry. This is one of the rare times I have seen an article from a vendor.

    http://support.logitech.com/en_us/article/Recalibrate-controller-axes-RegEdit

    In addition they are beginning to move all of the saitek drivers/software from the old Saitek site to the Logitech site. It will be nice to have everything in one place when they are done.

    https://community.logitech.com/s/question/0D55A000071vphXSAQ/x55-rhino-support-
     
    guavaman likes this.
  38. Selzier

    Selzier

    Joined:
    Sep 23, 2014
    Posts:
    611
    I'm an asset store publisher and currently building a Platformer Pack. I want my asset to work with Rewired for input, are there some general guidelines how I should script my Input class so that it will easily connect with Rewired?
     
  39. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,852
    Hi,

    There is nothing published on this.

    My general recommendation to anyone who asks is to structure your system to allow for modular input in a way that is super easy for users to switch input sources without requiring them to swap out components on all their game objects.

    One way to achieve this is to create an input manager singleton that can be overridden by input assets.

    Code (csharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. namespace SomeNamespace {
    6.  
    7.     public interface IInputManager {
    8.         bool GetButton(int playerId, InputAction action);
    9.         bool GetButtonDown(int playerId, InputAction action);
    10.         bool GetButtonUp(int playerId, InputAction action);
    11.         float GetAxis(int playerId, InputAction action);
    12.     }
    13.  
    14.     public abstract class InputManager : MonoBehaviour, IInputManager {
    15.  
    16.         private static IInputManager _instance;
    17.         public static IInputManager instance { get { return _instance; } }
    18.  
    19.         public static void SetInstance(IInputManager instance) {
    20.             _instance = instance;
    21.         }
    22.  
    23.         protected abstract void Awake();
    24.         public abstract bool GetButton(int playerId, InputAction action);
    25.         public abstract bool GetButtonDown(int playerId, InputAction action);
    26.         public abstract bool GetButtonUp(int playerId, InputAction action);
    27.         public abstract float GetAxis(int playerId, InputAction action);
    28.     }
    29. }
    The exact structure of this base class depends on your package's particular input needs. The base implementation would obviously use UnityEngine.Input. This is overridable by 3rd party assets by creating their own implementation and adding it to a component in the scene. Because the Unity version checks whether the instance is null before assigning it, it can be overridden by the 3rd party asset manager at any time without having to remove the Unity input manager component or even worrying about the script execution order. The user simply adds a prefab/game object to the scene and the input source changes to their input system of choice.

    A basic example of a Unity input manager implementation:

    Code (csharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. namespace SomeNamespace {
    7.  
    8.     public class UnityInputManager : InputManager {
    9.  
    10.         [SerializeField]
    11.         protected string _playerAxisPrefix = "";
    12.         [SerializeField]
    13.         protected int _maxNumberOfPlayers = 1;
    14.  
    15.         [Header("Unity Axis Mappings")]
    16.         [SerializeField]
    17.         protected string _jumpAxis = "Jump";
    18.         [SerializeField]
    19.         protected string _attackAxis = "Fire1";
    20.         [SerializeField]
    21.         protected string _subAttackAxis = "Fire2";
    22.         [SerializeField]
    23.         protected string _dashAxis = "Fire3";
    24.         [SerializeField]
    25.         protected string _runAxis = "Run";
    26.         [SerializeField]
    27.         protected string _horizontalAxis = "Horizontal";
    28.         [SerializeField]
    29.         protected string _verticalAxis = "Vertical";
    30.         [SerializeField]
    31.         protected string _pauseAxis = "Submit";
    32.  
    33.         private Dictionary<int, string>[] _actions;
    34.  
    35.         protected override void Awake() {
    36.             if(instance != null) return; // do not override existing input sources
    37.  
    38.             SetInstance(this); // set this as the singleton instance
    39.  
    40.             // Set up Actions dictionary for each player
    41.             _actions = new Dictionary<int, string>[_maxNumberOfPlayers];
    42.             for(int i = 0; i < _maxNumberOfPlayers; i++) {
    43.                 Dictionary<int, string> playerActions = new Dictionary<int, string>();
    44.                 _actions[i] = playerActions;
    45.                 string prefix = !string.IsNullOrEmpty(_playerAxisPrefix) ? _playerAxisPrefix + i : string.Empty;
    46.                 AddAction(InputAction.Jump, prefix + _jumpAxis, playerActions);
    47.                 AddAction(InputAction.Attack, prefix + _attackAxis, playerActions);
    48.                 AddAction(InputAction.SubAttack, prefix + _subAttackAxis, playerActions);
    49.                 AddAction(InputAction.Dash, prefix + _dashAxis, playerActions);
    50.                 AddAction(InputAction.Run, prefix + _runAxis, playerActions);
    51.                 AddAction(InputAction.MoveHorizontal, prefix + _horizontalAxis, playerActions);
    52.                 AddAction(InputAction.MoveVertical, prefix + _verticalAxis, playerActions);
    53.                 AddAction(InputAction.Pause, prefix + _pauseAxis, playerActions);
    54.             }
    55.         }
    56.  
    57.         private static void AddAction(InputAction action, string actionName, Dictionary<int, string> actions) {
    58.             if(string.IsNullOrEmpty(actionName)) return;
    59.             actions.Add((int)action, actionName);
    60.         }
    61.  
    62.         public override bool GetButton(int playerId, InputAction action) {
    63.             return Input.GetButton(_actions[playerId][(int)action]);
    64.         }
    65.  
    66.         public override bool GetButtonDown(int playerId, InputAction action) {
    67.             return Input.GetButtonDown(_actions[playerId][(int)action]);
    68.         }
    69.  
    70.         public override bool GetButtonUp(int playerId, InputAction action) {
    71.             return Input.GetButtonUp(_actions[playerId][(int)action]);
    72.         }
    73.  
    74.         public override float GetAxis(int playerId, InputAction action) {
    75.             return Input.GetAxis(_actions[playerId][(int)action]);
    76.         }
    77.     }
    78. }
    79.  
    Note that the above examples use an enum for game-side Actions as this example was written for a system that has a static set of inputs. You could easily use strings for more versatility.

    Of course this is just one idea on an implementation. There really are almost limitless ways you could approach this like using interfaces, virtual controllers, inversion of control, etc. But the goal of all approaches is pluggable, source-agnostic input handling.
     
    Last edited: Aug 22, 2017
    Selzier likes this.
  40. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,852
    Following up on this issue:

    I bought an Oculus Rift and did through testing using the latest Oculus tools for Unity. I have found zero issues in any version of Unity tested using Raw Input, Direct Input, or XInput. At no time was input tracking lost in the editor or builds.

    The original user who reported this issue has said that he reinstalled Windows for other reasons and the issue no longer affects him. There is no way I can reproduce this so no way to know how or why it was happening. I can only guess, but perhaps old Oculus driver files/plugins were present on his system causing this.

    At this time, there is no issue with using Oculus Rift and Rewired.
     
  41. MrCool92

    MrCool92

    Joined:
    Jul 13, 2015
    Posts:
    15
    Hi!

    I don't know if it's a bug but when I assign controller from player to system, system gets up input and processes it immediately.

    For example.. On player selection menu I have controller assignment through system player. Action cancel drops player if he's joined, meaning his controller now belongs to system player.. but same action on system player will return you to main menu.

    I'm using input event delegates. Both actions invoke even when system player had no controller in same frame. I've tried delaying controller assignment for a frame-two no luck.

    Only solution I came up with is to delay input so it cannot process events.

    Code (CSharp):
    1. private void SystemPlayerBackEvent(InputActionEventData eventData)
    2.     {
    3.         if (ReinputExtensions.SystemPlayer.InputAllowed())
    4.             MainCanvas.Instance.PreviousMenu();
    5.     }
    where InputAllowed is extension for Rewired.Player

    Code (CSharp):
    1. public static bool InputAllowed(this RPlayer rp)
    2.     {
    3.         float time;
    4.         if (_blockInputEndTimes.TryGetValue(rp.id, out time))
    5.         {
    6.             if (time > Time.unscaledTime)
    7.                 return false;
    8.             return true;
    9.         }
    10.         _blockInputEndTimes.Add(rp.id, 0f);
    11.         return true;
    12.     }
    13.  
    14.     public static void DelayInput(this RPlayer rp)
    15.     {
    16.         float timeOut = Time.unscaledTime + _blockInputTimeout;
    17.         if (_blockInputEndTimes.ContainsKey(rp.id))
    18.         {
    19.             _blockInputEndTimes[rp.id] = timeOut;
    20.         }
    21.         else
    22.         {
    23.             _blockInputEndTimes.Add(rp.id, timeOut);
    24.         }
    25.     }
    I hope there is a better solution to this.

    Thx!

    Oh! Forgot to mention that I'm using v1.1.1.0.U5
     
    Last edited: Aug 23, 2017
  42. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,852
    This is not a bug. When you assign your controller to a Player and are holding the same button down that has an Action assigned to it in the other Player, the Action will have a value of TRUE. When you release the button, a Button Up event will occur because the button was released.

    Rewired is an Action-based system. An Action is essentially a virtual controller element that is an combination of an undetermined number of underlying input sources whether physical button, physical axis, or virtual element. Virtual "button" events of Down, Up, and On are calculated based on the previous frame's On value. If On in previous frame and not On in current frame, an Up event is generated. There is no direct relationship to the underlying physical hardware. What you are expecting to happen is for it to ignore the value it is receiving from the physical button until the next time you press it. This isn't the way it works and it would be extremely problematic and potentially impossible in some cases to make it work like this because of the input-source agnostic nature. For example, think of the case of toggle/switch buttons such as on many flight sticks (mode selectors). If it had to ignore any existing button values at the time of assignment until they zero out, these buttons could never work. Axes also would complicate things, especially triggers on unknown controllers where they return -1 for a rest value.

    Rewired has special handling to ignore the ButtonDOWN event on the first frame when the first Action Element Map that binds a particular Action for a Player is first enabled. This was done specifically for these cases where a Controller Map is enabled or a controller is assigned using a button that also maps to another Action on the new Controller Map / controller. It was possible to come up with a solution (albeit rather convoluted) to make this happen, the same is not true for the UP event, nor is it true for the ON state. Note that the DOWN event is only ignored on the very first frame any Action Element Map that maps that Action is enabled. That means if you have another Controller Map for any controller in that Player that already maps the Action and is already enabled, for example a Keyboard Map, the DOWN event will not be silenced when you assign the joystick or enable the Joystick Map.

    You don't state which event you are watching for. Down, up, or on? (ButtonJustPressed, ButtonJustReleased, ButtonPressed)

    This would definitely work if you are watching for an Up/Down event. They only stay on for a single frame unless you've changed the Button Down Buffer value in the Input Behavior assigned to the Action in question. A single frame skip would work. If you're watching for the ON event (ButtonPressed), it will always return true if the button is held.

    The ways to handle this:
    1. Check GetButtonUp/ButtonJustReleased to do your controller assignment and change menu modes instead of Down.
    2. Add an input allowed delay / frame skip as you have done.
     
    Last edited: Aug 23, 2017
  43. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,852
    Actually, it doesn't work, it just looks like it does. An exception is thrown because of an unrelated issue involving reflection in .NET 4.6 and the exception is silently swallowed forcing Rewired to run in UnityEngine.Input mode instead. No native input works with the 4.6 .NET backend. The fact that 1.1.3.0 looks like it worked was just a fluke due to the unrelated exception.

    This is addressed in the Known Issues section of the documentation:
    http://guavaman.com/projects/rewired/docs/KnownIssues.html#unity-2011-dot-net-46-editor-errors

    Editor corruption in Unity 2017.1 when using .NET 4.6 experimental backend
    The .NET 4.6 experimental backend contains a major bug that affects Rewired's ability to run in the editor. The 2nd time you press Play in the editor, it will throw thousands of exceptions and cause the editor to become corrupt until quit and restart. This bug has been reported to Unity and they have acknowledged it. Until this bug is fixed, Rewired is not compatible with the .NET 4.6 experimental backend. See the following forum posts for more details about the issue.
    The only workaround is to disable native input by setting the input source for the editor platform to Unity in the Rewired Input Manager -> Settings page. By doing this, you will lose access to all the special features and benefits native input provides.

    ------------

    Unity has already reportedly fixed the issue in 2017.1.p4 as noted here:
    https://forum.unity3d.com/threads/rewired-advanced-input-for-unity.270693/page-68#post-3175079
     
    Last edited: Aug 24, 2017
  44. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,852
    Rewired 1.1.6.0 is now available to registered users. Please contact me here to get early access to Rewired updates. The update will available on the Unity Asset Store when it is approved.

    As always, make sure to read Updating Rewired before updating.

    1.1.6.0:

    Changes:
    - Changed Sony DualShock 4 controller display name and element identifier names on PS4 platform to conform to Sony's required standards.
    - Added Positive Name and Negative Name fields to Controller Element Identifier in Hardware Joystick Map editor.
    - Changed mouse axis positive/negative axis names to Mouse Left, Mouse Right, etc.
    - Updated Control Mapper to use positive/negative name fields.
    - Added FirstNonZeroValue Custom Calculation type.
    - Added default UI controls to Corgi Engine integration.
    - Corgi Engine integration: Added inventory system integration.
    - Corgi Engine integration: Minimum required Unity version changed to Unity 5.6.3f1.
    - Special platform inspector settings for Rewired_Core.dll are now checked more often that just when the build platform is changed to account for installing Rewired and/or special platform plugins with the build target already set to a special platform that is not supported by the base Unity editor.

    New Controller Definitions:
    - Logitech MOMO Racing Wheel

    Modified Controller Definitions:
    - Sony DualShock 3: Added WebGL mappings for OSX and Linux.
    - Microsoft Xbox One: Added OSX Native mapping for Xbox One S controller firmware 3.1.1221.0.
    - Added positive/negative axis names to most recognized controller axes.
    - Changed CH CombatStick "Dial" name to "Throttle."
    - Changed CH FighterStick "Dial" name to "Throttle."
    - Changed Saitek Heavy Equipment panel "Stick Z (Blue)" name to "Stick Rotate (Blue)."
    - Changed Saitek Heavy Equipment panel "Stick Z (Red)" name to "Stick Rotate (Red)."
    - Changed Saitek X45 "Rudder" name to "Stick Rotate."
    - Changed Saitek X-56 Rhino Throttle "MiniStick X", "MiniStick Y", and "MiniStick Button" to "Mini Stick X", "Mini Stick Y", and "Mini Stick Button."
    - Changed Thrustmaster T.16000M "Slider" name to "Throttle."

    API Changes:
    - Added ControllerElementIdentifier.positiveName property.
    - Added ControllerElementIdentifier.negativeName property.
    - Added ControllerPollingInfo.controller property.
    - Added ControllerPollingInfo.player property.
    - Added ControllerPollingInfo.elementIdentifier property.

    Bug Fixes:
    - Disabling "Ignore Input When App Not In Focus" in the Rewired Input Manager works again in the Unity editor even when "Run Application in Background" is disabled in the Unity Player settings.
    - Fixed missing class and method exceptions thrown during build time on Windows 8.0 Store and 8.1 Universal platforms.
    - Windows Standalone, Raw Input: Fixed issue preventing Microsoft Xbox One controller from working when used with "Use XInput" disabled.
     
  45. MrCool92

    MrCool92

    Joined:
    Jul 13, 2015
    Posts:
    15
    Thanks for fast in-depth reply!

    Both delegates are ButtonJustPressed type and I did not change Button Down Buffer.

    So you are saying ButtonJustPressed will be ignored on freshly added controller only if maps were previously disabled and after assignment, they are enabled? Because the whole thing worked after that. I disabled all system maps, started coroutine with 2x null yield before controller assignment and then enabled system maps.

    I just want to be sure if that is the right process you were explaining, if I want to delay controller assignment.

    Anyway.. I thought ButtonJustPressed would work on its own regardless of map enable/disable state with just controller assignment delay...
     
  46. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    2,429
    FYI the fix for .NET 4.6 in 2017.1, isn't fixed in p4. Hit it today while using rewired for the first time.
     
  47. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,454
    This is a great Rewired update. Thanks for changing those element names. It will make it easier to work with in the flight controller template. The positive and negative name is also a welcome addition.
     
  48. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,852
    I misunderstood where you were putting this frame delay before. No, this would not work because the button is still held down in the frame where you finally make the assignment. Because an Action's Down state is calculated based on previous frame compared to current frame, no matter how long you delay the assignment, when you finally make it, if the button is still held down, it will generate a Down state.

    The key to making this work is to place the delay immediately AFTER Joystick assignment.

    For example:
    1. Press A to assign Joystick.
    2. Delay 1 frame.
    3. Press A to Fire.
    If you delay one frame after assigning the Joystick before you start processing Fire, the ButtonDown event will be skipped in your code and you won't shoot when assigning the joystick. This is probably the easiest solution apart from using ButtonUp instead of ButtonDown.

    Code (csharp):
    1. IEnumerator AssignJoystickCoroutine(Joystick joy) {
    2.     player.controllers.AddController(joy, true);
    3.     yield return null;
    4. }
    Edit: I just realized that this won't help because you are using input events. The above method would work fine for input polling since you would be delaying the next polling of GetButtonDown until the next frame. With events, you're not polling and the event will come in regardless. The only way to skip that would be to flag it in your code to ignore input for a frame and then resume.

    To behave the way you expect it to, the Action's button state really has to be tied directly to the physical button's state and not be a simulation. I do not know for sure if a change like this would be possible while also maintaining current functionality for all the different things handled by an Action (combining hardware/virtual buttons and axes from multiple controllers into axis values and buttons states, digital axis simulation, double click, timed press, pressure-sensitive buttons, treating mouse axes as buttons, etc.) I will look into the possibility.

    I wasn't advising you a process to take, I was just trying to explain how the ButtonDown exception works which was added to handle enabling controller maps on button press.

    Explanation of the ButtonDown exception special case. Skip the rest of this message if you're not interested in this because it may just add confusion and is not important to the use of Rewired. It is simply an explanation of the only special case for ButtonDown handling.

    The reason why the above worked for is that you disabled ALL the System Player controller maps and all Actions became idle (nothing enabled maps this Action in question). Therefore, when you assigned the controller, ButtonDown was silenced on the first frame that the Action in question was enabled.

    Based on this information, you must have some other Controller Map in this System Player which maps this Action that is already enabled at the time you assign the joystick.

    Take this example:

    Let's say the Action in question is "Fire." Let's also say the System Player

    System Player:
    |- Keyboard Map (enabled)
    |------ Fire

    Now assign a Joystick with this map by pressing the "Fire" button:
    |- Joystick Map
    |------ Fire

    Because there was an enabled Keyboard Map which binds Fire, you will get a ButtonDown event for Fire from the Joystick on the first frame you assign it.

    If instead, the Keyboard Map was disabled first, you would not get a Fire ButtonDown event from the Joystick on the first frame you assigned it because it's the only enabled map that binds the "Fire" Action in this Player.

    This "hack" was done to make things "just work" in the vast majority of cases where this ButtonDown issue caused a problem. The most common use case is enabling a Controller Map with a button press which also binds some Action on the Controller Map which is just being enabled. It does not work in all cases like yours where you have multiple bindings to the same Action in your Player.

    None of the above is to say that you should disable all the System Player maps before making your assignment. All this information is for is so you understand what specific case the ButtonDown event will be silenced, not to tell you to go through a process like this to assign a controller. I understand this is confusing and it's certainly not required information to know.
     
    Last edited: Aug 24, 2017
  49. Steve-Tack

    Steve-Tack

    Joined:
    Mar 12, 2013
    Posts:
    1,240
    Definitely not a big deal, but I'm curious why you did that. On the X45, there's a funky rudder control that's actually on the throttle and the flight stick doesn't actually have a stick rotate.
     
  50. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,852
    Oops! I looked up the stick and found an image with callouts but it wasn't clear. I'll revert it in the next update.