Search Unity

Rewired - Advanced Input for Unity

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

  1. yakandco

    yakandco

    Joined:
    Dec 3, 2014
    Posts:
    87
    Hi there, after upgrading to v1.1.40 I'm getting this warning when used in 2021.1.18 on mac:

    Rewired: The version of Rewired installed (1.1.40.0.U2020) was not designed for Unity 2021. Please install Rewired for Unity 2021.

    I tried completely removing Rewired first and and reinstalling fresh like the warning suggests but the warning still appears, any ideas? thanks.
     
  2. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,849
    This is a Unity issue, not specific to Rewired:
    https://guavaman.com/projects/rewired/docs/Troubleshooting.html#wrong-rewired-version-installed
     
  3. jason_yak

    jason_yak

    Joined:
    Aug 25, 2016
    Posts:
    411
  4. Hi_ImTemmy

    Hi_ImTemmy

    Joined:
    Jul 8, 2015
    Posts:
    127
    Hello there,

    This is just a fun question (not cruical at all). I found this gem of a controller recently, an original Xbox pad, and have a USB adapter for it. By default Windows 10 & Unity doesn't detect or know what to do with it when plugged in. There is however the XBCD driver which at least gets the controller working in Windows.

    Could this work with Unity and Rewired? Would installing XBCD be the first step or is the fun dream actually an impossible nightmare in disguise?

     
  5. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,509
    Installing the driver would be your first step. At least in theory if it works in windows it should work with unity and rewired. You should fire up Unity and Rewired and see what it sees.

    You are dependent on how good the windows driver is and who will be maintaining it long term. It seems fairly regularly Microsoft makes some changes to their USB driver that impacts other controllers so driver updates will be required. Based on what I see on that website the driver is not signed. That is seems like a big red flag long term at least for production purposes. You did read their disclaimer I expect.

    Fun exercise (or you really mean an exciting nightmare :):):) ) can an important part of the journey with controllers in general. I would not consider that production quality but definitely and exciting journey just to play with it.

    I have several controllers that basically fall into this category of basically an wonderful adventure in getting it running on windows.
     
    guavaman likes this.
  6. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,849
    I have several Xbox controllers in the closet. I wasn't aware of a USB adapter for them. Interesting. If the driver creates a valid HID device that identifies itself as a Gamepad or Joystick, it will work. If it creates an XInput device it will also work. Rewired works with other controller adapters like PS1, PS2, GameCube, etc.
     
  7. little_box

    little_box

    Joined:
    Aug 22, 2017
    Posts:
    25
    Hi, guavaman.
    In my game, character is still moving after releasing the keyboard sometimes. When I output, I find that axis still gets input after the keyboard is released.
     
  8. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,849
    This is very likely the reason:
    https://guavaman.com/projects/rewired/docs/Troubleshooting.html#digital-axis-smoothing

    When a keyboard key or D-Pad is pressed, GetAxis value ramps up/down slowly instead of instantly returning 1/-1
    You have left the default Input Behavior Digital Axis settings. Please read the documentaion on Input Behaviors.

    Digital Axis Settings:
    These settings allow buttons and keyboard keys to be treated like axes and return values ranging from -1 to 1 instead of just True and False as is the usual case. This allows you, for instance, to have smooth character movement when using the keyboard for movement controls. The GetAxis value of the Action can be smoothed over time based on the Digital Axis Settings (gravity and sensitivity). See Rewired Editor - Input Behaviors for more information about each setting.

    The default values have been set to mimic Unity's default Gravity and Sensitivity settings.

    To get an instant on/off value for a keyboard key, do one of the following:

    • Disable Digital Axis Simulation in the Action's Input Behavior.
    • Use player.GetButton and player.GetNegativeButton instead of GetAxis when getting the value of the Action.
    • Use player.GetAxisRaw instead of GetAxis when getting the value of the Action.

    Or else this:
    https://guavaman.com/projects/rewir...#windows-editor-keyboard-keys-stuck-raw-input

    Windows Editor: Keyboard keys sticking for the same duration they were pressed after being released
    Update: According to Unity, this bug will be fixed in Unity 2019.4.0f1.

    1. Unity made a change to the editor update thread in 2019.3.8 (https://unity3d.com/unity/whats-new/2019.3.8 - Editor: Fixed the editor application main thread tick timer throttling causing unwanted spikes and delays. (1211383)) that has resulted in this lag in a very roundabout way. The Windows message queue is having to wait on the editor GUI thread, so heavy CPU usage in the editor GUI update thread now maifests as a severe slowdown to the main thread if messages are waiting to be delivered to it by Raw Input. This issue persists as of 2019.3.15, the latest version, as of the date of this message.
    2. The more work happening on the editor GUI thread, the worse the slowdown of the main thread will be when it has to wait on a Raw Input event to be delivered.
    3. This affects Raw Input, presumably because Raw Input relies on the Windows messaging queue for delivery of input events.
    4. This is most easily reproduced by having the Rewired Input Manager selected in the inspector with the Debug Information foldout open displaying a lot of fields such as when looking at Controllers -> Keyboards and listing all the keys. With this open, the lag after releasing a key when held down for a second or more while is > 1 second. Debug Information makes a lot of calls to Editor Prefs which slows down the editor thread enough to make the new issue visible.
    5. This also affects Unity's new input system through the exact same mechanism of preventing the Raw Input events from being delivered in a timely manner to the input thread. The lag can be reproduced exactly simply by enabling their new input system and running a CPU-intensive operation in an editor script.
    This bug has been reported to Unity with a simple reproduction case using their new input system.
     
  9. StageClearStudios

    StageClearStudios

    Joined:
    Jan 30, 2018
    Posts:
    26
    Hi everyone. We are constanly getting a crash in the rewired system. When unity crashes, the log prints the next error: SharedThread: Too many Calls to Unregister

    Any idea how can we solve this? The crash happens more frequently when we attach the visual studio. Thanks!
     

    Attached Files:

  10. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,849
    The only possible way I know of that this error could occur is if you are instantiating or enabling a Rewired Input Manager Game Object in OnDestroy or OnDisable.
     
    StageClearStudios likes this.
  11. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,849
    New mouse input issue on Windows:

    I have suddenly received multiple reports since yesterday of a new mouse input bug on Windows. When moving the mouse while clicking, the click mail fail to register, or the button may get stuck in an on state.

    I have scoured through the code and find there is no possible way for this to be happening due to code in Rewired. What these reports are describing is missed input events. If it misses the down event, no click is detected. If it misses the up event, the button stays stuck on. Rewired receives its input events directly from Windows through Raw Input messages from the Windows message queue. The events are never buffered in Rewired and are instead processed immediately, guaranteeing there are no buffer overruns that could lead to lost events.

    After thorough investigation, this issue only happens in 2021.2.0b12. This is incredibly baffling that updating Unity could have any effect on Rewired’s native mouse input. This does not make any logical sense. Rewired does not depend on Unity in any way shape or form for receiving input events. Rewired creates its own input event window, registers with Windows API to receive Raw Input events to that window, and Windows sends the events on to Rewired’s window directly. Unity is not in the loop. That makes no sense that an update to Unity could break Rewired’s input, unless Unity is suddenly now hooking the Windows APIs and interfering with input before the events ever get sent to the application, or something equally unusual. At this point, I don't know. I am going to have to spend a bunch of time to deeply investigate this. Whatever the reason, this new issue is caused by something outside Rewired. This is the reason I do not support beta versions of Unity based on many past experiences just like this.

    I have confirmed that in in 2021.2.0b12 the Raw Input mouse button events are not being reported to Rewired by Windows when they occur at the same time as a mouse axis event. I have no explanation. This has been reported to Unity here.
     
    Last edited: Sep 22, 2021
  12. RobertOne

    RobertOne

    Joined:
    Feb 5, 2014
    Posts:
    121
    is there a way to turn off the "Rewired: The version of Rewired installed (XXXX) was not designed for Unity 20XX."

    thanks for letting me know, but thanks, leave that to me
     
  13. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,509
    guavaman likes this.
  14. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,849
    There is no way to turn off these important warnings other than to fix the issue causing it. The link @longroadhwy sent is correct.
     
  15. spraycanmansam

    spraycanmansam

    Joined:
    Nov 22, 2012
    Posts:
    250
    Hi @guavaman, we're supporting Sony DualShock controllers in Japanese regions where the X/O are inverted. Just wondering if there is a quick way to switch action elements in this scenario? ...a toggle I'm missing, etc, or will we have to do this manually...
     
  16. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,849
    There is no built-in toggle for A/B map switching on Nintendo Devices or Cross/Circle map switching on Dual Shock devices. The best way to handle this is with Layouts and Layout Manager.
     
  17. spraycanmansam

    spraycanmansam

    Joined:
    Nov 22, 2012
    Posts:
    250
    Great, I will check it out. Thanks!
     
  18. EpicMcDude

    EpicMcDude

    Joined:
    Apr 15, 2013
    Posts:
    42
    Hey Guavaman,

    Thank you for still offering support for such a great asset.

    How would I be able to change sensitivity of the Right Stick for looking around faster/slower in an FPS? Like changing the mouse sensitivity, but for the controller.
    I've tried making a separate behavior and map that to the Actions on the Right Stick, but that just makes it ultra janky, doesn't change the speed.

    I've searched around and couldn't find anything, I did find a post from 2014 saying you might add a separate function for stick sensitivity but I guess that never came around.

    Thank you!
     
  19. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,849
    There are two ways to modify the output of an axis:

    1. Input Behavior joystick axis sensitivity. This is a simple multiplier. It does work. I don't know what you mean by "makes it ultra janky". It simply multiplies the value of the final Action by the multiplier you set. If you set 0.5, it will multiply the Action value by 0.5. If you multiply it by 2.0, it multiplies it by 2.0. The value is clamped to a -1 to +1 range, so making the value something like 2.5 will not make the resulting Action move 2.5 faster when you have the stick fully pressed. It will make the Action reach 1.0 much earlier on the stick's range, but it will not increase the overall speed. If you're looking for something like that, you would need to change your own speed multiplier that you are modifying the Action value by when you apply this to camera movement.

    2. Axis calibration:
    https://guavaman.com/projects/rewired/docs/HowTos.html#calibrating-controller-axes

    This is applied at the Controller Axis level, not the Action level, and applies to any Actions bound to that Axis. This has been implemented for many years and is shown in both the ControlRemapping1 example and in Control Mapper.
     
  20. marchall_box

    marchall_box

    Joined:
    Mar 28, 2013
    Posts:
    106
    Hello,

    I have 2 questions/

    A.
    How do I use Axis (say, Left Stick) to behave like a button to navigate specific UI's up or down?
    I am trying to control the Dialogue Log list with it.
    I set the Action of it as Button.
    In Joystick Maps, I am setting it to be
    Element: Left Stick Y
    Should I set "Axis Range" to be Negatives for down? Positive for up?
    Let me know if this approach is ideal.

    B.
    UIHorizonal (Unity Input control related), how do I set them with Dpad? (not the left stick axis)
     
    Last edited: Oct 1, 2021
  21. lazylukey

    lazylukey

    Joined:
    May 26, 2017
    Posts:
    15
    Hi I have run into a wall during integration of Rewired, I need to be able to retrieve the default Joystick map in the Rewired Input Manager even if a joystick is not connected. I believe this is possible with `ReInput.mapping.
    GetJoystickMapInstanceSavedOrDefault()` but it's not working as expected. It's returning a JoystickMap that contains 2 elements for Mouse X and Mouse Y. The default joystick map I have does not contain those elements and it also has more like 15-20 different elements. The way I am calling the function is:

    `JoystickMap map = ReInput.mapping.GetJoystickMapInstanceSavedOrDefault(0, ControllerIdentifier.Blank, 0, 0);`

    I tested out GetMouseMapInstanceSavedOrDefault() and that seems to work fine but perhaps that because a mouse is connected.

    I do have a UserDataStore_PlayerPrefs component but I have not yet saved anything to it.
     
  22. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,849
    First, ControllerIdentifier.Blank provides no information about what controller you're trying to retrieve data for. You're trying to retrieve a generic universal Unknown Controller mapping that applies to all Unknown Controllers, but it can't do that. Unknown Controller mappings require the Hardware Identifier which is used to distinguish among different individual Unknown Controllers, each of which can have it's own unique mappings saved.

    Second, you probably do have saved data but you don't realize it. UserDataStore_PlayerPrefs will save any time you close Control Mapper, assuming you're using it. Clear Player Prefs.
     
  23. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,849
    A) The Action type isn't important. All Actions can be queried as both Buttons and Axes.
    https://guavaman.com/projects/rewired/docs/Actions.html

    You can bind Left Stick Y to two Actions (Axis Range Positive to Action "Move Up", Axis Range Negative to "Move Down") or you can bind Left Stick Y to a single Action (Left Stick Y to "Move Vertical").

    Descriptions of the binding settings are available by hovering your mouse pointer over the setting and in the documentation:

    https://guavaman.com/projects/rewired/docs/RewiredEditor.html#JoystickMaps

    Capture.PNG

    B) The same way you bind anything else. Bind D-Pad Left to your "Move Horizontal" Action and bind it to Axis Contribution Negative. Bind D-Pad Right to your "Move Horizontal" and bind it to Axis Contribution Positive.
     
    Last edited: Oct 2, 2021
  24. marchall_box

    marchall_box

    Joined:
    Mar 28, 2013
    Posts:
    106
    It is really great to know.

    I have another question.

    Would this script look valid to you? (I recently came to Rewired from Unity's New Input System due to porting issue so I am transferring all the input code that I wrote)

    My game has multiple mode + multiple additional input that needs to be turned on/off based on the situation on top of main input mode if that makes sense.
    Stuff like "AdditionalInputLocationEventTrigger" is to get it working only within the collider enter/exit area. Other gamemode is based on your Documentation's example.

    Code (CSharp):
    1.  
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Rewired;
    5.  
    6. public class GameInputManager : MonoBehaviour
    7. {
    8.     static readonly int PLAYER_INPUT_ID = 0;
    9.    
    10.     public enum GameMode {
    11.         Combat,
    12.         MiniGame,
    13.         Menu,
    14.         None // when player should not have any control
    15.     }
    16.  
    17.     private GameMode _currentGameMode; // this tracks the current game mode
    18.  
    19.     private bool _additionalInputLocationEventTrigger;
    20.     public bool AdditionalInputLocationEventTrigger
    21.     {
    22.         set
    23.         {
    24.             _additionalInputLocationEventTrigger = value;
    25.             SetControllerMapsForCurrentGameMode();
    26.         }
    27.     }
    28.    
    29.     private bool _additionalInputCityDungeon;
    30.     public bool AdditionalInputCityDungeon
    31.     {
    32.         set
    33.         {
    34.             _additionalInputCityDungeon = value;
    35.             SetControllerMapsForCurrentGameMode();
    36.         }
    37.     }
    38.    
    39.    
    40.     // A dictionary to look up the Map Category from the GameMode
    41.     static Dictionary<GameMode, string> gameModeToMapCategory = new Dictionary<GameMode, string>() {
    42.         { GameMode.Combat, "Combat" },
    43.         { GameMode.Menu, "Menu" },
    44.         { GameMode.MiniGame, "MiniGame" },
    45.         { GameMode.None, "None" }
    46.     };
    47.    
    48.     private Player _player;
    49.     public Player PlayerInput
    50.     {
    51.         get
    52.         {
    53.             if (!ReInput.isReady) return null;
    54.            
    55.             if (_player == null)
    56.             {
    57.                 _player = ReInput.players.GetPlayer(PLAYER_INPUT_ID);
    58.             }
    59.             return _player;
    60.         }
    61.     }
    62.    
    63.    
    64.     private void Awake() {
    65.         // Subscribe to the controller added event in Player so we can update
    66.         // Controller Maps when a new Joystick is assigned
    67.         PlayerInput.controllers.ControllerAddedEvent += OnControllerAdded;
    68.     }
    69.  
    70.     private void OnDisable() {
    71.         PlayerInput.controllers.ControllerAddedEvent -= OnControllerAdded;
    72.     }
    73.  
    74.     // Call this when you change game modes
    75.     public void ChangeGameMode(GameMode mode) {
    76.         _currentGameMode = mode; // store the new game mode
    77.         SetControllerMapsForCurrentGameMode(); // enable the correct Controller Maps for the game mode
    78.     }
    79.    
    80.  
    81.     // This is called when a Controller is assigned to the Player
    82.     private void OnControllerAdded(ControllerAssignmentChangedEventArgs args) {
    83.         SetControllerMapsForCurrentGameMode();
    84.     }
    85.  
    86.     // Enable only the maps for the current game mode
    87.     private void SetControllerMapsForCurrentGameMode() {
    88.         // Disable all controller maps first for all controllers of all types
    89.         PlayerInput.controllers.maps.SetAllMapsEnabled(false);
    90.  
    91.         // Enable maps for the current game mode for all controllers of all types
    92.         PlayerInput.controllers.maps.SetMapsEnabled(true, gameModeToMapCategory[_currentGameMode]);
    93.        
    94.         // Must turn on map - general UI stuff (Unity.UI controls..)
    95.         PlayerInput.controllers.maps.SetMapsEnabled(true, "Persistent");
    96.  
    97.         // Additional map toggle
    98.         PlayerInput.controllers.maps.SetMapsEnabled(_additionalInputLocationEventTrigger, "Layered_LocationEventTrigger");
    99.         PlayerInput.controllers.maps.SetMapsEnabled(_additionalInputCityDungeon, "Layered_CityDungeon");
    100.     }
    101. }
    102.  
     
  25. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,849
    I can't validate code by reading through it as this is too difficult to do without actually sitting down and testing it. But I would suggest you use Map Enabler instead of trying to manage the enabled state of Controller Maps. See the first paragraph of the documentation section where you got this code:

    https://guavaman.com/projects/rewired/docs/HowTos.html#persistent-current-controller-map-category

    It is far easier to manage changing game states using Map Enabler and you don't have to be aware of all the idiosyncrasies of how the system works, for example, the fact that the enabled state must be set for new Controller Maps loaded into a Player because of connecting a new joystick. Use Map Enabler and it will handle those cases automatically based on the rules you define.
     
  26. marchall_box

    marchall_box

    Joined:
    Mar 28, 2013
    Posts:
    106
    If I want to know my controller is Playstation (generally, ps4 or ps5) or Xbox (generally including xbox 360, xbox one etc),

    Would below is the optimal way or is there any other preferred way to do it?

    Code (CSharp):
    1. public static InputControllerType GetControllerType()
    2.     {
    3.         var playerInput = GameManager.Instance.inputManager.PlayerInput;
    4.        
    5.         Controller controller = playerInput.controllers.GetLastActiveController();
    6.  
    7.         if(controller != null) {
    8.             switch(controller.type) {
    9.                 case ControllerType.Keyboard:
    10.                     return InputControllerType.Keyboard;
    11.                    
    12.                 case ControllerType.Joystick:
    13.                     // Get the Dual Shock 4 Controller Extension from the Joystick
    14.                     var ds4 = controller.GetExtension<DualShock4Extension>();
    15.                     if (ds4 != null) return InputControllerType.PlayStation;
    16.                     var ds = controller.GetExtension<DualSenseExtension>();
    17.                     if (ds != null) return InputControllerType.PlayStation;
    18.                     var xbox = controller.GetExtension<XboxOneGamepadExtension>();
    19.                     if (xbox != null) return InputControllerType.Xbox;
    20.                     return InputControllerType.GenericGamePad;
    21.                    
    22.                 case ControllerType.Mouse:
    23.                     return InputControllerType.Keyboard;
    24.                    
    25.                 case ControllerType.Custom:
    26.                     return InputControllerType.GenericGamePad;
    27.                     ;
    28.             }
    29.         }
    30.        
    31.         return InputControllerType.PlayStation;
    32.     }
     
  27. FM-Productions

    FM-Productions

    Joined:
    May 1, 2017
    Posts:
    58
    Hi,
    is it possible to do something like running a separate thread that polls input of a joystick a specified number of times per second, with close to constant delays between the polls? So that it can run separated from the visual update loop? The intention behind it is to track joystick values for (quick) gesture detection in order to have consistent outcomes/processing of inputs.
    I think I have seen someone doing this with XInput on windows. Having it only work for the Windows standalone platform as first step would be enough for now, but if there are suggestions on possibilities to approach it for other platforms too?
     
  28. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,849
    I would not use Controller Extensions to determine controller type. Controller extensions differ by platform. Follow the guidelines in the docs here:
    https://guavaman.com/projects/rewired/docs/HowTos.html#identifying-recognized-controllers
     
    Last edited: Oct 3, 2021
  29. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,849
    No. Rewired is a frame-based input system that only runs in Unity's Update, FixedUpdate, and/or OnGUI. See this:
    https://guavaman.com/projects/rewired/docs/FAQ.html#framerate-independent-input
     
    Last edited: Oct 3, 2021
    FM-Productions likes this.
  30. marchall_box

    marchall_box

    Joined:
    Mar 28, 2013
    Posts:
    106
    I guess this is the way to go? hopefully.

    Code (CSharp):
    1. var playerInput = GameManager.Instance.inputManager.PlayerInput;
    2.         Controller controller = playerInput.controllers.GetLastActiveController();
    3.         if(controller != null) {
    4.             if (controller.type == ControllerType.Joystick)
    5.             {
    6.                 // Xbox 360, One
    7.                 if (controller.hardwareTypeGuid == new Guid("d74a350e-fe8b-4e9e-bbcd-efff16d34115") ||
    8.                     controller.hardwareTypeGuid == new Guid("19002688-7406-4f4a-8340-8d25335406c8"))
    9.                 {
    10.                     return InputControllerType.Xbox;
    11.                 }
    12.                 // PS2, PS3, PS4, DualSense
    13.                 if (controller.hardwareTypeGuid == new Guid("c3ad3cad-c7cf-4ca8-8c2e-e3df8d9960bb") ||
    14.                     controller.hardwareTypeGuid == new Guid("71dfe6c8-9e81-428f-a58e-c7e664b7fbed") ||
    15.                     controller.hardwareTypeGuid == new Guid("cd9718bf-a87a-44bc-8716-60a0def28a9f") ||
    16.                     controller.hardwareTypeGuid == new Guid("5286706d-19b4-4a45-b635-207ce78d8394"))
    17.                 {
    18.                     return InputControllerType.PlayStation;
    19.                 }
    20.                 // Switch Controllers
    21.                 if (controller.hardwareTypeGuid == new Guid("3eb01142-da0e-4a86-8ae8-a15c2b1f2a04") ||
    22.                     controller.hardwareTypeGuid == new Guid("605dc720-1b38-473d-a459-67d5857aa6ea") ||
    23.                     controller.hardwareTypeGuid == new Guid("521b808c-0248-4526-bc10-f1d16ee76bf1") ||
    24.                     controller.hardwareTypeGuid == new Guid("1fbdd13b-0795-4173-8a95-a2a75de9d204") ||
    25.                     controller.hardwareTypeGuid == new Guid("7bf3154b-9db8-4d52-950f-cd0eed8a5819"))
    26.                 {
    27.                     return InputControllerType.Switch;
    28.                 }
    29.                 return InputControllerType.GenericGamePad;
    30.             }
    31.             if (controller.type == ControllerType.Keyboard ||
    32.                      controller.type == ControllerType.Mouse)
    33.             {
    34.                 return InputControllerType.Keyboard;
    35.             }
    36.         }
     
  31. FM-Productions

    FM-Productions

    Joined:
    May 1, 2017
    Posts:
    58
    Thanks for the quick response! Sorry to ask this since it isn't directly related to ReWired, but since you have a lot of experience with Input APIs, are there any APIs or wrappers that can be used in C#/Unity that would support this type of thing - running a separate thread and polling inputs at set intervals (specifically for Joysticks/Controllers)? I heard you can get non-frame-based input states through the new Input system too but I haven't looked into it yet.

    In response to the FAQ link: The suggestion for an accessible queue with input state (actions, for me more importantly axis values) and timestamp to evaluate during a Unity update cycle would sound pretty good, which is what I'd like to try for my game, and like the article mentions there are a lot of issues with immediately responding to the input changes by adjusting game state, and it should usually not be necessary. The relevant part is that recent input can be evaluated in an update cycle without having missed some states between the current and last cycle.
     
    Last edited: Oct 3, 2021
  32. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,849
    No, I don't. Every single platform and input source works differently which is a major part of the problem .Simple example: Raw Input is event-based. Direct Input and XInput are polling based. Event-based input APIs make it impossible to run your own custom update loop where you determine when to poll for events, as your original question suggested. Multiply this by 30+ platforms Unity supports, some with multiple optional input APIs.

    SDL2 is the only system I know of that runs on just about every platform in existence. There's probably a C# wrapper for it somewhere.

    An Action-based input system like Rewired that can combine unlimited number of inputs into a single Action have a significant problem with something like this. While capturing controller input events into a queue is easy enough, the more levels of mapping and abstraction you have, the more fakery and event synthesis you have to do in order to provide an event stack. Rewired has at least 5 different levels of abstraction before you reach the input API level. Every single level of abstraction may perform transformations or mappings on input. For example, the lowest level, the Controller Definition, has the capability of reading low-level elements as buttons, axes, etc., regardless of their type and transforming them into another type. This includes even the possibility of requiring multiple button presses simultaneously to synthesize a different element this is used for (4 and 8 way hats). It also includes the ability to have a custom element source driven by code to be able to dynamically change element mappings and transform input values based on certain input value patterns because of some driver (some racing wheels) that allow the user to switch modes on the device with no other way to detect the mode change. That's the first level. Then we have the Input Manager level specific to each input source, then we have the Rewired Controller level, then we have calibration of the Controller level, then the Action level, then the Action level is transformed by the Input Behavior... Every single one of these steps can and does perform transformations that make generating event stacks extremely expensive to perform and complicated and problematic to navigate, especially when more than one device is contributing value to an Action. And then there's the matter of maintaining separate event queues for raw and calibrated events, and Input Behaviour-modified events and not. The Action level itself generates events because it can be queried both as a Button and an Axis, and those each need to have their own separate event queues of synthesized events, both raw and non-raw. I did implement this years ago as a test. It was a very long process to implement as it requires significant structural changes to all individual platform input support at multiple levels and changes at the core level. But once I was finished, I abandoned it because it increased the CPU workload of Rewired by at minimum 300% because of all the different event queues, analysis and processing of those events in order to synthesize new events at the next level of the stack, over and over until the top-most Action level. This was unacceptable because 99% of users wouldn't even be interested in inter-frame event stacks, but the structure and overhead would be required regardless if they used it or not. Creating a queue of events from XInput is simplistic by comparison, both in generation and in consumption. Add to that the fact that quite a few platforms got zero benefit from it, considering they're running on UnityEngine.Input as the source of input which is not capable of delivering inter-frame events, and it was pretty obvious for me that it was not going to be worth it.
     
    Last edited: Oct 3, 2021
  33. FM-Productions

    FM-Productions

    Joined:
    May 1, 2017
    Posts:
    58
    Thank you for the detailed explanations! The design decision against the complex event queues in favour of performance makes a lot of sense. I'll look more into XInput, SDL2 and perhaps the new Unity input system, as it seems to have an option to have input updates occur at a fixed frame rate (although the setting seems to be tied with FixedUpdate, which wouldn't be ideal either) or alternatively by manually calling an Update method. If the game performance allows a stable frame rate in all scenarios, maybe the accuracy of the gesture detection is sufficient for frame-based input systems too, but in cases where the performance tanks, I'd imagine there will be issues with that.
     
    Last edited: Oct 3, 2021
  34. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,849
    It would probably be more efficient to make static variables with the Guids you're interested to check against.
     
    marchall_box likes this.
  35. jason_yak

    jason_yak

    Joined:
    Aug 25, 2016
    Posts:
    411
    Hi there, apologies if this has been asked a bunch of times, I couldn't find any answer in the docs or this thread. I'm using the super handy shared Gamepad Template for most controllers, but for some I need to define a couple of things that only slightly differ from the shared template.

    For example, the shared template covers all I need for a Dualsense controller, but I need to define an action for the touchpad button, but it seems I'd have to redefine all of the actions exactly the same as the shared game template just for that one custom input/action. I'm hoping I'm missing something, but is there a way for the two templates to be additive where the shared gamepad template is the base which the dualsense template further overrides? it's not that bad to have to redo the whole template, but just seemed like it would be much better for upkeep that I have one base template to manage and the individual templates could act as custom deviations just for the couple of inputs that differ.

    Thanks!
     
  36. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,849
    Controller-specific Controller Maps override Template Controller Maps of the same Map Category and Layout if found when loading. They are not additive. The only way to achieve something similar to that would be to break up your Controller Maps into more maps that contain fewer bindings, then override the smaller group of bindings instead of everything.
     
  37. jason_yak

    jason_yak

    Joined:
    Aug 25, 2016
    Posts:
    411
    No worries, and cool thanks for the tip, something to look into.
     
  38. Kazeon

    Kazeon

    Joined:
    May 22, 2017
    Posts:
    25
    @guavaman

    Hi. I'm making a custom joystick-auto-assignment mechanism that prioritize players without keyboard input. I haven't any problem actually, I just have this thought occurred just now and feel like I need to ask you.

    In older consoles like PlayStation 2, it has dedicated controller slot for each player IIRC. I haven't owned any Play Station machine for a very long time so I'm not sure but my friend said PS4 also have similar controller slots.

    How do you think I should handle the auto-assignment so that it makes sure that if the controller is plugged into slot-1 (initially) it will always be assigned to Player 1, if it's in slot-2 it will be assigned to Player 2, etc? Unless if players have modified the controller assignment themselves of course. Does Rewired auto-assignment mechanism already handles this out of the box?
     
    Last edited: Oct 7, 2021
  39. Hi_ImTemmy

    Hi_ImTemmy

    Joined:
    Jul 8, 2015
    Posts:
    127
    Hello,

    Apologies, I'm sure this must be in the documentation somewhere but I'm having trouble finding it.

    I'm looking for an event that fires whenever any control pad input is detected, and an event which fires whenever any keyboard or mouse input is detected. As you might guess it's for changing things like UI based on the active input device.

    I've found things like
    player.AddInputEventDelegate()
    however I can't see any overload that is based around the hardware type (it seems to be geared towards actions or buttons)
     
    Last edited: Oct 7, 2021
  40. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    540
    guavaman and Hi_ImTemmy like this.
  41. Hi_ImTemmy

    Hi_ImTemmy

    Joined:
    Jul 8, 2015
    Posts:
    127
  42. Hi_ImTemmy

    Hi_ImTemmy

    Joined:
    Jul 8, 2015
    Posts:
    127
  43. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    540
    Hi_ImTemmy likes this.
  44. Hi_ImTemmy

    Hi_ImTemmy

    Joined:
    Jul 8, 2015
    Posts:
    127
    flashframe likes this.
  45. Kazeon

    Kazeon

    Joined:
    May 22, 2017
    Posts:
    25
    Hey @guavaman I have another question. I noticed in the controller element csv file, for switch pro controller it says:

    Nintendo Switch Pro Controller,"Pro Controller","7bf3154b-9db8-4d52-950f-cd0eed8a5819","16","Left Stick","1"
    Nintendo Switch Pro Controller,"Pro Controller","7bf3154b-9db8-4d52-950f-cd0eed8a5819","17","Right Stick","1"
    ....
    Nintendo Switch Pro Controller,"Pro Controller","7bf3154b-9db8-4d52-950f-cd0eed8a5819","22","Left Stick","100"
    Nintendo Switch Pro Controller,"Pro Controller","7bf3154b-9db8-4d52-950f-cd0eed8a5819","23","Right Stick","100"

    Both element 16 & 17 and 22 & 23 are named /the same/.. Usually the upper ones are named "Left Stick Button" & "Right Stick Button". The same occurrence also applies on all the joycon controller variants.. Could it be a mistake or is it what it is?

    P.S. it's from the latest version of the CSV file
     
  46. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,849
    Your question can only be answered if the platform is known. Every platform works differently. PC platforms have no concept of "slots" and therefore this question does not apply. Each console has a different system for handling user management, and Rewired support for that platform would include exposure of the relevant information required to make user to Player associations.
     
  47. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,849
    As @flashframe noted, the Last Active Controller functionality is what you want. There are two versions of this though, one that monitors Actions in the Player and one that just monitors all Controllers:

    https://guavaman.com/projects/rewired/docs/HowTos.html#last-used-controller
     
  48. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,849
    It's not a mistake. The buttons are named that way in order to comply with Nintendo's naming rules. The last 2 are not axes. They are Axis 2D's which represent a 2D stick made up of 2 axes. The "100" value is the value of Axis2D.
     
  49. Hi_ImTemmy

    Hi_ImTemmy

    Joined:
    Jul 8, 2015
    Posts:
    127
    Thanks. The player centric delegate worked a charm. Here it is in action running alongside Adventure Creator:

    https://twitter.com/Hi_ImTemmy/status/1446160442058059779

    I really like Rewired.
     
    guavaman and flashframe like this.
  50. Kazeon

    Kazeon

    Joined:
    May 22, 2017
    Posts:
    25
    We plan to release our game on PS4 and PS5 one day, I'm not sure about PS5 but for PS4 my friend said it also have controller slots, but he is not sure whether or not each slot is dedicated for specific player like on PS2. So for now I'm asking in the context of PS4 platform if that makes sense. I haven't tried any of these newer PS generations so I have no slightest clue of how the controller assignment generally works.

    Got it. Thanks!
     
unityunity