Search Unity

Rewired - Advanced Input for Unity

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

  1. James_FallenTreeGames

    James_FallenTreeGames

    Joined:
    Sep 30, 2016
    Posts:
    16
    Hi,

    We have been using Rewired on our game which has been released on PC + console, and Rewired has been an amazing plug-in, thanks!

    We are having an issue with a small amount of our PC players, where they can't use the mouse on our UI screens. The hover over doesn't work when over standard Unity UI buttons, and clicking the buttons doesn't do anything either.

    All through development and for the majority of our players it's working fine, but for a small number we can't figure out what is going wrong. I just wondered if you'd heard of this before, or I don't suppose you have any ideas?

    Unfortunately we have been unable to reproduce the issue in our office, or I'm sure we would have figured it out much sooner.

    Thanks in advance, and thanks again for an amazing plugin.
     
  2. James_FallenTreeGames

    James_FallenTreeGames

    Joined:
    Sep 30, 2016
    Posts:
    16
    Turns out we had 'Allow Mouse Input If Touch Supported' unchecked, I believe we unticked this to help with an issue on a console version, and had missed leaving it enabled on PC.
     
  3. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    Glad you figured it out and that you've been happy with Rewired!
     
  4. alexr1221

    alexr1221

    Joined:
    Mar 5, 2016
    Posts:
    70
    Hello,
    After upgrading to Unity 2019.1, I get these errors at the beginning which prevents the code to compile:

    Code (CSharp):
    1. Assembly 'Library/ScriptAssemblies/Assembly-CSharp.dll' will not be loaded due to errors:
    2. Reference has errors 'Rewired_Core'.
    3.  
    4. Assembly 'Library/ScriptAssemblies/Assembly-CSharp-Editor.dll' will not be loaded due to errors:
    5. Reference has errors 'Assembly-CSharp'.
    6.  
    7. Assembly 'Assets/Rewired/Internal/Libraries/Editor/Rewired_Editor.dll' will not be loaded due to errors:
    8. Unable to resolve reference 'UnityEngine.UI'. Is the assembly missing or incompatible with the current platform?
    9. Reference validation can be disabled in the Plugin Inspector.
    10.  
    11. Assembly 'Assets/Rewired/Internal/Libraries/Runtime/Rewired_Core.dll' will not be loaded due to errors:
    12. Unable to resolve reference 'UnityEngine.UI'. Is the assembly missing or incompatible with the current platform?
    13. Reference validation can be disabled in the Plugin Inspector.
    14.  
    15. Assembly 'Assets/Rewired/Internal/Libraries/Runtime/Rewired_Windows.dll' will not be loaded due to errors:
    16. Reference has errors 'Rewired_Core'.
    I tried to:
    - Remove Assembly-CSharp.dll and all the others from Library
    - Remove and reinstall rewired
    - Switch from NET 4.x to 2.0

    With no success.

    Do you know how to fix this?
    Thanks
     
  5. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    Is this 2019.1 or 2019.2? You state 2019.1 but these errors should only show up in 2019.2. This is due to a major breaking change in the Unity UI system and is not possible to fix. See more here:
    https://forum.unity.com/threads/ui.673504

    If you have installed some preview/beta Unity UI package, uninstall it. Unity has acknowledged this as an error and is in the process of figuring out some way to fix this so all packages that reference UnityEngine.UI do not break. There is no way to make this work at this time.
     
  6. alexr1221

    alexr1221

    Joined:
    Mar 5, 2016
    Posts:
    70
    Thanks for the reply! I'm indeed using 2019.2b. 1 month ago I decided to move to beta in order to see if a bug would disappear. In the meantime, I paused the project and did a lot of things, and then when I came back to the project I mingled the old bug with this one.
     
  7. jmdeb

    jmdeb

    Joined:
    Jul 28, 2017
    Posts:
    23
    Hi,
    I'm using the "Rewired\Examples\SimpleControlRemapping\Scripts\SimpleControlRemapping.cs" script, with slight additions to suit my needs.
    ...but I'm facing a little problem and would like your advises if you don't mind!

    In my 'remap' panel, user can modify the keys used inside the game and/or inside the UI.
    Here's the problem I'm facing.
    1. The default key for 'Submit' is 'Return'
    2. So, to remap this same 'Submit' key the user presses 'Return' on the keyboard, the script waits for the key, the user type the new key.
    3. The user choose to map it to another modifier key like 'L-Ctrl'
    4. So, for the next key to remap the user will have this time to press 'L-Ctrl' (the new 'Submit' key) to enter the new key...
    5. ...but if he does so, it's like there's no wait mode* and the 'L-Ctrl' is directly accepted as the new key!!



    * actually, when capturing to gif to send you the images I could see that the script is entering the 'wait' mode (5a) but the 'L-Ctrl' key is directly injected as the new key (5b)!

    Hope that I'm clear. In summary, if one choose to map the 'Submit' action to Ctrl or Alt, once you press those keys to enter the remapping process the key acts as 'Submit' in one frame then is injected as the new key!
    This only happens with Ctrl and Alt keys.
    Thank you in advance for your assistance with this.
     
  8. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    I cannot reproduce any problem with this using the SimpleControlRemapping example.

    What you state cannot happen if you have left the default settings of having a minimum timeout before accepting a modifier key:
    http://guavaman.com/projects/rewire...DurationToMapKeyboardModifierKeyAsPrimary.htm

    If you have changed this, it may cause this to happen.

    In addition, line 221 of SimpleControlRemapping.cs prevents the key bound to Submit from triggering as the key to bind:

    Code (csharp):
    1. yield return new WaitForSeconds(0.1f);
    Disabling options.allowKeyboardKeysWithModifiers may also have this effect.

    Code is going to have to be changed in Input Mapper to require the key be down for modifier keys if you have changed either of those options so no time is required to trigger a modifier key.
     
    Last edited: May 28, 2019
  9. jmdeb

    jmdeb

    Joined:
    Jul 28, 2017
    Posts:
    23
    Thanks for your quick reply! You're absolutely right...my mistake, I had set holdDurationToMapKeyboardModifierKeyAsPrimary to 0
    Sorry..and thanks for the great support!!
     
  10. Casder

    Casder

    Joined:
    May 14, 2019
    Posts:
    4
    Hey guavaman!
    I have an issue with the exported constants that I can't seem to resolve.
    Following the documentation at http://guavaman.com/projects/rewired/docs/HowTos.html#exporting-constants, I have created my constants file.
    In my component class I have then defined
    Code (CSharp):
    1. [ActionIdProperty(typeof(RewiredConsts.Action))]
    2.         public int _rewiredAction;
    But when looking at the component in the inspector in the editor, rather than see the dropdown with all the available actions, it just has the text "No constants found in RewiredConsts.Action."

    Do you have any idea why this is happening?
     
  11. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    That is correct. If you are using some kind of 3rd party inspector system like Odin, it's unlikely to work properly.
     
  12. Casder

    Casder

    Joined:
    May 14, 2019
    Posts:
    4
    Interesting.....I am not using a 3rd party inspector :confused:
    All I am using is Rewired 1.1.22.3.U2018 and Unity 2018.2.2.21f1
     
  13. Roman-Ilyin

    Roman-Ilyin

    Joined:
    Oct 9, 2013
    Posts:
    29
    Hello. The current version of Rewired does not support unity 2019.1.
    ("Rewired: The version of Rewired installed (1.1.26.0.U2018) was not designed for Unity 2019. Please install Rewired for Unity 2019. This warning does not mean that Rewired will not function, but it may not function optimally.")

    When will the new version be available?
     
  14. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    It does and has done so for a long time. Read this:
    http://guavaman.com/projects/rewired/docs/Troubleshooting.html#wrong-rewired-version-installed
     
  15. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    It works in all my testing. Nothing has changed that would affect this.

    Look at your RewiredConsts.Action class in the CS file. Does it include any public integer constants?
     
  16. Casder

    Casder

    Joined:
    May 14, 2019
    Posts:
    4
    Yeah there are constants, I can access and use them in code but the inspector doesn't recognise them.
    This is what my class looks like, the actual version has more actions defined in Default and Menu.

    Code (CSharp):
    1. namespace RewiredConsts {
    2.     public static partial class Action {
    3.         public static partial class Default {
    4.             [Rewired.Dev.ActionIdFieldInfo(categoryName = "Default", friendlyName = "Move Horizontal")]
    5.             public const int Move_Horizontal = 0;
    6.         }
    7.         public static partial class Menu {
    8.             [Rewired.Dev.ActionIdFieldInfo(categoryName = "Menu", friendlyName = "Ready")]
    9.             public const int Ready = 11;
    10.         }
    11.     }
    12. }
     
  17. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    The problem is you have enabled the "Create Action Category Classes" option. This does not work with the property drawer because the parent class does not contain any constants just like it says. This option was added later at the request of a user. It was never tested with the property drawer and obviously cannot work unless the code is changed significantly to search the assembly class for nested classes within the parent class and parse all of those for constants.
     
    canis likes this.
  18. Casder

    Casder

    Joined:
    May 14, 2019
    Posts:
    4
    Ah! Yeah that worked :) Thanks for your help, I really appreciate it. It's really cool that you are so active with helping everyone out :)

    Again, thanks :D
     
  19. mmvlad

    mmvlad

    Joined:
    Dec 31, 2014
    Posts:
    98
    Hi @guavaman
    how would you suggest to manage input state with rewired?
    E.g. you have input map for dialog 1, dialog 2, dialog 3. Dialog 3 can be opened from dialog 1 or 2.
    So after dialog 3 is closed you must enable input map for underlying dialog.
     
  20. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    You keep track of your game state(s) in your code and enable/disable the Controller Maps based on the current state(s) that should be enabled. Your state(s) in your code should control Rewired's Controller Maps, not the other way around.
     
  21. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    Glad it works! I will see if it makes sense to change that in a future update.
     
  22. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    522
    I read somewhere that the time taken when pressing Play in the editor can be improved by deleting some mappings or something, but I can't find that text again. Can someone please let me know how I can speed up the Editor Play startup time?
     
  23. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
  24. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    So I setup some keyboard input mapping and noticed that when a conflict is found rewired fires the event for the key that was pressed. Is there a way to stop that behavior?
     
  25. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    No it doesn't. You must either have multiple bindings for that key/button or your have multiple Players with the same keyboard bindings and it's finding a conflict on the other Player's Controller Maps. It would also conflict if you have another Controller Map in another Map Category loaded such as UI if the Map Category of the Controller Map you're trying to modify is set to conflict with all other Map Categories.
     
    Last edited: Jun 3, 2019
  26. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    I have a single player with a single keyboard map. SYSTEM I never touched it has no maps.

    It's also happening when it maps to the same element. It's like if it doesn't remap then it fires.

    I'm creating the context and input mapper myself. I'm positive there are not multiple bindings in the config. Now it's possible I'm creating them in my mapping flow somehow, if only temporarily? Or maybe doing something in a different order from your built in control mapper or not doing something you are.
     
  27. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    Reading your original message, I realize there are a number of ways one could read it. I don't understand what you're saying is happening. Can you please explain exactly what is happening in sequence and which "event" you're referring to firing?

    The way I understood what you said:
    When rebinding an Action to the same key, the Input Mapper conflict found event fires.

    Now when I re-read it, I am reading it as:
    When rebinding a key, the key's input Action event (ButtonDown) fires when a conflict is found.

    "Event" is ambiguous. It could refer to an input Action event, the Input Mapper conflict found event, or some other event.

    Please try Rewired/Examples/ControlRemapping1 and see if it does the same thing you are describing.

    View all the live objects in Rewired using Debug Information to see what Keyboard Maps are loaded in your Player:
    http://guavaman.com/projects/rewired/docs/Troubleshooting.html#debug-information
     
  28. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    Ok so more specifically, what I mean by event is this delegate I have setup for keyboard events.

    Code (csharp):
    1.  
    2. RewiredPlayer.AddInputEventDelegate(OnInput, UpdateLoopType.Update, InputActionEventType.ButtonJustPressed);
    3.  
    When the input mapper fires ConflictFoundEvent, the above is also fired. Which could be completely normal and I'm expected to ignore it myself. Or there is something else I'm missing.
     
  29. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    FYI 2019.1.5f1 changed Selectable.AllSelectablesNoAlloc to not take a ref var.
     
  30. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    A breaking API change in a minor version release... I pointed out the fact that the "ref" keyword on this function was useless when 2019.1 was still in beta.
     
    Last edited: Jun 4, 2019
  31. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    Player input events are fired regardless of what else you're monitoring (polling) if the Controller, Controller Maps, and Action Element Maps are enabled. That is the expected behavior.
     
    Last edited: Jun 4, 2019
  32. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    This is wrong and should not happen. Unity needs to implement far better standards when it comes to API changes in releases. The compiler symbols they provide do not allow you to make #if statements to differentiate different minor version updates and newer, hence they should not be making API changes in minor releases. #if UNITY_2019_1_OR_NEWER cannot be used. They do not provide a UNITY_2019_1_5_OR_NEWER symbol, so this cannot be cleanly made into a conditional statement. Now it has to be a ridiculous structure like this:

    Code (csharp):
    1. #if UNITY_2019_1_OR_NEWER
    2. #if UNITY_2019_1_0 || UNITY_2019_1_1 || UNITY_2019_1_2 || UNITY_2019_1_3 || UNITY_2019_1_4
    3.             selectableCount = Selectable.AllSelectablesNoAlloc(ref s_reusableAllSelectables);
    4.             allSelectables = s_reusableAllSelectables;
    5. #else
    6.             selectableCount = Selectable.AllSelectablesNoAlloc(s_reusableAllSelectables);
    7.             allSelectables = s_reusableAllSelectables;
    8. #endif
    9. #else
    10.             allSelectables = Selectable.allSelectables;
    11.             selectableCount = allSelectables.Count;
    12. #endif
    There's a reason API changes should only be made in non-minor version update.
     
  33. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    Debugging this issue more deeply, this change is not what caused your editor stepping to not work. Did this ever work? What version were you using previously? I've tested old versions back to 1.1.21.0 and pressing buttons while paused does not yield values when unpaused/stepped.
     
  34. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    522
    How can I cause an Action using a script?

    For example, my game has a cockpit with an Eject switch. I have an Action and a Joystick Map working, and pressing the button on the joystick causes player.GetButtonDown("Eject") to return true.
    Now I would also like the player to be able to click on the switch with the mouse, and have any GetButtonDown("Eject") return true. I can raycast and detect when the switch has been clicked on, but how do I trigger the Eject button action from a script?

    If there's a different way I should be going about this, please let me know :)
     
  35. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    Custom Controllers:
    http://guavaman.com/projects/rewired/docs/CustomControllers.html

    This is the only way to input a value into the Player-Action system.
     
  36. The_BenEvans

    The_BenEvans

    Joined:
    Jul 31, 2012
    Posts:
    139
    My project imploded for a day when I tried updating to 2019.1.5f. Managed to save it by reverting it to an earlier Cloud version. Occured to me to look on here today with that "ref" error, so I'm glad it's got a workaround, project works again! Thanks
     
    guavaman likes this.
  37. jason07

    jason07

    Joined:
    May 10, 2011
    Posts:
    34
    Hi,

    I want to get the binding of a key so it can be displayed in-game in a UI. The player can change the binding through Control Mapper and I want the UI to update if the player makes a change to this key binding. For example, by default moving forward is done by pressing "W" and the UI will display "W", but if the player changes this to "G" for example then the UI will display "G".

    I'm using the Playmaker action "Rewired Action Element Map Get Keyboard Key Code" and am using an integer variable with the ID (in the attached pic it is the unique value 2405) as the Action Element Map ID to identify the binding. I can display values fine in the UI, the trouble I run into is the ID changes between game sessions so the displayed binding will change. Is there a way I can use another value to identify the key binding instead of the unique ID? It seems like the Action Element Map ID only responds to the unique ID.

    Or is there a way to get the unique ID by using a static value, like the Element ID, and passing that into in Playmaker? It seems most Playmaker actions associated with getting values require the unique ID as the Action Element Map ID. I tried using the "Rewired Player Get First Element Map ID with Action" action and that almost works for getting the unique ID, the problem I run into there is I can't tell it to look for the positive or negative value of the action.

    Thanks
     

    Attached Files:

    Last edited: Jun 13, 2019
  38. zKici

    zKici

    Joined:
    Feb 12, 2014
    Posts:
    438
    I'm probably a dummy for asking this, but I've been on your documentation and I have gotten to the part of:

    action.positiveDescriptiveName
    action.negativeDescriptiveName

    However I actually need the key mapped to the negative Action not just the positive key.

    Please help me with the code to get that (also no lists just a single negative keymap similarly to the GetFirstButtonMapWithAction)

    NOTE: I did go through the documentation part where it does the
    foreach(ActionElementMap aem in player.controllers.maps.ButtonMapsWithAction(ControllerType.Keyboard, "Vertical", false)) {

    But I need to assign the 1st Positive KeyMap and 1st Negative KeyMap to a variable for future use as a token on a dialogue... and I do not know how to do that in the foreach loop as it spits out a few even 2nd modifiers and such,

    Thank you
     
    Last edited: Jun 13, 2019
  39. slimshader

    slimshader

    Joined:
    Jun 11, 2013
    Posts:
    187
    Hey getting
    Code (csharp):
    1.  
    2. Assets\Rewired\Extras\ControlMapper\Scripts\UISelectionUtility.cs(39,68): error CS1615: Argument 1 may not be passed with the 'ref' keyword
    3.  
    just after importing latest in unity 2019.1.5f1
     
  40. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    guavaman likes this.
  41. slimshader

    slimshader

    Joined:
    Jun 11, 2013
    Posts:
    187
  42. jason_yak

    jason_yak

    Joined:
    Aug 25, 2016
    Posts:
    531
    Hi there,

    I was just wondering (might be jumping the gun here) but with the announced support of DS4 and Xbox One S controllers coming to iOS13, I just wondering roughly when we could expect support to be added? I’m not sure if the new features are available to the iOS13 beta yet or not, but I imagine there’s going to be some updates to the MFI profiles.

    Any info on this topic so we can prepare for the upcoming controller ahead of iOS13 release would be greatly appreciated, thanks!

    Jason
     
  43. jason_yak

    jason_yak

    Joined:
    Aug 25, 2016
    Posts:
    531
    Ps: looks like the controllers do already connect in iOS13 beta. I’ve not tried myself but it sounds like many devs have already been able to connect.
     
  44. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    No, there is no such thing as a static Action Element Map Id. The only way to get an Action Element Map is via some kind of selector that finds it based on some criteria. This is what all the GetFirst... functions do in the scripting API. They allow you to find a specific Action Element Map based on selection criteria. Either that or you have to iterate over all of them to determine which one you want.

    PlayMaker does not have access to the controller remapping API. There are just too many functions and too many nested objects and passing of objects around to make this work with PlayMaker. The Action Element Map actions require a unique id because this is the only way to get the Action Element Map on which to work. In the scripting API, you simply get the Action Element Map object and access various functions or properties on it, whereas PlayMaker has to get the Action Element Map object every time using the unique id in order to access any properties on the object. This is a limitation of PlayMaker.

    If you want to build a controller remapping system, do it through scripting, not PlayMaker actions.
     
  45. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    Every piece of information regarding bindings is in the Action Element Map. Look at the API reference:
    http://guavaman.com/projects/rewired/docs/api-reference/html/T_Rewired_ActionElementMap.htm

    There is no convenience function in Player to find the first element binding that binds to the negative pole of an axis. If you have such specific selection needs, you have to find it yourself manually by iterating the Action Element Maps searching for your chosen criteria.

    The ActionElementMap properties determine what Action and what range of the Action the element is bound to. Check the properties and branch based on whether it's an axis or button binding, and if axis, what the axis range is, if button, what the axis contribution is.

    Many complete binding examples are provided:
    http://guavaman.com/projects/rewired/docs/Examples.html
     
  46. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    This is also at the top of the documentation landing page:
    http://guavaman.com/rewired/docs
     
    slimshader likes this.
  47. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    Rewired has zero native code on iOS. See here:
    http://guavaman.com/projects/rewired/docs/Overview.html#tested-platforms

    Support for these controllers cannot possibly be added until Unity adds support for them.
     
  48. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    Due to high support volume, responses may be delayed. All messages will be answered in the order they were received. Thanks!
     
  49. mmvlad

    mmvlad

    Joined:
    Dec 31, 2014
    Posts:
    98
    Hello @guavaman ,
    is it possible to add controller maps/action categories/actions and other elements from editor script?
     
  50. Michael316

    Michael316

    Joined:
    Aug 2, 2012
    Posts:
    21
    Are there any obvious things I should check if my scene is working in the editor but not in a Windows build player? It's just the clicking of buttons - mouse movement works, but no buttons will register clicks.

    I realize this is very limited info, but before I get into the details I thought I'd check if I'm making a common (noob) mistake. Thanks!

    EDIT: Hover isn't working either, but only in the standalone player. Added info - I'm using a PointerCanvas to move the mouse pointer with either mouse or joystick. Again, everything works perfectly in the editor, but only movement works in the player (click and hover do not).
     
    Last edited: Jun 19, 2019