Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Rewired - Advanced Input for Unity

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

  1. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,185
    The examples included in Rewired are not designed to be dropped-in-and-used in your projects. They are there strictly to show you examples how to code to get some result. If you try to use any of the examples in Rewired as part of your game without knowing exactly how they're working, you're just going to have problems. And the examples are never complete implementations either. For example, the PressStartToJoin example makes no accommodation for a Player leaving the game.

    If you are just copying the structure of the example scripts, this is most likely a Player Id problem. Your PlayerShip 1 and PlayerShip 2 must be assigned different "game player ids."

    The problem could also be something else entirely. Use Debug Information to view Player and controller information. If both Controllers are assigned to the same Player, it would explain what you are describing:
    https://guavaman.com/projects/rewired/docs/Troubleshooting.html#debug-information
     
    Last edited: Mar 9, 2020
  2. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,185
    Rewired 1.1.30.2 is available on the Unity Asset Store.

    See Updating Rewired before updating.

    Release Notes:

    1.1.30.2:

    Changes:
    - Input is no longer blocked when application is in full-screen mode and "Ignore Input When App Not In Focus" is disabled due to problems with Steam and VR games.
    - OSX Native: Added support for HID devices with multiple logical sub devices (some multi-port controller adapters including Mayflash GameCube contorller adapters).
     
  3. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,185
    Last edited: Mar 10, 2020
  4. Verdante

    Verdante

    Joined:
    May 22, 2017
    Posts:
    15
  5. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,185
  6. Flishwap

    Flishwap

    Joined:
    Mar 26, 2014
    Posts:
    2
    Hi @guavaman!

    I wanted to ask if you could show me a very basic example of how to use:
    AddLastActiveControllerChangedDelegate(ActiveControllerChangedDelegate, ControllerType)

    I have been programming for a few years but I only started using delegates since my team recently bought your amazing Rewired extension. I've been fine using AddInputEventDelegate functions but I can't seem to find an example showing the above function in use in your documentation. Hoping you can help me out, thanks!
     
  7. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,185
    Delegates in Rewired are no different than any other delegates in C#. I suggest you read about C# delegates to understand them and don't rely on an input plugin's documentation to provide you examples on how to use aspects of the C# languages you don't understand.

    https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/delegates/

    Code (csharp):
    1. void Awake() {
    2.     ReInput.controllers.AddLastActiveControllerChangedDelegate(OnLastActiveControllerChanged, ControllerType.Joystick);
    3. }
    4.  
    5. void OnLastActiveControllerChanged(Controller controller) {
    6.     // Do something
    7. }
    There is very little reason to use the overload that you have chosen that takes a ControllerType. This will never change for Keyboard or Mouse because there can be only one of each and is only useful to tell if the last active Joystick or Custom Controller changed. It is very unlikely you want to use this overload. Use the one that does not take a ControllerType argument:

    https://guavaman.com/projects/rewir...er_AddLastActiveControllerChangedDelegate.htm
     
  8. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,185
    Another update. Looks like they fixed the button bug but broke Left Stick X with the fix. :mad: (Or perhaps the left stick was already broken as well before but not fixed? Not sure.)

    A customer reported Left Stick X not working anymore on iOS/tvOS 13 2019.3.4f1, which is the version in which the Pause/Menu button fix was made according to the bug tracker.

    A workaround was posted here by @Benzor. I cannot understand why this fix would have anything to do with the left stick X value since these lines of code he commented out are related to buttons. It looks like there's a button/axis id mixup somewhere deeper in the code.
     
    Last edited: Mar 11, 2020
  9. Raidenwins

    Raidenwins

    Joined:
    Dec 18, 2012
    Posts:
    118
    I am having a hard time getting Cinemachine to work with Rewired. I've read the Cinemachine integration in the Rewired documentation, but so far no luck. The problem is that when I press the Up Arrow or Down Arrow buttons (for vertical movement) they control the camera (Free Lookup Cinemachine camera), in addition to making the character move, and the camera gets stuck either at the top or the bottom. Here is my set-up, I've named the horizontal and vertical actions "Mouse X" and "Mouse Y" to match the Cinemachine axis names:

    This is the actions declaration:

    Rewired_Cinemachine_Question_1.png

    Rewired_Cinemachine_Question_2.png

    Next is the keyboard map:

    Rewired_Cinemachine_Question_3.png Rewired_Cinemachine_Question_4.png Rewired_Cinemachine_Question_5.png

    In the Rewired Cinemachine Bridge I've mapped "Mouse X" to "Mouse X" and "Mouse Y" to "Mouse Y".

    What is the problem here?
     
  10. Raidenwins

    Raidenwins

    Joined:
    Dec 18, 2012
    Posts:
    118
    Here is what my Rewired Cinemachine Bridge looks like:

    Rewired_Cinemachine_Question_7.png
     
  11. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,185
    Sounds to me like it's working. If it weren't, your camera wouldn't be moving.

    What are you expecting to happen?
    1. You assigned "Mouse X" to Left/Right and "Mouse Y" to Up/Down Arrow.
    2. The camera is moving when you press Up/Down Arrow as you stated. This is what is supposed to happen.
    3. Whether or not your character moves has nothing to do with the Cinemachine controls. That's entirely dependent on whatever script you're using to move your character. It's getting input somehow, but I have no information on that. If your character movement script is even using Rewired, it's probably getting input from some other Action that is not shown in those pictures, and it's very likely that Action is also bound to Up/Down Arrow.
    4. The Cinemachine bridge does absolutely nothing but pipe input into Cinemachine from Rewired instead of UnityEngine.Input. It does not do any automatic management of Controller Maps or anything else. If you have Controller Maps for your character movement that need to be disabled when using Cinemachine, you have to manage that as usual.
    5. Whether or not the camera gets stuck has nothing to do with Rewired. Rewired provides the input. The Cinemachine script interprets that input and moves the camera. If it's getting stuck, it's Cinemachine or some other script on your camera doing it.
    Debug Information: How to find the source of the problem:
    https://guavaman.com/projects/rewired/docs/Troubleshooting.html#debug-information
     
    Last edited: Mar 12, 2020
    Raidenwins likes this.
  12. Flishwap

    Flishwap

    Joined:
    Mar 26, 2014
    Posts:
    2
    @guavaman! I'll be sure to read up on them but in the mean time thanks so much for your help! I got up and running perfectly. Thanks again :D
     
  13. Max_Lag

    Max_Lag

    Joined:
    Oct 18, 2018
    Posts:
    7
    Hi, not sure if I'm using the feature correctly (99% chance I'm wrong)

    I got Controller Rules Set disabling working with this :

    Code (CSharp):
    1.  
    2. foreach (ControllerMapEnabler.RuleSet ruleSet in m_player.controllers.maps.mapEnabler.ruleSets)
    3.         {
    4.             if (ruleSet.tag == "My fancy tag containing rules to disable some controls")
    5.             {
    6.                 ruleSet.enabled = isActive;
    7.             }
    8. }
    But I find this not very handy / nice and don't understand why the following (based on what I found in the doc) is not working :

    Code (CSharp):
    1.  
    2. // Load an instance of the Rule Set
    3. var ruleSet = ReInput.mapping.GetControllerMapEnablerRuleSetInstance("RuleSetName");
    4.  
    5. ruleSet.enabled = false;
    6.  
    7. // Apply the changes to the Player's Controller Maps
    8. m_player.controllers.maps.mapEnabler.Apply();
    9.  
    Any hints / ideas on that ?
    Or maybe disabling some maps / categories is not supposed to be achieved like that ? However I've read that directly disabling with code controller maps is not persistent...

    Thanks !
     
  14. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,185
    You can't load a new instance of a Rule Set and have that automatically apply to a Player. Loading an instance from the Rewired Input Manager is making a new copy of a Rule Set. That Rule Set is owned by nobody. The example you pulled that code from in the documentation shows loading a rule set by creating an instance, assigning that to the Player's list, then applying the change.

    I don't understand why you think managing rule sets by iterating a list is not handy or nice. You have complete control over that List and can process it with whatever List processing tools and extension methods you want. You can use handy tools like Linq and predicates to target the rules you want to change. In my opinion, this is far more handy and nice than being forced to look through a giant list of convenience functions to find and/or change state of rules based on a very large number of criteria.

    Code (csharp):
    1. List<ControllerMapEnabler.RuleSet> list = player.controllers.maps.mapEnabler.ruleSets;
    2.  
    3. // Enable a specific Rule Set by tag
    4. list.Find(item => item.tag == "My Tag").enabled = true;
    5.  
    6. // Linq set enabled state of all Rule Sets
    7. list.ForEach(item => item.enabled = false);
    8.  
    9. // Apply the changes
    10. player.controllers.maps.mapEnabler.Apply();
    There's far more you can do with Lists making them very convenient to work with. This is just basic C# and not specific to Rewired.
     
    Last edited: Mar 12, 2020
  15. sultanwalid

    sultanwalid

    Joined:
    May 5, 2011
    Posts:
    27
    Hello @guavaman I have a quick question, is it possible to assign (in code) keyboard to other players because it is always detected as the first player?
    I have tried
    Code (CSharp):
    1. ReInput.players.GetPlayer(i).controllers.Keyboard.enabled = true;
    thank you
     
  16. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,185
    There is a single Keyboard Controller. Changing the enabled state on the Keyboard changes it system-wide. This is not correct.

    Players must be assigned Controllers for them to contribute to input. All the information you need is right here in the documentation:
    https://guavaman.com/projects/rewired/docs/HowTos.html#assigning-controllers
     
    sultanwalid likes this.
  17. sultanwalid

    sultanwalid

    Joined:
    May 5, 2011
    Posts:
    27
  18. gearedgeek

    gearedgeek

    Joined:
    Jun 19, 2015
    Posts:
    177
    Was the game play example for the gamepad removed?
     
  19. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,185
    I don't know what you're referring to. No examples were removed
     
  20. gearedgeek

    gearedgeek

    Joined:
    Jun 19, 2015
    Posts:
    177
    I remember a demo that had Ethan in a scene where you could pick up items and it showed the inventory, etc..
     
  21. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,185
    There was never an example like that in Rewired.
     
  22. gearedgeek

    gearedgeek

    Joined:
    Jun 19, 2015
    Posts:
    177
    Was that part of a intergration?
     
  23. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,185
    I never made any scenes like that. If it was, it was simply part of the package itself like Opsive's Third Person Controller or something. I haven't added or removed anything from the integrations.
     
  24. gearedgeek

    gearedgeek

    Joined:
    Jun 19, 2015
    Posts:
    177
    So I figured what it was. Inventory Pro was the example I was thinking of. Sorry about the confusing.
     
  25. Max_Lag

    Max_Lag

    Joined:
    Oct 18, 2018
    Posts:
    7
    OK, thanks for the hint.
    I guess I've misunderstood documentation. Seeing methods like "GetControllerMapEnablerRuleSetInstance", I thought there would be a direct getter for ruleSets. List is ok (linq is not, by the way, and should be avoided but I won't debate ^^), and works perfectly fine, just wanted to have confirmation.

    I'm using the feature to disable a whole set of controls category to avoid my character moving around when opening his inventory, I would like to have your opinion about that : would you use MapEnabler feature to achieve this ?

    Thanks a lot !
     
  26. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,185
    You need to understand the structure of Rewired's classes:

    How To's - Important Classes:
    ReInput.mapping - Controller Map, Action, Input Behavior and other data in the Rewired Input Manager.

    You are using a function in ReInput.mapping. ReInput mapping gives you read-only access to mapping-related data defined in the Rewired Editor stored in the Rewired Input Manager. By definition, Rewired Input Manager data consts of default configurations created by the developer at edit time, not live run time data. Nothing stored in the Rewired Input Manager is directly used at run time. Players are run time objects instantiated on Awake, each Player's local data is instantiated from the configuration defined and stored in the Rewired Input Manager. Once instantiated, every Player exists as its own run time object with self-contained instances of various objects to be used for calculating input. Every Player contains its own instances of Controller Maps, has its own Map Enabler and Layout Managers with their own instances of Rule Sets, etc. This is necessary because each run time Player is an independent entity and can have completely customized settings per-Player, all modifiable by scripts at run time. If you want to change something in a Player, you access it through the Player and its helper classes, not ReInput.mapping. The Player is where run time input is managed, calculated, and consumed. All data that affects a Player's input values are calculated using data (Controllers, Controller Maps, Rule Sets, etc.) that is contained within that Player. By using ReInput.mapping, you are accessing default configuration data from the database that was initially used to populate data in the Player upon initialization, not the live data in the Player, and therefore making changes to that data does nothing to the Player.

    All methods that are titled "GetInstance" create a new instance of a class from the Rewired Input Manager. These methods never give you existing run time instances. This is akin to Object.Instantiate in Unity terminology.

    That's one of the common use case examples mentioned a number of times throughout the documentation. Anything you would enable or disable Controller Maps for, use Map Enabler for. Enabling a UI map and disabling others is a very common use of this.

    https://guavaman.com/projects/rewired/docs/HowTos.html#enabling-disabling-controller-maps
     
    Last edited: Mar 13, 2020
  27. jorge89

    jorge89

    Joined:
    May 28, 2015
    Posts:
    6
    I moved my project from a Mac to a PC with Windows 10 and everything works except controller input. Rewired debugging shows that the joystick is being assigned to player 1, but pressing the buttons on the controller does nothing. Mouse and keyboard controls still work though. Does anyone know what I need to do to fix this?
     
  28. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,185
    This is the only way to find the solution to your problem:
    https://guavaman.com/projects/rewir...l#debug-information-diagnosing-input-problems
     
  29. jorge89

    jorge89

    Joined:
    May 28, 2015
    Posts:
    6
    Thank you for the help. I followed the list and made sure that everything is enabled and mapped as it should. When I got to "Check the live values returned by the Action" the controller would not return any values while the keyboard and mouse did even though everything was assigned to the player. I also assigned the controller to system player and got the same result. The same happened when I got to "Check that the Controller elements are actually returning some value"

    What does this mean?
     
  30. marvalshot

    marvalshot

    Joined:
    Dec 29, 2013
    Posts:
    196
    When switching from standalone to rewired input module it seems like I can't the menu submit and cancel to work.
    UIHorizontal and Vertical work fine.
    I as suggested created new maps and action categories specific to the UI.
    Thanks
     
  31. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,185
    >> The same happened when I got to "Check that the Controller elements are actually returning some value"

    Did you make sure you clicked into the game window before trying to move the sticks and press buttons when testing using Debug Information?

    If no values are returning on the controller elements, there's nothing you will be able to do to fix it. This means the low-level input library is receiving no information from your controller.
    • What controller is this you are using?
    • How is this controller connected to the system?
    • What is the Primary Input Source chosen for the platform in question?
     
  32. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,185
    UI Submit and Cancel do work if everything is configured properly. As always, the only way you're going to debug this is to use the tools provided to determine what is happening and why:
    https://guavaman.com/projects/rewir...l#debug-information-diagnosing-input-problems
     
  33. marvalshot

    marvalshot

    Joined:
    Dec 29, 2013
    Posts:
    196
    I did but having trouble because the stick responds and not the buttons. Guess I'll try again
     
  34. jorge89

    jorge89

    Joined:
    May 28, 2015
    Posts:
    6
    Yes the game window was clicked, and input was being registered for my keyboard and also mouse. It's just controllers not returning any values.
    I've tried using an XBOX one controller over Bluetooth and USB, I've tried using a steelseries Nimbus with USB (so windows recognizes it as a Nimbus) and also using MFIGamepadFeeder so windows sees it as an XBOX 360 controller. When I go to the game controller properties I can see that windows is registering all of the controller inputs.
    Where can I check my Primary Input Source?
     
  35. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,185
    Click the button labeled "Windows" under Platform Settings.

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



    1. Is Primary Input Source set to Raw Input?
    2. Is Use XInput enabled?
    3. Did you enable Unity's new input system by any chance? https://guavaman.com/projects/rewired/docs/KnownIssues.html#not-compatible-unity-new-input-system
    4. Open the scene Rewired/DevTools/JoystickElementIdentifier. This shows values coming directly from Raw Input. Open the Rewired Input Manager in the scene and go to Settings -> Windows -> and disable Use XInput. Press Play. Move the joysticks and press buttons. Do you see anything happening on the screen? Press +/- to cycle through detected controllers.
     
    Last edited: Mar 15, 2020
  36. Raidenwins

    Raidenwins

    Joined:
    Dec 18, 2012
    Posts:
    118
    You are right, since I am still new to Cinemachine I was mixing character controls with camera controls. I was using the inputs for the camera (the Mouse X and Mouse Y actions) in my character controller script and that was causing the problem. All I had to do was create one Mouse Map and one Gamepad Map for the Mouse X and Mouse Y actions, map those to Mouse X and Mouse Y in the Cinemachine Bridge, and everything started working.

    Thank you.
     
  37. trizero

    trizero

    Joined:
    Feb 15, 2014
    Posts:
    13
    I used corgi v6.3 and rewired 1.1.30.3, and the console log
    Assets/Rewired/Integration/CorgiEngine/Scripts/RewiredInventoryHotbar.cs(14,10): error CS0246: The type or namespace name 'InformationAttribute' could not be found (are you missing a using directive or an assembly reference?)
    Assets/Rewired/Integration/CorgiEngine/Scripts/RewiredInventoryHotbar.cs(14,10): error CS0246: The type or namespace name 'Information' could not be found (are you missing a using directive or an assembly reference?)
    Assets/Rewired/Integration/CorgiEngine/Scripts/RewiredInventoryHotbar.cs(14,116): error CS0103: The name 'InformationAttribute' does not exist in the current context
     
  38. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,185
    The Corgi Engine integration was built for Corgi Engine 4. See the integration documentation:
    https://guavaman.com/projects/rewired/docs/Integration.html#CorgiEngine

    Requirements:
    • Corgi Engine v4.0 (No future version compatibility is guaranteed.)
    • Unity 5.6.7f1+
    The author of the engine has obviously made breaking changes to the engine that make it no longer compatible with the Rewried integration.
     
  39. Eldoir

    Eldoir

    Joined:
    Feb 27, 2015
    Posts:
    38
    Hello,
    First of all thank you for this fantastic plugin.
    I tried Unity's new InputManager and it had too many problems, especially regarding local multi.
    Rewired works perfectly!

    I have a question: in my game, I have 2 actions, "Dash" and "Trickshot".
    I actually map the same button for these 2 actions, and performing a Dash or a Trickshot depends on the context: when I press the button, I have to check certain conditions to determine if the player can do a dash or a trickshot.
    The code therefore quickly gets pretty ugly: when I press the button, the scripts verifying the Trickshot action and those verifying the Dash action are triggered at the same time, and each one must verify whether the player is actually doing a Trickshot or a Dash.

    How to do this easily with Rewired?

    I had the impression that the MapEnabler and the Rule sets could allow me to do that: I intended to put the Dash action in a separate category, and the Trickshot action in another category. If I understand the principle correctly, I could then in runtime activate one or the other category depending on the context.

    Is this the right way to do it?
     
  40. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,185
    There is no "right way" to do many things. Rewired is very flexible so you can use it however you want to. You can certainly try to use it that way, but it will probably get quire cumbersome to try to manage single button mappings per Controller Map, especially if you're planning to allow your users to rebind their controls (and you definitely should). (Rebinding controls takes places on a per-Controller Map basis, so having all your Actions split onto a dozen Controller Maps would require some special steps in designing your rebinding UI system to abstract away this reality.)

    If the enabled bindings need to change states very often like when holding some other button, it may be better to enable/disable the bindings themselves manually instead of splitting them onto separate Controller Maps. Managing this state change is a manual process. Nothing like Map Enabler exists for persisting binding states. Be aware that these binding state may get stuck in certain scenarios such as if the controller gets disconnected while the binding states have changed (say while holding R trigger), and the next time the controller is reconnected during the current session, that state will be remembered from history. You will have to manage resetting these states when a controller is re-assigned to a Player, etc.

    https://guavaman.com/projects/rewired/docs/HowTos.html#enabling-disabling-controller-maps

    Enabling and Disabling Action Element Maps

    Individual Action Element Maps in each Controller Map can also be enabled and disabled:

    Code (csharp):
    1. // Disable all individual Action Element Maps in all Controller Maps in the Player
    2. foreach(ControllerMap map in player.controllers.maps.GetAllMaps()) {
    3.  
    4.    // Disable all Action Element Maps of all types
    5.    foreach(ActionElementMap aem in map.AllMaps) {
    6.        aem.enabled = false;
    7.    }
    8.  
    9.    // Disable all Button Maps (these were already disabled above but this is just for illustration)
    10.    foreach(ActionElementMap aem in map.ButtonMaps) {
    11.        aem.enabled = false;
    12.    }
    13.  
    14.    // Try disabling all Axis Maps if this is a Joystick Map (these were also disabled above)
    15.    JoystickMap joystickMap = map as JoystickMap;
    16.    if(joystickMap != null) {
    17.        foreach(ActionElementMap aem in joystickMap.AxisMaps) {
    18.            aem.enabled = false;
    19.        }
    20.    }
    21. }

    I'm not entirely certain but I get the sense based on this comment that you're hoping to use Rewired's Controller Map system to offload state permission management out of your scripts and onto Rewired by enabling/disabling inputs for flow control, leaving your scripts free to just check for input without action permission checking. If this is the case, don't do it. This is a very common mistake and warned against in the documentation:

    https://guavaman.com/projects/rewired/docs/Actions.html

    Rewired’s Purpose and Responsibilities

    It is common for Rewired's Action system to be used in an unintended manner as an integral part of or in place of a separate game state management system. This is not what Rewired was designed for and not how it is intended to be used.
    • Rewired’s sole purpose is to read user input.
    • All “Actions” in Rewired are actually “Input Actions” and should not be used for any other purpose than to get information about the user’s intent. They should not be confused with or used as game states or actions.
    • The Action “Jump” does not designate “Player is jumping,” but rather “The user wants to jump.”
    • The game should implement permission and state management systems that evaluate user input and then change states. After that point, what happens is outside the responsibility of the input system.
     
    Eldoir likes this.
  41. Eldoir

    Eldoir

    Joined:
    Feb 27, 2015
    Posts:
    38
    Thanks a lot for all these informations.
    I'm going to look at Action Element Maps, otherwise it is indeed possible that a state management system for my character is the right way to do it :)
     
  42. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,475
    I noticed that 1.1.30.3 is already on the asset store.

    1.1.30.3: Bug Fixes: - OSX Native: Fixed bug causing joysticks created from HID devices with multiple logical sub devices to possibly shift around when another joystick device is connected or disconnected.
     
  43. nickfourtimes

    nickfourtimes

    Joined:
    Oct 13, 2010
    Posts:
    178
    Hey there, I'm hoping to find a way to use iOS touch input as a mouse pointer (specifically not as a UI-based Touch Controller). It seems like ReInput.controllers.GetLastActiveControllerType(); does return ControllerType.Mouse when I start touching the iOS screen; however, I've got a Mouse Map with "Left Mouse Button" mapped to "Mouse Click+"... and this doesn't seem to be fired when I touch the screen.

    Wondering if there's any other settings I need to be aware of to get iOS touches to register Mouse Clicks in the mouse maps.
     
  44. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,185
    Rewired's mouse, keyboard, and joystick controllers are based on hardware. You cannot make touch input appear as mouse input. Also, Rewired cannot control the OS cursor on any platform.

    Custom Controllers are the only type of input you are allowed to determine the source of input input yourself.

    Any simulating of touch input as mouse input would have to happen below Rewired. iOS is a UnityEngine.Input dependent platform (for now) and therefore any changes to what UnityEngine.Input returns will be reflected in Rewired.

    The only reason ReInput.controllers.GetLastActiveControllerType() would return Mouse when you touch the screen is that Unity is sending mouse data for touches.

    This is the only value I know that I know of:
    https://docs.unity3d.com/ScriptReference/Input-simulateMouseWithTouches.htm
     
    nickfourtimes likes this.
  45. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    324
    Can someone help me understand the concept of the Map Enabler? I've read the documentation on it twice, and I understand when you might want to use it, but I don't understand how the actual Rules and Rule Sets decide when a certain map is enabled / disabled.

    In my case, just like the documentation states, I'd like to enable certain maps in the main menu, and others during gameplay automatically. I just don't understand how my Rules / RuleSets should be configured to accomplish this....
     
  46. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,185
    You are the one who determines what controller maps you want enabled and disabled. You do this by defining rules that do what you want them to for your purposes. You determine which Rules and Rule Sets are enabled, and therefore which ones evaluate and which ones are ignored. I really can't make it any more clear than the documentation:

    https://guavaman.com/projects/rewired/docs/MapEnabler.html

    Rules:
    Rules are individual commands that are evaluated and applied to all matching Controller Maps in the Player to determine which Controller Maps should be enabled or disabled. Each Rule in a Rule Set is evaluated in sequence.

    Rules contain 4 pieces of information:
    1. Controller Selector - Determines which Controller(s) the Rule applies to. Only Controller Maps for the specific Controller(s) will be managed by this Rule.
    2. Categories - Determines which Controller Map(s) this Rule applies to by Map Category.
    3. Layouts - Determines which Controller Map(s) this Rule applies to by Layout.
    4. Enabled - Determines whether the Controller Map(s) should be enabled or disabled.
    When Map Enabler evaluates the Rules, for the specified Controller(s), it will enable or disable any Controller Maps in the Player that match the specified criteria in the Rule.
     
    Last edited: Mar 25, 2020
  47. msfredb7

    msfredb7

    Joined:
    Nov 1, 2012
    Posts:
    24
    Hey @guavaman. I'm looking into testing my game with automated tests. This means I need to recreate player behavior and inputs with a bot.

    Is there any way I can dynamically generate "fake" rewired inputs at runtime (like jump, move left, etc.) ? If so, where should I start looking.

    Thanks!
     
  48. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,185
    https://guavaman.com/projects/rewired/docs/CustomControllers.html

    There is no other way to input your own values into the system.
     
    msfredb7 likes this.
  49. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    324
    @guavaman Sorry I feel dumb. What I don't understand, is the correlation between my game logic state saying "hey, we are in the main menu right now" and Rewired's map enabler know that we are in the games "main menu", so evaluate the Rule Set for "Main Menu".

    How do I communicate to the map enabler which rule set is currently relevant?
     
  50. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,185
    You write code to enable the Rule Sets you want enabled and disable the Rule Sets you want disabled. It's as simple as that. Study at this picture. It shows exactly how the system works in the most concise way possible:



    Disabled Rule Sets are not evaluated, enabled Rule Sets are. Whatever the enabled Rule Set defines to to be enabled or disabled will be enabled or disabled when it is evaluated.

    Map Enabler literally contains a a System.Collections.Generic.List of Rule Sets. You write a script to go through this list and decide what Rule Sets you want enabled or not whenever you need to change enabled states. When the Rule Sets evaluate, they enable or disable the Controller Maps they target. You decided what job each Rule Set had when you created them. All you're doing now is turning them on and off to achieve some kind of pattern of enabled states.

    Accessing from Scripts:
    Code (csharp):
    1. player.controllers.maps.mapEnabler
    1. Each Player has its own Map Enabler that can be used to manage the Controller Maps for that Player.
    2. The Map Enabler contains a list of Rule Sets.
    3. Each Rule Set contains a list of Rules which determine what Controller Maps are to be enabled or disabled.
    4. When Apply is called on the Map Enabler (manually or when certain things happen such as when assigning a Controller to a Player or loading Controller Maps), all Rules in all enabled Rule Sets are processed one at a time in order. Controller Maps for the matching Controllers are enabled or disabled to comply with each Rule.

    Code (csharp):
    1. // Apply the changes to the Player's Controller Maps
    2. player.controllers.maps.mapEnabler.Apply();

    API Reference:
     
    Last edited: Mar 26, 2020
unityunity