Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Rewired - Advanced Input for Unity

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

  1. Darkkingdom

    Darkkingdom

    Joined:
    Sep 2, 2014
    Posts:
    81
    EDIT:
    I'm looking for a way to slowly increase the axis input when a joystick is pushed in a certain direction, similar to the digital simulation of the keyboard input.

    The reason is that jumping and landing with the keyboard is very precise, in my game.
    When I just shortly press a direction key it's possible to do tiny hops.
    But with an controller, if I tend the joystick only briefly, too its full extend I always do far jumps.
    So I did some Debug Logs of my GetAxis () method and saw that the input is much faster at its maximum value with the gamepad. I hoped this could be configurable in the input settings, but maybe I'm looking in the wrong direction.
     
    Last edited: Oct 14, 2018
  2. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    Please describe what you're doing to get the +1 / -1 value. Are you pressing the joystick a little bit or a lot? Axis values do not fade or animate over time unless the joystick is currently being moved (except Digital Axis Simulation which is used only for buttons/keys and the time it takes to animate is based on your settings in the Input Behavior). Joystick axis values are read from the device directly. A joystick has an absolute value. -1 / +1 at the min/max extents and it will report +/-1 value the instant a stick is pressed fully in a direction. If you are pressing the stick a tiny bit and getting a +1 / -1 value, then either the calibration is wrong or you have the Input Behavior's Joystick Axis Sensitivity set too high.
     
    Last edited: Oct 14, 2018
    Darkkingdom likes this.
  3. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    789
    Hi @guavaman

    For keyboard input, does Rewired use the same KeyCodes as Unity when reporting key names? Will the name reported be consistent no matter what keyboard / keyboard layout being used?

    (I'm making a list of abbreviations for keys with longer names (e.g. LeftBracket) for onscreen prompts.)
     
  4. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    Rewired uses the same KeyCodes, but it does not report the keycode name when displaying key information intended to be shown to the user.

    The only platform that supports native keyboard input is Windows. All other platforms simply wrap UnityEngine.Input.GetKey and therefore it behaves the same as Unity with regard to non-us, non-QWERTY keyboards.

    Windows native keyboard handling has no special code for any non-standard keyboard type. Windows sends keyboard events that contain a VKey (virtual key) code. This VKey code is converted to a KeyCode so it will return the same information as Unity. Handling of different keyboard types is dependent on how Windows handles it via the VKey system.

    This is the list of display names for keys Rewired uses, followed by the KeyCode values and abbreviations for modifier keys.

    Code (csharp):
    1. private static readonly string[] _keyboardKeyNames = new string[] {
    2.     "None",
    3.     "A",
    4.     "B",
    5.     "C",
    6.     "D",
    7.     "E",
    8.     "F",
    9.     "G",
    10.     "H",
    11.     "I",
    12.     "J",
    13.     "K",
    14.     "L",
    15.     "M",
    16.     "N",
    17.     "O",
    18.     "P",
    19.     "Q",
    20.     "R",
    21.     "S",
    22.     "T",
    23.     "U",
    24.     "V",
    25.     "W",
    26.     "X",
    27.     "Y",
    28.     "Z",
    29.     "0",
    30.     "1",
    31.     "2",
    32.     "3",
    33.     "4",
    34.     "5",
    35.     "6",
    36.     "7",
    37.     "8",
    38.     "9",
    39.     "Keypad 0",
    40.     "Keypad 1",
    41.     "Keypad 2",
    42.     "Keypad 3",
    43.     "Keypad 4",
    44.     "Keypad 5",
    45.     "Keypad 6",
    46.     "Keypad 7",
    47.     "Keypad 8",
    48.     "Keypad 9",
    49.     "Keypad .",
    50.     "Keypad /",
    51.     "Keypad *",
    52.     "Keypad -",
    53.     "Keypad +",
    54.     "Keypad Enter",
    55.     "Keypad =",
    56.     "Space",
    57.     "Backspace",
    58.     "Tab",
    59.     "Clear",
    60.     "Return",
    61.     "Pause",
    62.     "ESC",
    63.     "!",
    64.     "\"",
    65.     "#",
    66.     "$",
    67.     "&",
    68.     "'",
    69.     "(",
    70.     ")",
    71.     "*",
    72.     "+",
    73.     ",",
    74.     "-",
    75.     ".",
    76.     "/",
    77.     ":",
    78.     ";",
    79.     "<",
    80.     "=",
    81.     ">",
    82.     "?",
    83.     "@",
    84.     "[",
    85.     "\\",
    86.     "]",
    87.     "^",
    88.     "_",
    89.     "Back Quote",
    90.     "Delete",
    91.     "Up Arrow",
    92.     "Down Arrow",
    93.     "Right Arrow",
    94.     "Left Arrow",
    95.     "Insert",
    96.     "Home",
    97.     "End",
    98.     "Page Up",
    99.     "Page Down",
    100.     "F1",
    101.     "F2",
    102.     "F3",
    103.     "F4",
    104.     "F5",
    105.     "F6",
    106.     "F7",
    107.     "F8",
    108.     "F9",
    109.     "F10",
    110.     "F11",
    111.     "F12",
    112.     "F13",
    113.     "F14",
    114.     "F15",
    115.     "Numlock",
    116.     "Caps Lock",
    117.     "Scroll Lock",
    118.     "Right Shift",
    119.     "Left Shift",
    120.     "Right Control",
    121.     "Left Control",
    122.     "Right Alt",
    123.     "Left Alt",
    124.     "Right Command",
    125.     "Left Command",
    126.     "Left Windows",
    127.     "Right Windows",
    128.     "AltGr",
    129.     "Help",
    130.     "Print",
    131.     "SysReq",
    132.     "Break",
    133.     "Menu"
    134. };
    135.  
    136. internal static readonly int[] _keyboardKeyValues = new int[] {
    137.     0, // None
    138.     97, // A
    139.     98,
    140.     99,
    141.     100,
    142.     101,
    143.     102,
    144.     103,
    145.     104,
    146.     105,
    147.     106,
    148.     107,
    149.     108,
    150.     109,
    151.     110,
    152.     111,
    153.     112,
    154.     113,
    155.     114,
    156.     115,
    157.     116,
    158.     117,
    159.     118,
    160.     119,
    161.     120,
    162.     121,
    163.     122, // Z
    164.     48,
    165.     49,
    166.     50,
    167.     51,
    168.     52,
    169.     53,
    170.     54,
    171.     55,
    172.     56,
    173.     57,
    174.     256,
    175.     257,
    176.     258,
    177.     259,
    178.     260,
    179.     261,
    180.     262,
    181.     263,
    182.     264,
    183.     265,
    184.     266,
    185.     267,
    186.     268,
    187.     269,
    188.     270,
    189.     271,
    190.     272,
    191.     32, // Space
    192.     8,
    193.     9,
    194.     12,
    195.     13,
    196.     19,
    197.     27, // Escape
    198.     33,
    199.     34,
    200.     35,
    201.     36,
    202.     38,
    203.     39,
    204.     40,
    205.     41,
    206.     42,
    207.     43,
    208.     44,
    209.     45,
    210.     46,
    211.     47,
    212.     58,
    213.     59,
    214.     60,
    215.     61,
    216.     62,
    217.     63,
    218.     64,
    219.     91,
    220.     92,
    221.     93,
    222.     94,
    223.     95,
    224.     96,
    225.     127,
    226.     273,
    227.     274,
    228.     275,
    229.     276,
    230.     277,
    231.     278,
    232.     279,
    233.     280,
    234.     281,
    235.     282,
    236.     283,
    237.     284,
    238.     285,
    239.     286,
    240.     287,
    241.     288,
    242.     289,
    243.     290,
    244.     291,
    245.     292,
    246.     293,
    247.     294,
    248.     295,
    249.     296,
    250.     300,
    251.     301,
    252.     302,
    253.     303,
    254.     304,
    255.     305,
    256.     306,
    257.     307,
    258.     308,
    259.     309,
    260.     310,
    261.     311,
    262.     312,
    263.     313,
    264.     315,
    265.     316,
    266.     317,
    267.     318,
    268.     319 // Menu
    269. };
    270.  
    271. private static readonly string[] _modifierKeyShortNames = new string[] {
    272. "",//None = 0,
    273. "Ctrl",//Control = 1,
    274. "Alt",//Alt = 2,
    275. "Shift", //Shift = 3,
    276. "Cmd", //Command = 4
    277. };
    278.  
     
    flashframe likes this.
  5. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    I did not see your edit. I must have been replying to your message when you edited it.

    There is no joystick axis "smoothing" capability built into Rewired. I have played with this concept before and I really don't think you would like the results. It ends up feeling exactly like input lag when applied to a stick and makes control very difficult. Users expect joysticks to respond based on the amount of pressure they're putting on it. To achieve a small move vector, you should be able to press the stick very lightly in a direction. Sticks have a full range of -1 to +1. Even with a dead zone, it will start at 0 when it reaches the end of the dead zone, so the ramp should be smooth all the way to 1. The exact curve depends on the joystick hardware itself. The proper way to change the sensitivity curve of a joystick is to calibrate it:
    http://guavaman.com/projects/rewired/docs/HowTos.html#calibrating-controller-axes
     
    Last edited: Oct 15, 2018
    Darkkingdom likes this.
  6. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    789
    Perfect, thanks
     
  7. Deleted User

    Deleted User

    Guest

    I was wondering if you might have some debugging insight.

    https://hastebin.com/egehevecix.cpp

    Previously code like this logged all player's Rewired ID's. (and then there's a thing that hooks them to individual menus by assigning their ID if they push a button and aren't already "isPlaying")

    This code is now only logging a single player's ID. I realize it's not much to go on...

    Edit: Ignore me, it must be related to my project. This script behaves as expected when put in a scene alone, so I must have some created a conflict in the last few weeks somehow.

    https://hastebin.com/ayenuwetid.cpp

    I'll figure it out. Nice plugin :D a real godsend.
     
    Last edited by a moderator: Oct 16, 2018
  8. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    The only way that input would not be updated for a Player is if there are no enabled Controller Maps that bind anything loaded in that Player.

    What's the purpose of using this input update event for all the Players? It will simply be called every Update or FixedUpdate (if you have that enabled). There's no benefit of doing this vs just calling your function every frame. Player.isPlaying has no impact on whether or not this callback is fired.
     
  9. Deleted User

    Deleted User

    Guest

    No worries, I was able to isolate the problem. I had created a script execution order issue when updating a bunch of UI code I haven't touched in ages. It'll probably make more sense if I show you this script, I don't mind:

    https://hastebin.com/wipavecuna.cs

    This script creates a pseudo-lobby- it's only present while setting the game up. I use a MenuController script to navigate Selectables which sets color properties to indicate menu focus, tracking a focused element for each menu. The controller can invoke buttons and moves between the UI elements using explicit navigation links; which is the only thing keeping them separated while accommodating four players using their own menus, while sharing a canvas.
     
    guavaman likes this.
  10. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    I am hoping the Sublight Dynamics is able to get their potential product into production.

    There is another company HoneyComb that is making new Yoke and Throttle. The founder came from Saitek USA originally. Last I checked it is 2019 when their products are supposed to ship.

    https://flyhoneycomb.com/

    The engineering is interesting since they are working with PFC (precision flight controls). PFC is well better known for making higher quality flight sim gear that typically used in FAA approved flight simulations. It will be interesting to see what their overall quality is based on the price point they are targeting. More details can be found here.

    https://flyhoneycomb.com/design-2/
     
    guavaman likes this.
  11. utkarshdwivedi3997

    utkarshdwivedi3997

    Joined:
    Aug 11, 2017
    Posts:
    25
    Hey @guavaman, I'm working on a weird controller layout setup menu for my game, and it works great, except in one specific scenario. It's a game that can support 1-4 controllers. I have the players set up the controller layouts in the main menu, then load the scenes for levels. Once they head back to the main menu, and a controller either gets connected or disconnected, Rewired gives me this error:
    Code (CSharp):
    1.  
    2. Rewired: An exception occurred inside an event handler or callback.
    3. Source: Rewired.ReInput.ControllerPreDisconnectEvent
    4.  
    5. This happens if your event handler code throws an exception. It can also happen if you forget to unsubscribe to an event in a MonoBehaviour class and that object gets destroyed. Make sure you unsubscribe to events in OnDisable or OnDestroy. Rewired will attempt to continue running.
    6.  
    7. Exception:
    8. UnityEngine.MissingReferenceException: The object of type 'ControllerImage' has been destroyed but you are still trying to access it.
    9. Your script should either check if it is null or you should not destroy the object.
    10.   at (wrapper managed-to-native) UnityEngine.Component:get_gameObject ()
    11.   at Menus.MenuState_ControllerSetup.ControllerDisconnected (Int32 rewiredID) [0x00011] in C:\Users\ud26\Desktop\Fling (1)\Assets\_Tech\Scripts\Managers\Menu\MenuState_ControllerSetup.cs:783
    12.   at RewiredJoystickAssign.OnControllerPreDisconnect (Rewired.ControllerStatusChangedEventArgs args) [0x0009d] in C:\Users\ud26\Desktop\Fling (1)\Assets\_Tech\Scripts\Character&Tether\Controls\RewiredJoystickAssign.cs:165
    13.   at Rewired.Utils.SafeAction`1[Rewired.ControllerStatusChangedEventArgs].VfbtPPoKpUpxbswEdvcWbXJjauL (System.Object , System.Action`1 ) [0x00000] in <filename unknown>:0
    14.   at Rewired.Utils.SafeDelegate`1[System.Action`1[Rewired.ControllerStatusChangedEventArgs]].Invoke (System.Action`2 invokeCallback) [0x00000] in <filename unknown>:0
    15. ------- Rewired System Info -------
    16. Unity version: 2017.4.6f1
    17. Rewired version: 1.1.19.9.U2017
    18. Platform: Windows
    19. Editor Platform: Windows
    20. Using Unity input: False
    21. Primary input source: DirectInput
    22. Use XInput: True
    23. Native mouse handling: True
    24. Enhanced device support: False
    25.  
    26. UnityEngine.Debug:LogError(Object)
    27. Rewired.Logger:LogErrorNow(Object, Boolean)
    28. Rewired.Logger:LogError(Object, Boolean)
    29. Rewired.ReInput:HandleCallbackException(String, Exception)
    30. Rewired.ReInput:FSfRwAfXtUVtYMqUcSttTjcrFTU(Exception)
    31. Rewired.Utils.SafeDelegate`1:Invoke(Action`2)
    32. Rewired.Utils.SafeAction`1:Invoke(ControllerStatusChangedEventArgs)
    33. Rewired.ReInput:bUZtqhXMqkpBsYnujWxFHAKsHpB(ControllerStatusChangedEventArgs)
    34. klGIhoyMGvANUbvUamaEKoFQAQFE:FUMkBmEpuvuzQxIUSEuUdaMtVLk(Int32)
    35. klGIhoyMGvANUbvUamaEKoFQAQFE:WmuBQrprdLAJLcUvvfZAbefpGpBd(Int32)
    36. Rewired.ReInput:AIIXGutUrrPqlCoVokTlYOPDPKH(ControllerDisconnectedEventArgs)
    37. sxvqTloJPEIEORdGECxqKbFSNfF:nsmGKWSAPzBnRsoTMbFlNhNaDAOD(ControllerDisconnectedEventArgs)
    38. vCbouAIzRavhNrIdGrVBVuINirK:kxVgBuKEDctOAvHpOmNjOlIYDPJU(ESgQIsGcFMNQUzGtpIWhJAdrtKl, Boolean)
    39. vCbouAIzRavhNrIdGrVBVuINirK:PVEGBPFxkFsQlWVCioQoRveSImS(Boolean[])
    40. vCbouAIzRavhNrIdGrVBVuINirK:wxfJMcEMMmIBcfkqEaNnSDRQryv()
    41. vCbouAIzRavhNrIdGrVBVuINirK:Update(UpdateLoopType)
    42. sxvqTloJPEIEORdGECxqKbFSNfF:Update(UpdateLoopType)
    43. Rewired.ReInput:iPZxQqQEwYzPXQqUqaimkhJfeCk(UpdateLoopType)
    44. Rewired.InputManager_Base:DoUpdate(UpdateLoopType, UpdateLoopSetting)
    45. Rewired.InputManager_Base:Update()
    46.  
    47.  
    I have a script that is a singleton instance, and doesn't destroy on load, since that keeps track of the layouts. In this script, I subscribe a function to ReInput.ControllerConnectedEvent, and OnDestroy(), I unsubscribe to these functions. I'm not sure why exactly I'm getting this error, because the script never really gets destroyed, and that is the way the code is meant to work. The script needs to always exist until the game is exited out of.

    Any suggestions?

    I can send you more details if needed.
     
  12. Klamore74

    Klamore74

    Joined:
    Jun 17, 2013
    Posts:
    103
    Hi @guavaman !

    We are running Rewired on Unity 2018.2.11f1. We just download from the store but we got the message:

    Rewired: The version of Rewired installed (1.1.19.9.U2017) was not designed for Unity 2018. Please install Rewired for Unity 2018.

    How can we download the 2018 version (1.1.19.9.U2018 I suppose).

    Thanks!
     
  13. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    Download it from the Unity Asset Store in Unity 2018. See this:
    http://guavaman.com/projects/rewired/docs/Troubleshooting.html#installation-problems-5x

    Delete the download file from the Unity Asset Store's cache and re-download it if it doesn't give you the option to download again.

    This is how the Unity Asset Store works and isn't specific to Rewired.

    Edit: New documentation on this problem: http://guavaman.com/projects/rewired/docs/Troubleshooting.html#wrong-rewired-version-installed
     
    Last edited: Oct 17, 2018
  14. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    The error is not in Rewired or in subscription/unsubscription. It's an exception being thrown by the code in your callback as the exception message states. Look at the stack trace:

    --------------------
    UnityEngine.MissingReferenceException: The object of type 'ControllerImage' has been destroyed but you are still trying to access it.
    Your script should either check if it is null or you should not destroy the object.
    at (wrapper managed-to-native) UnityEngine.Component:get_gameObject ()
    at Menus.MenuState_ControllerSetup.ControllerDisconnected (Int32 rewiredID) [0x00011] in C:\Users\ud26\Desktop\Fling (1)\Assets\_Tech\Scripts\Managers\Menu\MenuState_ControllerSetup.cs:783
    at RewiredJoystickAssign.OnControllerPreDisconnect (Rewired.ControllerStatusChangedEventArgs args) [0x0009d] in C:\Users\ud26\Desktop\Fling (1)\Assets\_Tech\Scripts\Character&Tether\Controls\RewiredJoystickAssign.cs:165
    -------------------
    1. Rewired fires OnControllerPreDisconnect
    2. Your callback, Menus.MenuState_ControllerSetup.ControllerDisconnected is called.
    3. Your callback is accessing the gameObject property on some ControllerImage component.
    4. The ControllerImage component was already destroyed yet you are trying to get the gameObject on it, hence Unity throwing the exception.
     
    utkarshdwivedi3997 likes this.
  15. utkarshdwivedi3997

    utkarshdwivedi3997

    Joined:
    Aug 11, 2017
    Posts:
    25
    @guavaman Whoops, you're right. Thanks for pointing that out! Another error that I see pop up a bunch of times when connecting/disconnecting controllers is this:

    Code (CSharp):
    1. <RI.Hid> Failed to read input report:
    2. The I/O operation has been aborted because of either a thread exit or an application request.
    3.  
    I think this has nothing to do with Rewired but Unity instead?
     
  16. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    That's a Unity error message. All Rewired messages are prefixed with "Rewired:".
     
    utkarshdwivedi3997 likes this.
  17. Klamore74

    Klamore74

    Joined:
    Jun 17, 2013
    Posts:
    103
    Thanks! Removing old downloaded version from %appdata%\Unity\Asset Store-5x works for me.
     
  18. whatnotory

    whatnotory

    Joined:
    Sep 21, 2017
    Posts:
    7
    Hi,
    So LoadDefaultMaps() works great for resetting all the player's control maps back to the defaults -- but is there an easy way to reset individual actions to default (that is, as defined in the RewiredInputManager editor)?
    I think my problem basically comes down to getting a reference to the default controller map. I tried using

    Code (CSharp):
    1. ReInput.mapping.GetControllerMapInstance(playerController, "Gameplay", "Default");
    .. which seems promising, but I haven't gotten it to work quite yet. Is this the correct direction to head?

    Thanks!
     
  19. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    Yes, using the GetControllerMapInstance is correct.

    There is no built-in functionality to reset an individual binding on a Controller Map. That would be very prone to causing conflicts.

    The only way you can do it for individual bindings is to load the instance and compare the bindings to the bindings in the other Controller Map.
     
    whatnotory likes this.
  20. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    You can load an individual Controller Map into the Player which will reset just that map:
    http://guavaman.com/projects/rewired/docs/HowTos.html#loading-controller-maps-runtime
     
    whatnotory likes this.
  21. Khena_B

    Khena_B

    Joined:
    Aug 21, 2014
    Posts:
    273
    How can I specify a different rate and delay when calling GetButtonRepeating()?
     
  22. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    See the API documentation for the method:
    http://guavaman.com/projects/rewired/docs/api-reference/html/M_Rewired_Player_GetButtonRepeating.htm

    Gets the repeating button state of an Action. This will return TRUE when immediately pressed, then FALSE until the Input Behaviour button repeat delay has elapsed, then TRUE for a 1-frame duration repeating at the interval specified in the InputBehavior assigned to the Action. This also applies to axes being used as buttons.

    ----------

    Input Behaviors - Button Repeating
    Rewired Editor - Input Behaviors
     
  23. Khena_B

    Khena_B

    Joined:
    Aug 21, 2014
    Posts:
    273
    I know how to use it and how to set the rate and delay in the Input Behavior tab, but I want to specify a different rate and delay every time I call it, as in:

    Code (CSharp):
    1. GetButtonRepeating(action, delay, rate)
    How can I change the rate and delay by code, I don't understand how to access the buttonRepeatRate and buttonRepeatDelay properties.
     
    Last edited: Oct 19, 2018
  24. Khena_B

    Khena_B

    Joined:
    Aug 21, 2014
    Posts:
    273
    I'll create multiple actions for now and switch actions when i need a different repeat rate, please let me know if there is another way.
     
  25. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    789
    Hey @guavaman

    How do I access controller maps outside of play mode (i.e. in the editor)? Is that possible?
    Sorry if this is covered in the docs - had a look but couldn't find it.

    Thanks!
     
  26. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    There is no way to set the delay and repeat rate every time you call the method.

    You can change the repeat rate and delay in the Input Behavior at runtime:
    http://guavaman.com/projects/rewired/docs/HowTos.html#modifying-input-behaviors-during-runtime
     
    dithyrambs and Khena_B like this.
  27. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    Rewired does not provide a public API for that. It is designed for you to create and configure Controller Maps in the editor.
     
  28. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    789
    Ah ok, fair enough. Was hoping to test my code for showing glyphs and button names without needing to be in play mode, but no problem.

    Thanks!
     
  29. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    flashframe likes this.
  30. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    789
  31. whatnotory

    whatnotory

    Joined:
    Sep 21, 2017
    Posts:
    7
    Thanks for your help. I ended up doing the following which seems to work well. (this code snippet doesn't cover all cases -- just the one I'm particularly interested in at the moment)

    Code (CSharp):
    1. Controller playerController = _rewiredPlayer.controllers.GetLastActiveController(ControllerType.Joystick);
    2. ControllerMap playerMap = _rewiredPlayer.controllers.maps.GetMap(playerController, "Gameplay", "Default");
    3. ActionElementMap playerActionElementMap = playerMap.GetFirstElementMapWithAction(_rewiredAction, false);
    4.  
    5. ControllerMap templateMap = ReInput.mapping.GetControllerMapInstance(playerController, "Gameplay", "Default");
    6. ActionElementMap defaultActionElementMap = templateMap.GetFirstElementMapWithAction(_rewiredAction, false);
    7.  
    8. if (defaultActionElementMap != null) {
    9.     if (playerActionElementMap != null) {
    10.         playerActionElementMap.elementIdentifierId = defaultActionElementMap.elementIdentifierId;
    11.     }
    12. }
    So, the previous code snippet seems to work well for me -- but, in the spirit of understanding things more fully, I'm wondering why the following alternative didn't work?
    Code (CSharp):
    1. []
    2. if (defaultActionElementMap != null) {
    3.     if (playerActionElementMap != null) {
    4.         ElementAssignment elementAssignment = new ElementAssignment(defaultActionElementMap.elementIdentifierId, defaultActionElementMap.actionId, false, playerActionElementMap.id);
    5.         playerMap.ReplaceElementMap(elementAssignment);
    6.     }
    7. }
    -- the result of that code, looking at the RewiredInputManager's Debug Information, is that rather than the proper ActionElementMap in the player's ControllerMap being replaced, it is instead just deleted from the player's ControllerMap. (And I checked to make sure that the return value of playerMap.ReplaceElementMap(elementAssignment) is true.)

    Also, using playerMap.ReplaceOrCreateElementMap(elementAssignment) yielded the same result.

    I wondered if having the player's Gameplay ControllerMap enabled or disabled made a difference -- but got the same behavior both ways

    Anyway, any insight would be much appreciated

    Thanks!
     
    StageClearStudios likes this.
  32. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    There are many things that could be going on here.

    First:
    playerMap.GetFirstElementMapWithAction is going to be returning the first mapping with that Action. There there are multiple, you wouldn't know what type of binding it is.

    Second:
    The constructor you used for new ElementAssignment is only correct for a full-axis binding as the API documentation states. If you do not know this is a full-axis binding, you can't use that overload.

    Third:
    If the binding type changed (button to axis to button), a new ActionElementMap will be created and the old one deleted. This ActionElementMap would appear in the buttonMaps or axisMaps list depending on the new type of binding that was created.
     
    whatnotory likes this.
  33. whatnotory

    whatnotory

    Joined:
    Sep 21, 2017
    Posts:
    7
    Ah, sorry I forgot to mention that I allow only one element mapping per action. But your second point is the issue.
    Thanks!
     
  34. fatality674

    fatality674

    Joined:
    Nov 1, 2012
    Posts:
    24
    Hi guavaman

    I’m looking at using rewired to take input from multiple joysticks at the same time and I have hit a couple of issues.

    To give more context, I’m making a military sim which has a joystick as well as a couple of buttons on the side of the unit. They are separate inputs which I need to react to within the same app.

    The way I have tried to set it up is to have a separate controller and calibration map for each input. Is this the right way to go about doing this? I’ve run into a problem where it listens for input via the inputmapper.context, but the issue with this is you can only specify one controller map to the context.


    I have a controller mapping and calibration scene which works fine, but you have to specify which controller you are mapping at the time. I just feel that it’s not listening to all controllers at the same time.


    I feel like I’m missing something here.

    How would you set up two separate inputs to be used by the same player?


    Im using version 1.1.19.9 with Unity 2017.2.0f3
     
  35. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    It's not. Rewired's entire structure is based on individual Controllers assigned to a Player, each with its own individual Controller Maps which bind Actions to the target Controller. It is not a system with a static global binding list like almost every other system out there. You do not just start the whole system listening and listen for bindings from every device.

    A Controller Map is associated to a single Controller. It is impossible to bind elements from multiple Controllers to a single Controller Map. InputMapper's binding system listens for bindings on a single Controller Map at a time. By definition, that means it's listening to a single Controller.

    All 3 of Rewired control rebinding examples (Simple Conrol Remapping, Control Remapping 1, Control Mapper) show how to handle controllers assigned to a Player on a controller-by-controller basis. You select the Player and list all the Joysticks assigned to that Player. Allow the user to rebind controls on each Joystick separately by selecting the Joystick first, then showing the list of binding fields.

    Assign multiple Joysticks to the same Player.
     
    Last edited: Oct 25, 2018
  36. Miguelfanclub

    Miguelfanclub

    Joined:
    Jun 14, 2015
    Posts:
    64
    Hi guavaman,

    I have successfully map the game pad to my game: left stick to move character, right stick to move the camera clamping values to do a mouselook effect. Buttons are also working perfectly.

    Now, in order to do an easy implementation of the UI, id like to map the right stick to the mouse, and buttons for the right and left click. I mean, fully controlling the mouse with the pad.

    I have a joystick map created, but I dont know how to set cursor movement using the sticks.

    Im using playmaker.

    Thanks.
     
  37. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    You cannot do this through Rewired:
    FAQ - Can Rewired set the mouse cursor position?

    The only feature Rewired offers like that is Player Mouse which can be used to move a sprite cursor, not the OS cursor:
    http://guavaman.com/projects/rewired/docs/RewiredStandaloneInputModule.html#player-mouse
     
  38. greengremline

    greengremline

    Joined:
    Sep 16, 2015
    Posts:
    183
    Hey is it possible to assign multiple actions to the same mouse button? I've tried separating via action category and map category, but I'm still getting a conflict message in the control mapper that "Right mouse button" is already assigned
     
  39. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    Conflict checking rules are up to you to determine:
    http://guavaman.com/projects/rewired/docs/ControlMapper.html#conflict-checking
     
  40. canis

    canis

    Joined:
    Oct 25, 2013
    Posts:
    79
    Hi, I was looking for a way to implement the "mapping button screen" with 3D gamepad controller.

    Question :
    Is there a way to bind the gamepad button/axis information instead of actionID ?
    • I want to display a mapping action label on that 3D gamepad mode.
    • player should always saw the button on screen are representing the real result (real controller)



    I found Player.controllers.Joystick + , may contain the information that I want.
    however I'm not sure how to display it on my 3D gamepad model.

    Code (CSharp):
    1. if (m_Player.controllers.joystickCount > 0)
    2. {
    3.     var joystick = m_Player.controllers.Joysticks[0];
    4.     string report = string.Empty;
    5.     foreach (var ele in joystick.Elements)
    6.     {
    7.         report += "id : " + ele.id + " : " + ele.name + ", type " + ele.type +"\n";
    8.     }
    9.     Debug.Log(report);
    10. }
    and I got the information like this....

    may be I just asking a silly question....
    you see, I only have a GameSir gamepad, which mean I'm not sure what if player use other type of gamepad.
    and how can I handle the gamepad layout on screen... I assume most of player using the gamepad llike what I display in the video.
    any suggestion for that ???
     
  41. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    Joystick Elements do not contain any display-friendly information. The ActionElementMap binding contains many convenience properties to get information. Other information not directly available through convenience properties can easily be obtained by using the binding information to look up the information in the Joystick. The Element Identifier is where display-friendly names come from. ActionElementMap.elementIdentifierId is the id of the Element Identifier on the Joystick bound to the Action.

    You can look at all the examples I've provided that tell you how to show information to the user about controls:
    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

    There are many complete examples included with Rewired that also show how to work with and display controller element information:
    http://guavaman.com/projects/rewired/docs/Examples.html#simple-control-remapping
    http://guavaman.com/projects/rewired/docs/Examples.html#control-remapping-1
    http://guavaman.com/projects/rewired/docs/ControlMapper.html

    There is an example included specifically for showing glyphs and names on gamepad elements in a generic Gamepad Template fashion:
    http://guavaman.com/projects/rewired/docs/Examples.html#gamepad-template-ui
     
    canis likes this.
  42. canis

    canis

    Joined:
    Oct 25, 2013
    Posts:
    79
    it's awesome !!!
    I was an idiot delete all example since 2016.... not even try to import them.
    thanks buddy..
     
  43. GordGames

    GordGames

    Joined:
    Nov 7, 2016
    Posts:
    32
    Hi @guavaman,

    I just got rewired today, really liking it, except I'm having a weird display problem. I think I setup the controller mapping properly, because the game uses them when playing. But when I bring up the Control Mapper in game and it shows the first section ok, but doesn't show any of the other keyboard sections, even if it's listed in the debug section.

    In the image, you *should* see two keyboard keys in the dragon section, but they're empty.

    Screenshot:
    Capture.PNG

    Unity: 2018.2.13
    Rewired: 1.1.19.9.2018
     
  44. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    Because you have two Controller Maps, one "Ayre" and one "Dragon" and are only viewing a single Controller Map in the view. You cannot see multiple Controller Maps at the same time for a single controller type. The page "Ayre" is showing you only the mappings in the "Ayre" Controller Map. The mappings in the "Dragon" Controller Map are not displayed. You have chosen what Controller Map Categories to display in the inspector of Control Mapper. You have chosen to display "Ayre", "Camera", and "Photo Mode." You have not chosen to display "Dragon" and therefore nothing in the "Dragon" Map Category will be shown. You either must add "Dragon" to the list of Map Categories to display or move your "Dismount" and "Start Flying" bindings to the "Ayre" Controller Map.
     
  45. GordGames

    GordGames

    Joined:
    Nov 7, 2016
    Posts:
    32
    Ahh! That's working fine now. I thought you could show multiple maps together in a list. Thank you very much for the quick reply!

    Gord
     
  46. fatality674

    fatality674

    Joined:
    Nov 1, 2012
    Posts:
    24

    I basically have two separate inputs coming in as joysticks. If I can't have both going into the same control map, and InputMapper only allows one control map at a time; Does that mean I can't use control maps for what I am trying to do?

    I'm happy with assigning them one by one which I have managed to do. But this obviously results in 2 control maps. I get what you are saying with that and understand why that is done. This part is working fine.

    I have tried getting input directly from the player and even then I'm having issues receiving input from both sources.

    Below is an example of what I am talking about,


    public void Update()
    {
    _player = ReInput.players.GetPlayer(0);

    if (_player == null) return;
    if (_player.GetButtonDown("ButtonThatDoesSomething"))
    {
    Debug.Log("Input from controller Two");
    }
    if (_player.GetAxis(0) != 0.0f)
    {
    Debug.Log("Input from controller One");
    }
    }


    The actions exist, if both controllers are plugged in, only one input will be picked up. If I unplug that controller, the other input will now be able to be picked up.

    When I debug the player, it shows it has both joysticks assigned to it correctly.

    What am I doing wrong?

    Cheers
     
  47. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    What you are describing will definitely work. Rewired's Player-Action system was designed to do exactly this -- combine inputs from an infinite number of sources into a single interface. Input values coming from multiple input devices, multiple elements on those input devices, applied to one or more Actions, etc.

    The only possible way I can imagine this not working is if there's something failing at the low level with your two devices attached, not related to the Player-Action system.

    You need to verify the input values are coming in on each Joystick at the Controller level.

    Open:
    Debug Information -> Controllers -> Joysticks -> THE JOYSTICK -> Buttons/Axes (depending)

    Click back in the game window and start pressing buttons and moving axes. Do the values change in Debug Information?

    Do the same for the other joystick.

    If you see values not coming in anymore for one joystick when the other is plugged in, then there is some kind of unknown conflict going on. I'll wait to hear your results before continuing.
     
    Last edited: Oct 29, 2018
  48. drumen

    drumen

    Joined:
    Oct 26, 2017
    Posts:
    1
    Hi Guavaman,

    we are curentlly using Rewired 1.1.5.3.U5 and we need to upgrade to latest one (1.1.19.9 (current)
    released Sep 11, 2018) because of support for OculusGo. We followed the instrustion steps and succesfully updated the Revired to 1.1.19.9 but we now get errors that the same Rewired classes are in both, Core and Scenes. And they really are. After update some of Rewired files appeared in both, Core and Scene.

    Are you aware of this problem and is there a workaround or any other solution.

    Regards.
     
  49. Wikzo-DK

    Wikzo-DK

    Joined:
    Sep 6, 2012
    Posts:
    83
    Is it possible to use the HD Rumble features of the Nintendo Switch while using Rewired? (as in setting both high and low frequencies of each rumble motor on e.g. a Joy-Con)
     
    Last edited: Oct 30, 2018
  50. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    I don't understand what you are referring to by "Core" and "Scene." There is no folder called "Core" or "Scene" in the entire Rewired structure, nor are there namespaces or classes with those names. If you've modified the structure or moved files/folders around within Rewired's folder, delete the entire thing and reinstall Rewired.

    http://guavaman.com/projects/rewired/docs/Troubleshooting.html#clean-reinstall

    An upgrade following these instructions with an unmodified Rewired installation would not result in any errors, even if updating from Rewired 1.0.0.0 to the latest:

    http://guavaman.com/projects/rewired/docs/Updating.html

    Rewired does not have any explicit support for OculusGo.
     
    Last edited: Oct 30, 2018