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. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    Thanks a lot for doing all these tests. Okay, based on what you've told me and at least two other people having somewhat similar but not identical symptoms that were also solved by disabling allowMouseInputIfTouchSupported, it looks like Unity is no longer respecting the Input.simulateMouseWithTouches. Here's one way to do it:

    Code (csharp):
    1. #if (UNITY_IOS || UNITY_TVOS) && !UNITY_EDITOR
    2.  
    3. var rsim = GameObject.FindObjectOfType<Rewired.Integration.UnityUI.RewiredStandaloneInputModule>();
    4. if(rsim != null) {
    5.     rsim.allowMouseInputIfTouchSupported = false;
    6. }
    7.  
    8. #endif
    As for the mouse pointer being moved by touch input, I am curious to know whether you have the Unity Player -> iOS -> Active Input Handling set to Input Manager or Both. I have a hunch this might be an issue with Both and not Input Manager.

    Edit: I just looked at the current documentation:
    https://docs.unity3d.com/ScriptReference/Input-simulateMouseWithTouches.html

    "If enabled, up to three concurrent touches are translated to state on the respective mouse buttons (example: a two-finger tap will be equal to a right-button mouse click)."

    Based on that description, that makes it sound like it only affects whether or not touches return as mouse button presses and not whether or not the mouse position is affected. From testing this years ago when creating the Rewired Standalone Input Module and the Touch Controls pack, I was under the impression that this option enabled/disabled movement of the cursor too. I was very sure this was the case on one platform where the DS4 touchpad was causing mouse movement. The standard solution to the problem was always to disable simulateMouseWithTouches...
     
    Last edited: Oct 31, 2022
  2. daxiongmao

    daxiongmao

    Joined:
    Feb 2, 2016
    Posts:
    412
    I would think for mouse buttons to be used it would also have to set the location of those clicks.
    Seems like maybe now its still setting the position but not generating the clicks.
    In my case it was the highlighted states of buttons that was being an issue.

    I guess you could just check internally if the Input.simulateMouseWithTouches was false instead of position=0,0.
    But it seem that disabling your already existing allowMouseInputIfTouchSupported would do the same thing.

    I just checked I thought I had it set to input manager. But its set to both.
    I did one build not turning off allowMouseInputIfTouchSupported and with set to InputManager (old). And it has the same issue where touching sets the mouse position and causes highlighting when scrolling.

    I do not have the new input system package installed anymore or i could test it selecting the other one.
     
  3. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    Thanks again for doing this testing. I just verified that on Android using Unity 2022.1.0 both mouse position and all the mouse delta values are affected by touch input. I am virtually certain this is a regression. I would need to be able to go back to Unity 2018 or 2019 and make an Android build to verify, but that's difficult because of the different version of the Android SDK and JRE required. Maybe I'll try to do that at some point.

    Because the mouse cursor is now always affected by touch input, any game that makes use of mouse controls in Rewired, say for the PC version, but touch controls in the mobile version will have problems because touch input will always be generating fake mouse input as well. Also the Dual Shock 4 mouse input can't be disabled by disabling simulateMouseWithTouches. People are going to have to disable the Rewired Mouse controller on mobile platforms.

    As for the Rewired Standalone Input Module, I believe the reason the result is different than Unity's module is they are testing for whether or not a mouse is connected before processing mouse input whereas Rewired tests whether or not mouse input is supported:

    Code (csharp):
    1. // Rewired
    2. if (!ProcessTouchEvents()) {
    3.     if (isMouseSupported) ProcessMouseEvents();
    4. }
    5.  
    6. // Unity
    7. if (!ProcessTouchEvents() && input.mousePresent)
    8.     ProcessMouseEvent();
    This is different because of Rewired's Player Mouse system. Part of the code for isMouseSupported used to include testing Input.mousePresent but I see I commented that out years ago:

    Code (csharp):
    1. RewiredPointerInputModule.cs line 613:
    2. // return Input.mousePresent; // REMOVED: Input.mousePresent is unreliable. Some platforms will return false when a mouse is present and working.
    It's difficult because this has to work for all use cases including a real mouse, a simulated touch mouse, and also on platforms that may have both a mouse and a touch screen. In the case of iOS, you can safely disable allowMouseInputIfTouchSupported, but that wouldn't be safe on a touch-enabled Windows PC or an iPad pro with a mouse. Checking whether a mouse is present before processing any mouse input seems to be the correct solution, but my note tells me there is at least one platform where this fails or failed in the past. Unfortunately I didn't document which platform that was. I'm probably going to have to just re-enable that check and assume they fixed that bug on whatever platform it was.
     
    daxiongmao likes this.
  4. qazwsx2498

    qazwsx2498

    Joined:
    Oct 17, 2022
    Posts:
    13
    “player.controllers.maps.GetFirstButtonMapWithAction().elementIdentifierName”。 When I'm not connected to Xbox, this API doesn't detect the xbox button that the controller is bound to 。Is there any other way to get the elementIdentifierName corresponding to this action even if I don't have an Xbox connected?
     
  5. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    See this:
    https://forum.unity.com/threads/rewired-advanced-input-for-unity.270693/page-130#post-6097785

    And this if you want more background to the limitations:
    https://forum.unity.com/threads/rewired-advanced-input-for-unity.270693/page-37#post-2569369
     
  6. Adam_Wisniewski

    Adam_Wisniewski

    Joined:
    Jul 29, 2021
    Posts:
    2
    Hello, I have very weird problem.
    I am porting game for PS4, but it shouldn't matter as problem is visible also in Editor (but I use Dualshock 4 everywhere). The problem is that when I disconnect gamepad after "accepting" start screen and before main menu is loaded, when I later reconnect gamepad input is just working very weird - only 2 buttons do anything (Cross and Left Stick) - but 1 of them triggers half of all available actions, and other triggers other half.
    I know it is probably something in initialization but I am searching for any problem and cannot find anything related.

    When in play mode I can see in "Debug information" under Rewired Input Manager that Actions are trggered with wrong buttons and are not triggered with proper buttons.

    Everything works fine when I don't disconnect gamepad (or do so after initialization of main menu), so I know there must be something in initialization process that causes this issue, but have no idea what to look for.
    Any kind of help or push in the right direction will be appreciated.

    Example of adding input delegate:
    Input.RwPlayer.AddInputEventDelegate(data => CurrentInputFrame.MainAttackDown = data.GetButton(), UpdateLoopType.Update, InputActionEventType.ButtonPressed, Actions.MAIN_ATTACK);


    EDIT: Also I made sure that all ControllerMaps are properly enabled, so that is not the case.
     
  7. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    If this problem is happening both in the editor and on a PS4 build, it can only be due to Controller Maps.

    Use Debug Information and examine the actual Action Element Maps in each Controller Map in your Player. Action Element Maps determine what Action a controller element binds to. Examine the bindings before disconnecting and after reconnecting. It is very likely that something is causing the bindings to change -- probably a script that is doing something in the OnControllerConnected event.

    And because you're talking about initialization, make sure the Rewired Input Manager in the first scene is not being replaced by a new one after the next scene is loaded. Rewired Input Manager starts by default with "Don't Destroy on Load" checked. Make sure it is still checked.
     
  8. Adam_Wisniewski

    Adam_Wisniewski

    Joined:
    Jul 29, 2021
    Posts:
    2
    Thanks for quick response.
    I couldn't find anything in OnControllerConnected event (or disconnected event) that may be causing those problems (if I disconnect and reconnect later in game after initialization everything works fine.
    What I have found is that every action in my controller map have "element Identifier Name" cleared and "Element index" set to 0 - which is the problem, because only input that does anything is from button with id 0 (cross) and from axis with id 0 (left stick X).
    Further investigation has showed that if there is no controller connected during initialization of my players controllers there will be Keyboard assigned (that's left from Steam version of the game) and switching back to dualshock was creating those strange issues. I blocked keyboard from PS4 version and everything seems to be working fine now.
    So issue have beeen resolved, thanks for the help :)
     
  9. kopanz

    kopanz

    Joined:
    Dec 6, 2016
    Posts:
    82
    Hi,

    When I try to start the InputMapper with context it says
    Rewired: Player id -1 does not exist!

    I'm sure actionId is not out of bounds and player 0 is enabled
    controllerMap and actionElementMapToReplace in context is not null.

    ------- Rewired System Info -------
    Unity version: 2020.1.17f1
    Rewired version: 1.1.43.0.U2020
    Platform: Windows
    Editor Platform: Windows
    Using Unity input: False
    Primary input source: RawInput
    Use XInput: True
    Native mouse handling: True
    Enhanced device support: True
     
  10. kopanz

    kopanz

    Joined:
    Dec 6, 2016
    Posts:
    82
    I found an alternative way of control remapping without InputMapper using

    ControllerPollingInfo tempCp = controller.PollForFirstElementDown();

    I can change mappings and I can confirm that ActionElementMap is getting updated in controller map.
    But I can't that make that change apply into PlayerSaveData.

    I was having the same issue when the InputMapper was working too.
     
  11. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    What you are describing is extremely baffling and should not even be possible. The only ways I know for Action Element Maps to be corrupted are:

    1. Corrupted saved XML/JSON data is being loaded, replacing the Controller Maps created on start by the Rewired Input Manager.

    2. Manual creation of these Controller Maps in code or by loading them when a controller is not connected using GetJoystickMapInstance and then adding that controller map directly to the Player and using it. The result still would not match what you're describing.

    3. Corrupted Rewired Input Manager serialized data or corrupted joystick definitions.

    What you describe with the "element identifier name" being cleared tells me that the controller map is never being "baked". When a Controller Map map is loaded into a Player, Action Element Maps initially only have an Element Identifier Id. This is a cross-platform identifier of each element. After loading it into the Player, because now the actual device is known and the platform/input source is known for that device, the actual element indices can be baked into the Action Element Map, and the string name of each element identifier is also baked at that time to save wasteful lookups through many levels of mapping. What you're describing to me is that the baking process never happened. I know of no code path that could lead to this and nobody has ever reported anything like this in the 8+ years Rewired has been out.

    I suspect something is very wrong in your project. Either serialized data corruption or some scripts doing something you're not aware of.

    Is nothing unusual logged?
     
  12. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    Input Mapper simplifies remapping 1000x. You will have an extremely hard time using the low-level remapping API. That's the whole reason Input Mapper was created. There's also no documentation on using the low-level API.

    >> When I try to start the InputMapper with context it says
    >> Rewired: Player id -1 does not exist!

    The Controller Map you are passing to the Context does not belong to a Player. This is not supported. Input Mapper can only work on Controller Maps that exist in and belong to Players.

    Examples using Input Mapper:
    https://guavaman.com/projects/rewired/docs/Examples.html#simple-control-remapping
    https://guavaman.com/projects/rewired/docs/Examples.html#control-remapping-1
     
    kopanz likes this.
  13. kopanz

    kopanz

    Joined:
    Dec 6, 2016
    Posts:
    82
    Thanks for the help,
    ControlMapper was embedded to my game's UI very seamlessly for a long time.
    But currently I'm creating a new UI which has "Full Control Support".
    I got rid of DoozyUI for this purpose, now I'm making my own control mapper.
    I will try to understand remapping examples better.
     
  14. haywirephoenix

    haywirephoenix

    Joined:
    May 17, 2017
    Posts:
    101
    Is it correct that I cannot assign a static System.Action to an InputEventDelegate, I have to create a separate action and invoke it first? Adding the System.Action as a parameter caused an error
     
    Last edited: Nov 5, 2022
  15. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    If you pass the static, uninitialized OnMoveHorizontalAction to player.AddInputEventDelegate, you're passing a value of null to the function. This can't work. The function cannot invoke a null callback. Your callback must be non-null or it can't be used. New additions to the static delegate later are not available to the function because null was passed, not an empty delegate. This issue isn't specific to Rewired.
     
    Last edited: Nov 4, 2022
  16. haywirephoenix

    haywirephoenix

    Joined:
    May 17, 2017
    Posts:
    101
    I see, thank you so much.
     
  17. waltercl

    waltercl

    Joined:
    Dec 30, 2018
    Posts:
    47
    I'm back to having an earlier issue which was temporarily resolved when I upgraded to the latest Rewired version.

    To summarize, the issue is that when I change the Mouse Invert in the Control Mapper screen it is not being saved unless I also change something else in the controls.

    As I said, this was happening and then was resolved with an update, and now it's back.

    I deleted all the PlayerPref data thinking that would help but it didn't and the problem persists.

    When I change the Mouse Invert value and click "Done" I see the below messages in the console so I know "saving" is taking place at some level but the mouse invert change isn't saved.

    Rewired: UserDataStore_PlayerPrefs saved controller assignments to PlayerPrefs.
    Rewired: UserDataStore_PlayerPrefs saved all user data to XML.

    In my project I'm instantiating Rewired Input Mapper and Control Mapper in the opening Menu and they both have "Don't Destroy" checked so that they persist in scene changes.

    In my opening scene I do have another instance of both (RI and CM) just so I can start with that scene when I'm doing testing, but I have these disabled when I start from the Main Menu. I tested trying to change the Invert value with these other instances in the first scene and invert won't save for them either.

    I see in the documentation a reference to clearing "XML Data" but I don't see the directions on how to do this. I've already tried clearing the Player Prefs data and that didn't help.

    Obviously the problem is somewhere in something I've done, but I don't know how to track it down.

    What's puzzling to me is why is this issue ONLY affecting the invert values? Everything else saves with no issue. And why does saving with Invert values work if I touch anything else in Control Mapper but not if I only touch the Invert value?

    Any help in pointing in the direction to resolving this would be appreciated.
     
    Last edited: Nov 6, 2022
  18. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    As before, this is a very unusual problem and I have very few ideas about what could possibly cause the symptoms you describe. What I said last time still applies. From my email response:

    As I suggested in my email to you, the single most likely cause in my view is having more Action Element Map bindings that bind this Action than columns being displayed. If you have 2 Action Element Maps binding this Action and are displaying 1 column, you are only seeing one of the two bindings that exist. When you press invert and save, you are changing the first visible binding but not the second. The next time you open Control Mapper the order might have changed and you would be seeing the 2nd binding (the one you did not change) instead of the 1st (the one you did change). You can easily verify this by using Debug Information and examining what bindings exist for this controller in your Player at runtime before and after you invert the binding and before and after you close and open Control Mapper.

    I suggest you get rid of these and use Rewired Initializer and make Control Mapper a child of the Rewired Input Manager Game Object so they are instantiated at the same time.

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

    Just touching something doesn't necessarily change anything. Bindings are only changed if you bind a new Action or change some value. Data is saved when Done is pressed regardless of whether or not anything changed.

    Again, what you are describing does not make sense based on how the system is written, which is why I am convinced what is actually happening is not what the symptoms make appear is happening. Understanding this type of issue is hard because the symptoms are indirectly related to the cause.

    Clearing PlayerPrefs is clearing XML data. It's the same thing. The default data saving system for Control Mapper, UserDataStore_PlayerPrefs saves XML data to PlayerPrefs. PlayerPrefs is the data storage medium. XML is the data format.

    I also suggest you test the Control Mapper demo scenes and verify that it works as you expect.
     
    Last edited: Nov 6, 2022
  19. waltercl

    waltercl

    Joined:
    Dec 30, 2018
    Posts:
    47
    Thanks for the reply. So here's what I did.

    In my Main Menu scene I deleted the Input manager and Control mapper. I then created both from the Window -> Rewired -> Create options.

    I childed the Control Mapper to the Input Manager.

    I ran the game and Invert values save as expected.

    Since this fixed it does that give you anymore information on what caused the issue?
     
  20. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    No. The only thing that would give me more information would be for you to have used Debug Information to examine the Action Element Maps before and after. You've created a new Rewired Input Manager which means your input configuration is not the same as what you were testing with before. If you had a double binding in your configuration, that would be gone because you created a new Rewired Input Manager.
     
  21. waltercl

    waltercl

    Joined:
    Dec 30, 2018
    Posts:
    47
    Any thoughts on what I could be doing to cause the double-binding if in fact that's what is happening?
     
  22. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    All it would require is that you created two bindings in the Rewired Input Manager in a Controller Map that bind the same Action.
     
  23. igorskugar

    igorskugar

    Joined:
    Aug 17, 2015
    Posts:
    14
    Hi,

    I'm in the process of moving all of the globally available "managers" to a prefab to instantiate them before any scene loads.

    Code (CSharp):
    1.  
    2. public static class Main
    3. {
    4.     [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
    5.     public static void Init()
    6.         var op = Addressables.LoadAssetAsync<GameObject>("Persistent");
    7.         var go = op.WaitForCompletion();
    8.         Object.DontDestroyOnLoad(Object.Instantiate(go));
    9.  
    10.         // Object.DontDestroyOnLoad(Object.Instantiate(Resources.Load("Persistent")));
    11.     }
    12. }
    13.  
    At first I tried to load that prefab called "Persistent" from the "Resources" folder (commented out above), and it seemed to worked fine (took only 50 ms)...
    But there is one issue:
    Moving the "Rewired Input Manager" into the Resources folder (no need to load it, just move it there) increased build time from 37 sec to almost 10 minutes!

    Second method utilises Addressables, and it also works but takes about 20 ms longer than Resources way.

    My questions:
    1. I'd like to understand why moving Rewired Input Manager (inside a prefab) to Resources folder has such negative impact on build time.
    2. Are there any alternatives or improvements to what I'm doing?

    Thanks for the Rewired, new Unity's input system drives me nuts... :)
     
  24. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    You would have to ask Unity that. I don't know anything about how their Resources system works internally. Rewired is just scripts, dlls, and scriptable objects.

    I can't give you advice on using Unity's various systems to load objects. Rewired, is just one of the objects you're trying to load.

    The way I know of to load things that are needed in every scene is to create an opening scene that contains the managers, set them to "don't destroy on load", then load your next scene.
     
  25. igorskugar

    igorskugar

    Joined:
    Aug 17, 2015
    Posts:
    14
    No problem, I hoped you encountered it before during all the years of package development.
    I heard that "Resources" are not good in most cases, but their main advantage in this case is being synchronous.

    Again, I hoped you are experienced enough with Unity to be able to share some good practice/advice on how to do it right.
    The "Initial scene" method is problematic during development phase because you either have to always open the "Initial scene" first or automate opening it from other scenes and go back (overcomplicated).
    Thanks for the quick reply, I appreciate it anyway.
     
  26. TGKG

    TGKG

    Joined:
    Dec 31, 2014
    Posts:
    180
    Hi,
    This question is about the Settings: "Default Axis Sensitivity Type". If I choose Multiplier, where is the multiplier value set? If I choose Power, where is the power value set? If I choose Curve, where is the curve value set.
    Do I need to set these values at all or are there default values for each of these types?
    If I have to set these values in my code, then where in my code do I do that and then an example of the code would be appreciated.
    Also a more detailed explanation of how the Power choice and Curve choice apply to the joystick movement would be appreciated.
     
  27. waltercl

    waltercl

    Joined:
    Dec 30, 2018
    Posts:
    47
    I have some more detailed information about this. The issue has reoccurred, and I've taken a close look at the Debug values and did my best to dig into what might be causing it.

    So after starting over with another fresh instance of Input Manager and Control Mapper in my starting scene and making sure these don't exist in any other scenes, I then imported all my actions and map data using the Tools -> Import Data.

    In my first scene I am able to see the value for Mouse Look Vertical Invert changing from true to false in the Debug Menu. However, when I go into the next scene I am no longer able to see this value changing in the Debug Menu when changing it in the ControlMapper UI.

    So I tried something. I removed the User Data Store_Player Prefs component from RI and changing the invert value works in the first scene AND it works in the next scene.

    I have cleared the Player Prefs Data in the Debug Options on the component several times and this does not resolve the issue.

    I only have one mouse map and the LookVertical and LookHorizontal is assigned on this one Mouse Map. These are also assigned on my one Joystick Map and assigned to the Right Stick Y and Right Stick X respectively.

    Does this information at least get us closer to finding out what is going on?
     
  28. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    That's why Rewired comes with the Rewired Initializer system so you can drop a Rewired Initializer in all scenes and have it instantiate the Rewired Input Manager from a prefab if none has been instantiated yet.

    See "Using the Rewired Input Manager in your game":
    https://guavaman.com/projects/rewired/docs/InputManager.html

    Rewired's Script Execution Order is what allows it to initialize before other scripts. Rewired Initializer also executes before other scripts.

    In my opinion, there is no "right" way to do most things in software. There are many different approaches, each with their pros and cons. The approach you use depends on your specific needs.
     
    Last edited: Nov 11, 2022
  29. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    In the Axis Calibration in the Calibration Map in the Controller:
    https://guavaman.com/projects/rewired/docs/api-reference/html/T_Rewired_AxisCalibration.htm

    See this:
    https://guavaman.com/projects/rewired/docs/HowTos.html#calibrating-controller-axes

    Rewired comes with complete code examples of calibration in both ControlRemapping1 example and Control Mapper. They only support Multiplier sensitivity though.
     
  30. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    If you can, please PM me a link to your project on Dropbox or some other file sharing service. (I will also need to know the version of Unity you are using.) I don't think there is any way I can figure out what is going on based on the description. There is no scenario I know of where this makes sense. Loading a scene should have no affect at all on the Rewired Input Manager, Control Mapper, or UserDataStore_PlayerPrefs if the game object has Don't Destroy on Load set. Rewired has no code at all that monitors level loading or does anything in relation to level loading.

    If the Control Mapper UI is showing an invert being toggled and the Action Element Map in the Player does not show invert being toggled, that can only mean the Action Element Map you are editing in Control Mapper is not the same one you are looking at in Debug Information. There has to be another Action Element Map being modified than the one you're looking at. The invert button in the UI in Control Mapper is directly tied to the Invert state of the Action Element Map. If there were no Action Element Map for it to be changing the Invert state on, it would be throwing a null reference exception.
     
  31. igorskugar

    igorskugar

    Joined:
    Aug 17, 2015
    Posts:
    14
    That's clever, thanks.
     
  32. waltercl

    waltercl

    Joined:
    Dec 30, 2018
    Posts:
    47
    I think I found the issue by process of elimination.

    Here is the code of my method where I open the Control Mapper:


    private void SelectControllerSettings()
    {
    StartMenuCanvasGroup.alpha = 0;

    RewiredControlMapper.Open();
    inputMapper.options.ignoreMouseXAxis = true;
    inputMapper.options.ignoreMouseYAxis = true;

    try
    {
    ReInput.userDataStore.Load(); // load saved user maps on start if there are any to load
    }
    catch
    {
    //do nothing
    }

    }

    See my new method below and what I commented out:

    private void SelectControllerSettings()
    {
    StartMenuCanvasGroup.alpha = 0;

    RewiredControlMapper.Open();
    //inputMapper.options.ignoreMouseXAxis = true;
    //inputMapper.options.ignoreMouseYAxis = true;

    //try
    //{
    // ReInput.userDataStore.Load(); // load saved user maps on start if there are any to load
    //}
    //catch
    //{
    // //do nothing
    //}

    }

    It is now working as I would expect.

    I don't know why I was using the code: ReInput.userDataStore.Load() because that appears to be handled by your UserDataStore_PlayerPrefs script. And I don't think I needed those ignore mouse axis lines either because they too are handled by the options on the control.

    To further muck things up, I used this code in two different places. One is the Start Menu at the beginning of the game and then also on the Pause Menu which is attached to the player. So in two different places I was calling that ReInput.userDataStore.Load() function and my theory is that either one or both (Main Menu or Player Pause Menu) was loading a different map.

    I'll monitor this carefully because I've thought I had this solved before and didn't, but for now I not only have it working but I seem to have a plausible reason for why it wasn't working.
     
  33. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    Input Mapper and Control Mapper are two entirely separate systems and not compatible with each other. If you are trying to use the two together, that could definitely be causing problems if you're actually starting the Input Mapper and trying to do rebinding with Input Mapper. Remove all references to Input Mapper. What you are trying to do, ignore mouse X and Y axes, must be done through the Control Mapper inspector:
    https://guavaman.com/projects/rewired/docs/ControlMapper.html#inspector-mouse-options

    Setting that value in Input Mapper is doing nothing because Control Mapper does not use Input Mapper. Even if it did, you would have to set that value on the instance of Input Mapper that Control Mapper would theoretically be using, not on some instance you created.

    UserDataStore_PlayerPrefs does already handle loading saved data on start. There's no reason you should be loading saved data when you open Control Mapper. The data needs to be loaded regardless of whether or not Control Mapper is opened.
     
  34. shotoutgames

    shotoutgames

    Joined:
    Dec 29, 2013
    Posts:
    290
    What is the best way to change just one Action with the same key based on context.
    Simpler, I want to use the A Button to Jump but when near an NPC I want to use the same A button to start a converstion and not jump.
    Thanks as always!
     
  35. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    353
    Hey @guavaman, hope you are doing well.

    I'm starting work on a project that will have AI enemies that I plan to control their navigation / movement by simulating controller input. The major benefit of this is that a developer could then play test an enemy at anytime with a physical controller.

    I'm looking for some guidance on how you'd recommend to approach a setup like this? I was thinking maybe I'd make a C# interface that is able to accept input values from anywhere, so a simulated input or input from Rewired could be accepted and then consumed by the entities (player or enemies, etc).

    I know Rewired also has Custom Controllers that I thought might work for this, but it appears that these are still assigned to Rewired Players so that wouldn't work for possibly 100's of enemies in a game scene at a time.

    Any guidance would be greatly appreciated. Thanks in advance.
     
  36. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    Changing input bindings is not appropriate for your use case. Use a single Action and determine what code to execute based on other criteria (how close you are to an NPC, etc.)
     
  37. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    There is no other way to simulate input in Rewired except through Custom Controllers. Rewired is a Player-based input system. Input has to happen through a Player if you want to use the Action system. There's no way around it.

    In any implementation of this, the majority of the work would be on your end and not in Rewired. You will probably have to write an input abstraction class for your enemies that can take either AI input or Rewired input and reserve one Player for use as a debug testing Player to control whatever enemy needs to be tested. This is totally off the top of my head in responding to this question. There are probably other ways to do something like this, but they're outside the scope of Rewired.
     
    Last edited: Nov 12, 2022
    rxmarccall likes this.
  38. GrassWhooper

    GrassWhooper

    Joined:
    Mar 25, 2016
    Posts:
    108
    hey there
    small question
    i tried to grab the full version of rewired and i noticed its not on the asset store anymore any news/ideas?
     
  39. qazwsx2498

    qazwsx2498

    Joined:
    Oct 17, 2022
    Posts:
    13
    Will “Mouse Horizontal” be triggered on a phone?
     
  40. qazwsx2498

    qazwsx2498

    Joined:
    Oct 17, 2022
    Posts:
    13
    When I drag the screen on my phone, "Mouse Horizontal" is triggered, is this normal?
     
  41. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    Unity is causing this, not Rewired.

    1. Rewired uses UnityEngine.Input on Android and iOS for input.
    2. Unity seems to have changed something at some unknown point in the recent past that makes disabling UnityEngine.Input.simulateMouseWithTouches no longer disable mouse axis movement, but only affects button presses. This means there's no way to prevent Unity from generating mouse events from touch input anymore.
    3. A workaround is to disable the Mouse controller in Rewired on the platform in question.
    Code (csharp):
    1. #if UNITY_IOS && !UNITY_EDITOR
    2.     Rewired.ReInput.controllers.Mouse.enabled = false;
    3. #endif
    4.  
     
  42. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
  43. kopanz

    kopanz

    Joined:
    Dec 6, 2016
    Posts:
    82
    Hi,

    I almost completed making my custom control mapper.
    Input Mapper works really well, no problem about that.
    But I'm a bit confused about removing an element map.
    Should I just remove the selected element map from AllMaps list ?
    From the list which we iterate over to process ActionElementMaps for displaying or replacing.

    Thanks for the help.
     
  44. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    No. The IList that is returned is read-only.

    The ControllerMap class and subclasses have a ton of functions for managing the contents of the Controller Map:
    https://guavaman.com/projects/rewired/docs/api-reference/html/T_Rewired_ControllerMap.htm
    https://guavaman.com/projects/rewired/docs/api-reference/html/T_Rewired_ControllerMapWithAxes.htm

    Look at the Delete... functions.
     
    kopanz likes this.
  45. TGKG

    TGKG

    Joined:
    Dec 31, 2014
    Posts:
    180
    Thank you for the reply. I have looked at the Control Remapping 1. You mention "This example demonstrates how to create a controller remapping screen using legacy Unity's GUI system. The demo shows examples of: .... ", however I do not see a link to the example / demo that is mentioned. What am I not seeing?


    Same when I visit the "Simple Control Remapping" page. "This example only supports 1 Player, 1 Joystick, 1 Controller Map, and 1 mapping per Action, per controller type. No UI windows are used and conflict checking is handled automatically by InputMapper to keep this example small and focused." If there is an example I am not finding any link to it???
     
  46. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    The examples are included in the Rewired folder of your project as it says at the top of the page:

    Examples
    All examples can be found in the Rewired/Examples folder. You should use these examples to learn how to work with the more advanced features of Rewired. More examples will be added in future updates.
     
  47. jmgek

    jmgek

    Joined:
    Dec 9, 2012
    Posts:
    103
    Going to be a dumb question:
    Code (CSharp):
    1. player.AddInputEventDelegate(OnMoveHorizontal, UpdateLoopType.Update, InputActionEventType.AxisActiveOrJustInactive, "Move Horizontal");
    What would be the proper way to register to movement both Horizontal and Vertical? I'm thinking registering "Move Vertical" but setting up two delegates doesn't seem like the proper way.
     
  48. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    Setting up two delegates is the proper (and only) way.

    Actions are 1 dimensional. Horizontal and Vertical are two separate Actions. You must subscribe to each Action individually.
     
  49. jmgek

    jmgek

    Joined:
    Dec 9, 2012
    Posts:
    103
    Yes, I understand but I feel like there should be some type of flag that should say if joysticks / any axis are active or not without polling in rewired, but thanks I'll set these up.
     
  50. kopanz

    kopanz

    Joined:
    Dec 6, 2016
    Posts:
    82
    What will happen when you connect two identical joysticks/gamepads to your pc while using Rewired ? Any known issues ? How does Rewired will name those controllers ? I couldn't try connecting two identical joysticks to Rewired but became curious when I saw a player complaint on Construction Simulator's steam discussions. They are using Unity with Rewired.
     
    Last edited: Nov 18, 2022