Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. 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,499
    The majority of support happens through email. I'm always busy.

    The only possible cause is bad axis calibration. Polling for input while listening to bindings requires a relative value change of +/- 0.7 on the axis to be detected. This is relative to the current value when polling started. Badly calibrated axes that cannot achieve that relative change when moved will never trigger a detection.

    Control Mapper uses UserDataStore_PlayerPrefs by default. See the documentation:

    https://guavaman.com/projects/rewired/docs/UserDataStore.html#playerprefs

    IMPORTANT: Saved XML data is not updated when you make changes to the Rewired Input Manager

    UserDataStore does not manage changes between the Rewired Input Manager and data that is already saved to XML. If you make changes to the Rewired Input Manager settings such as adding new controls to a Joystick Map, these new changes will not be preserved when loading saved XML data. The only automated solutions would be to either clear the save data by clearing Player Prefs so that the Rewired Input Manager defaults are used instead or load the default maps in the Player for the any controllers that changed and save those to XML overwriting the existing saved mappings.

    Management of saved user data is up to the developer. If you have special needs beyond the basic use cases, you should extend and replace the UserDataStore_PlayerPrefs component with a new UserDataStore component that meets your specific needs.

    IMPORTANT:

    During development, you may run into a situation where your controls don't seem to make sense. This may happen when you make some runtime control changes, save them, and then proceed to change your mappings in the Rewired Input Manager. Because UserDataStore_PlayerPrefs is configured to save controller data on disconnect and load controller data on start and controller connect, the loaded settings will override new changes you make to the default mappings in the Rewired Input Manager.

    During development, it may be useful to disable or remove the UserDataStore_PlayerPrefs component. If you've already saved controller settings and want to remove them, you can use the Clear All Player Prefs button in the Debug Options foldout on the UserDataStore_PlayerPrefs inspector. WARNING: This will clear ALL PlayerPrefs data for the current project. This is due to the limitation that there is no way to look up what keys exist in PlayerPrefs.
     
  2. nighty2

    nighty2

    Joined:
    Dec 29, 2020
    Posts:
    29
    Dear guavaman,

    thank you very much for your quick and thorough response!!
    It was spot on in both cases.

    In case of the axis values and the change of +/- 0.7, let me add that practically every tutorial on the joystick library for arduino I stumbled upon advises to map the values of the potentiometers (normally 0 to 1023) to another range of integers before sending them to the computer. Those other ranges appear to be selected randomly (e.g. 0 to 255 or -512 to 512) and it's merits are not explained anywhere.
    With Rewired, axis input from -1 to 1 (and thus making a change this big possible), is only achieved when communicating the native potentiometer values from 0 to 1023 to the computer.

    Thanks again!
     
  3. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,499
    You could also calibrate the axis in Rewired which will correct for the discrepancy. Control Mapper has a calibration window. Calibrate it first, then map to Actions.

    Rewired can read HID axes with different ranges and with negative and positive values, provided the HID descriptor gives the correct information about the range and format.
     
  4. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,739
    i'm running the memory profiler in the android device and i was surprised to find that the largest memory consumed is by rewired. is this normal? I attach the screenshot, it says 5mb for 3drudder... which i don't use in android
    memoria.jpg
     
  5. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,499
    Rewired contains over 1,000 different controller mappings (probably more like 1,500). Every single mapping and variant takes memory. If you don't like how much memory Rewired uses, remove controller definitions. There is no other solution and continue using Rewired..

    https://guavaman.com/projects/rewired/docs/HowTos.html#excluding-controller-definitions

    And no, the 3D rudder definition does not take 5 MB of memory. Unity is reporting 5.3 MB for all Rewired controller definitions loaded and incorrectly attributing all of that to the 3D rudder definition. 3DRudder.asset is 32KB in uncompressed YAML.
     
  6. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,739
    hmm shouldn't just load the ids of the devices and then load those fully when detected?
     
  7. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,548
    We love all of those flight controller definitions too! So thankful to have them. Always wishing manufacturers would make more flight controllers but happy to enjoy the existing ones via Rewired. Thanks again for your product. The only way to fly.
     
    guavaman likes this.
  8. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,499
    Far easier said than done. Rewired was written using Unity's data serialization system, and keep in mind it was written at version Unity 4.3. Unity's data serialization system loads all objects that are referenced in the scene into memory. Only the Resources system and possibly the Asset Bundles system existed at the time to manage what objects are loaded into memory. Use of Resources was always highly discouraged by Unity, and Asset Bundles could not work for Rewired's purposes for a number of reasons. Rewired's data management is based on ScriptableObject. With perfect hindsight, I would have chosen to create a completely different data storage system not based on Unity's serialization system that could address a lot of the problems using Unity system such as the increase in time to enter Play mode in the editor.
     
  9. ZurielA

    ZurielA

    Joined:
    Oct 19, 2021
    Posts:
    7
    In my game I have things setup so you can use keyboard and mouse or you can use joystick, but the functionality to use either is running at the same time, so a user can press WASD move his mouse and see his character aim and move around and then he can seamlessly pick up his joystick and control his char and aim. I am currently detecting if the mouse is out of view or not and then I swap to my joystick aim, but if they are in view it uses mouse aim, and if they leave the mouse alone for a few seconds it swaps back to joystick assuming they are on a joystick but their mouse was left in view. This works, albeit a little hacky... what I'd rather do is just detect the last known device input, if its a controller, swap to that in my aim script and if its a mouse input or keyboard input swap to that in my aim script. What would I use to do that or what can I go research for that concept?

    Thanks!
     
  10. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,499
    In the documentation How Tos:
    https://guavaman.com/projects/rewired/docs/HowTos.html#last-used-controller
     
  11. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,499
    1. Did you upgrade the Unity version in this patch?
    2. What platform(s) are these users playing on?
    3. What is the chosen Primary Input Source for the build target they are playing on?
    4. If Windows, are Native Mouse Handling and Native Mouse Handling enabled?
    5. Is other Rewired input working with Mouse and Keyboard? Meaning, input other than as it relates to Unity UI?

    What is your setting for "Allow Mouse Input If Touch Supported" in the Rewired Standalone Input Module inspector? (Ignore the red box in the image. It is just the inspector image linked from the docs.)



    The most common reason for problems with Unity UI are Unity-UI related and don't involve Rewired.

    Keyboard and Controller navigation in Unity UI are identical. They both use the UI Navigation system to change the current Selectable through the EventSystem by sending an event when user input is received. The Navigation settings that determine how to react to the events are defined in the Selectables themselves. The Input Module simply sends the navigation event to the Selectable and doesn't know the difference between keyboard or controller input.

    You've stated 1) Controllers work but keyboard and mouse don't. 2) It sounds like you have code that switches something depending on whether the user is using the mouse/keyboard or controller. It sounds to me the switching logic is most likely the cause. How are you determining which mode is in use and what specifically are you doing when it switches? I can imagine a scenario where some noise on a controller axis is changing the active controller type and, for example, clearing the current selected object in the EventSystem, if that's something you're doing when the type switches.

    The mouse symptoms sound like something is blocking the raycast to the UI Selectables. That ends up to be cause for almost all reports of mouse input in Unity UI not working.
     
    Last edited: Apr 6, 2022
  12. LittleRockGames

    LittleRockGames

    Joined:
    Jan 7, 2015
    Posts:
    11
    Thanks for looking up my other post. To clarify, I didn't suspect Rewired was the core issue, so I posted in the general forum. I know that you must be very busy, so I appreciate all the effort you've already put in to help!

    1. I have not updated Unity or Rewired between the last two patches. I updated rewired to see if it made a difference on a private test branch, but there was no noticeable change.

    2. All currently verified reports are from PC Windows 10

    3. The Primary Input source for windows is set to RawInput. This matches the setting we had before the issue.

    4. Native Mouse Handling and Native Keyboard Handling are both set to true. This also matches the setting we had prior to the issue.

    5. I haven't been able to confirm this yet, but I've reached out to a player experiencing the issue for confirmation.

    "Allow Mouse Input if Touch Supported" was unchecked. I've enabled it and will pass along a new test build to the player I'm in contact with about this issue.

    We do have code that swaps input prompts and hides/locks the cursor when controller mode is enabled and we determine the intended interaction mode by logging the controller type from GetLastActiveController. I had the same suspicion about joystick noise. To eliminate this as an issue, I completely moved any support for the controller mode. The only change was that no input was registered. I've also checked for raycasting issues, but could not find anything. I also don't think this is the issue, because it only seems to affect some users, although unusual aspect ratios mixed with canvas scaling could potentially cause edge cases.

    EDIT: I adjusted the Allow Mouse Input if Touch Supported field and made a new build. I tested the build that was experiencing issues on a laptop with a touchscreen and the new build with the adjusted checkbox. Mouse input failed on the older version and works on the newer version. That seems to be the issue. Thank you very much! Happy to finally have a solution. It's almost always something so simple.
     
    Last edited: Apr 6, 2022
  13. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,499
    I'm glad it worked, but that wouldn't explain keyboard issues.
     
  14. pocolomos

    pocolomos

    Joined:
    Nov 8, 2018
    Posts:
    5
    Hi guys

    How i get event when right stick be use from controller. I have assign function for right stick axis and keyboard too, and i need to check if that function be trigger by keyboard or by controller, how i do that?
     
  15. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,499
    Determining which Controller was last used
    https://guavaman.com/projects/rewired/docs/HowTos.html#last-used-controller

    Getting contributing input sources for an Action
    https://guavaman.com/projects/rewired/docs/HowTos.html#get-contributing-input-sources
     
  16. pocolomos

    pocolomos

    Joined:
    Nov 8, 2018
    Posts:
    5
  17. walaber_entertainment

    walaber_entertainment

    Joined:
    Jul 10, 2017
    Posts:
    30
    I just wanted to mention something that happened to me today, in case it's helpful for others. Today I booted up my project, and Unity was completely freezing when I hit play. The project was working fine the night before. It took me nearly an hour of trying to debug, and slowly remove more and more components until I discovered:

    Having the rewired input prefab in the scene cause Unity to freeze on start.

    Eventually I tracked it down:

    I had unplugged my Dualshock 4 from 1 USB port on my computer, and instead connected it to a USB hub. unplugging the controller from the HUB caused Unity to instantly wake up and continue playing the game. This was reproducible: plugging the Dualshock into the hub caused rewired to freeze on boot, plugging into another port on the computer and it worked fine.

    When not in play mode, if I plugged the controller into the USB hub, Unity would display the "Controller Connected" debug log message, so I don't think Unity was causing the problem.

    Anyway, just wanted to flag this and see if anyone else has seen this problem before. This was latest version of Rewired, on Unity 2021.2.19. Using legacy Unity input (not the new input system), and Rewired of course.
     
  18. Grumpy-Dot

    Grumpy-Dot

    Joined:
    Feb 29, 2016
    Posts:
    92
    @guavaman I have some quick feedback for improvements:
    - first, the UnityJoystickElementIdentifier script is only displaying the buttons until Button 19, would be nice for some controllers which have more buttons to display up to a higher number. For example Logitech G29 has up until Button 25, but we can't check them.

    - second, for Logitech G920 mapping, the buttons View and Menu are reversed, the View should have Source button 7 and Menu should have Source button 6. You can check this here: Logitech G920 mapping

    - third, if we made a new controller mapping for a controller not supported by default (eg. ThrustMasterTMXPro), could we share it here for the community? Will you consider including it in the plugin on the future update?
    Thank you.
     
  19. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,548
    What is the name of the USB hub? Is it a powered USB hub? Does the USB port that that usb port plugged provide enough power to support hub and other devices?

    In the past with a large number of flight controllers (usb devices) it was recommended to only use powered USB hubs. It was nothing to do with Rewired but mostly with how usb works especially when usb devices are drawing power. Not having enough usb power can cause all sorts of subtle problems with all types of devices.

    On Windows 10 make sure you have this disabled.

    How to disable Windows 10's 'USB selective suspend' setting

    https://www.windowscentral.com/how-prevent-windows-10-turning-usb-devices
     
    Last edited: Apr 11, 2022
  20. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,499
    You'll have ask Unity for that improvement. UnityJoystickElementIdentifier uses Unity's legacy input system, not Rewired's native input system. Their system has a hard limit of 20 buttons. Use JoystickElementIdentifier to see Raw Input, Direct Input, or other native input source information, not UnityJoystickElementIdentifier.

    What platform and input source are you referring to? The G920 definition has been around for many, many years and I have no reports of this being reversed. Are you using a driver that allows customization of button mappings? It is also possible a firmware or driver change has caused a problem.

    Of course you can share it. But as for including it in Rewired, I rarely add user generated definitions because they typically only have the ability to create definitions on one or two platforms / input sources. I typically make mappings for about a dozen platforms and input sources when I get a device. Also, I have to correct the naming of elements typically to match more closely to the standards I've used on other devices. You can send it to me, but I can't guarantee I would include it.
     
    Last edited: Apr 11, 2022
    Grumpy-Dot likes this.
  21. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,499
    The differences between Unity and Rewired regarding DS4:
    1. Unity uses HID API to poll devices for input. Not Raw Input.
    2. Unity does not have anything like Enhanced Device Support that reads and writes HID input/output reports using an internal driver to use the special features of the DS4.
    Disable Enhanced Device Support. I'll bet the problem will stop. But that doesn't mean there's a problem with the implementation of Enhanced Device Support. Upon connection to a DS4 when EDS is enabled, a message is sent to the device to tell it to change to PS4 mode which enables IMUs, lights, vibration, etc., and changes it from running in normal HID mode. Just the fact that it's in PS4 mode changes everything on the Windows side. So while it may look like Rewired's the cause, it is likely simply the fact that the controller is now in a different mode having unintended side effects on the hub and/or Windows.
     
  22. Hi_ImTemmy

    Hi_ImTemmy

    Joined:
    Jul 8, 2015
    Posts:
    174
    Hello.

    I'm using Rewired + Adventure Creator. I'm also using the Rewired Standalone Input Module (and AC is setup to use this for the event system).

    The problem I have is when changing to use direct-navigation with a control pad, if the mouse cursor was on a button that button stays highlighted.

    Here's a GIF showing the problem.


    I'm not sure if this is a Rewired issue, or a Unity quirk, but I'd appreciate knowing how I can stop the cursor from highlighting the button.
     
    Last edited: Apr 12, 2022
  23. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,499
    This is not a Rewired issue. This is just how Unity UI works. The Selectables themselves are responsible for managing their own highlight state. All the input module does is tell it when the cursor enters or exits or navigates.
     
  24. Hi_ImTemmy

    Hi_ImTemmy

    Joined:
    Jul 8, 2015
    Posts:
    174
    @guavaman Thank you for the reply and confirming it's a Unity thing.
     
  25. BasicallyGames

    BasicallyGames

    Joined:
    Aug 31, 2018
    Posts:
    90
    Is there any way to get AnyButton/AnyButtonDown without including analog inputs/axes? I'd like to be able to check if a button is being pressed, but not include control sticks or mouse movement when checking. Only actual buttons.

    Edit: Found ReInput.controllers.AnyButton, that did the trick!
     
    Last edited: Apr 14, 2022
  26. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,499
    Yes. Actions are not the same as controller elements, nor do they have a 1:1 relationship to them. Actions are not buttons or axes. Actions are virtual elements that can be queried as both buttons and axes. Actions abstract their contributing input sources away. Each Action may have an unlimited number of contributing input sources of any type, physical or virtual. Calling player.GetAnyButtonDown has the same result as calling player.GetButtonDown on every Action.

    There are also global methods that apply to all controllers:
    https://guavaman.com/projects/rewired/docs/HowTos.html#important-classes

    https://guavaman.com/projects/rewired/docs/api-reference/html/T_Rewired_ReInput_ControllerHelper.htm
     
    Last edited: Apr 15, 2022
  27. Morothar

    Morothar

    Joined:
    Dec 3, 2009
    Posts:
    25
    Hey everyone. While upgrading one of my projects to the new 2021 LTS version I encountered a problem with ExternalTools.cs lines 816 (which seems to be a recent fix for windows raw input). Compiler says Rewired.Internal.Windows does not exist. I commented out the line for now. Do we need an update or did I do something wrong locally @guavaman ?
     
  28. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,499
    The problem is you are using a version of Rewired incompatible with the version of Unity you are using.

    https://guavaman.com/projects/rewired/docs/Troubleshooting.html#wrong-rewired-version-installed

    Install the correct version and you will have no compiler errors.
     
  29. Morothar

    Morothar

    Joined:
    Dec 3, 2009
    Posts:
    25
  30. Raul_T

    Raul_T

    Joined:
    Jan 10, 2015
    Posts:
    363
    Hello @guavaman !

    What would be the best practice for remapping an action without affecting other categories?

    We have a category for UI actions where for example skipping popups and dialogue is binded to SPACE. And the actions have the visible in lists disabled.

    We use this code to remap on the main category but if an user binds SPACE to a gameplay action it will remove the SPACE binding from the UI action.

    Code (CSharp):
    1.     private IEnumerator StartListeningDelayed(InputButton button, int actionElementMapToReplaceId) {
    2.         // Don't allow a binding for a short period of time after input field is activated
    3.         // to prevent button bound to UI Submit from binding instantly when input field is activated.
    4.         yield return new WaitForSecondsRealtime(0.1f);
    5.  
    6.         // Disable the UI Controller Maps while listening to prevent UI control and submissions.
    7.         player.controllers.maps.SetMapsEnabled(false, 1);
    8.  
    9.         // Start listening
    10.         inputMapper.Start(
    11.             new InputMapper.Context() {
    12.                 actionId = button.action.id,
    13.                 controllerMap = controllerMap,
    14.                 actionRange = button.actionRange,
    15.                 actionElementMapToReplace = controllerMap.GetElementMap(actionElementMapToReplaceId)
    16.             }
    17.         );
    18.  
    19.         SetupOverlay(button);
    20.     }
    As visible in code snipped, we tried disabling the category
    How can we make sure the UI category remains persistent when binding in the main category with duplicate keys?

    Thanks
    Raul @ MadGoat Studio
     
  31. Elledan3101

    Elledan3101

    Joined:
    May 24, 2013
    Posts:
    18
    hi! can you tell me how to initialize Rewired manually?

    I'm using Zenject and I try to write initialization logic for all game services. And I wrote next code:
    Code (CSharp):
    1.         private void InstallRewired()
    2.         {
    3.             Container.InstantiatePrefab(rewiredInputManagerPrefab);
    4.        
    5.             Player playerInstance = ReInput.players.GetPlayer(playerID);
    6.             Container.Bind<Player>().FromInstance(playerInstance).AsSingle();
    7.         }
    but every time I catch the exception, cause ReInput and Rewired are not initialized:
    Like this one:
    so I tried another way:
    Code (CSharp):
    1.         private void InstallRewired()
    2.         {
    3.             GameObject initializerGO = new GameObject();
    4.             var initializer = initializerGO.AddComponent<Rewired.Initializer>();
    5.             initializer.inputManagerPrefab = rewiredInputManagerPrefab;
    6.             initializer.Initialize();
    7.        
    8.             Player playerInstance = ReInput.players.GetPlayer(playerID);
    9.             Container.Bind<Player>().FromInstance(playerInstance).AsSingle();
    10.         }
    and catch another exception... on the raw with the "var initializer = initializerGO.AddComponent<Rewired.Initializer>();" code. I guess, it's because of Initializer.Awake() method.
    so, can you show me the way to Initialize the whole Rewired system manually, please?

     
    Last edited: Apr 19, 2022
  32. WeAreMelmoss

    WeAreMelmoss

    Joined:
    Apr 12, 2014
    Posts:
    3
    Hi! Great asset, thanks for all the hard work. Was wondering if you can clarify something ? I like to quickly prototype ideas using visual scripting and so far have had zero problems using Unity 2020 and Bolt. Now that 2021 LTS is out and Bolt has been absorbed under just "visual scripting" will you be looking to update the integration package to work with this ? From what I can tell Rewired still works with the new version in terms of units added via the wizard but I suspect there will be problems without access to the events provided in the package ? All the best.
     
  33. _DS_1

    _DS_1

    Joined:
    Sep 6, 2016
    Posts:
    17
    Hi! I have a question, How to Swap Actions through code?

    For example, I have a "Jump" mapped to "Action Button Row 1" and "Fire" mapped to "Action Button Row 2"

    But at some point I just want to swap "Jump" to "Action Button Row 2" and "Fire" to "Action Button Row 1" and be able to revert this without having the player to press a button,


    This is what I been trying, any idea on how to make this?

    Code (CSharp):
    1.             ActionElementMap firstActionElement = m_PlayerInputController.controllers.maps.GetFirstButtonMapWithAction("Fire", false);
    2.             ActionElementMap secondActionElement = m_PlayerInputController.controllers.maps.GetFirstButtonMapWithAction("Jump",  false);
    3.  
    4.             InputAction firstAct = ReInput.mapping.GetAction(firstActionElement.actionId);
    5.             InputAction secondAct = ReInput.mapping.GetAction(secondActionElement.actionId);
    6.  
    7.             // Create a new instance
    8.             InputMapper inputMapperFirst = new InputMapper();
    9.             inputMapperFirst.options.timeout = 0;
    10.             inputMapperFirst.options.defaultActionWhenConflictFound = InputMapper.ConflictResponse.Replace;
    11.  
    12.             InputMapper.Context firstContext = new InputMapper.Context()
    13.             {
    14.                 actionId = firstAct.id, // the id of the Action being mapped
    15.                 controllerMap = map, // the Controller Map which will have the new mapping added
    16.                 actionElementMapToReplace = firstActionElement // the Action Element Map to be replaced (optional)
    17.             };
    18.  
    19.             inputMapperFirst.Start(firstContext);
     
  34. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,499
    See this:
    https://guavaman.com/projects/rewired/docs/HowTos.html#conflict-checking
     
    Raul_T likes this.
  35. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,499
    There is nothing special about the Rewired Input Manager. It is a GameObject with a MonoBehaviour component on it. Instantiate the enabled GameObject and Awake will run and Rewired will initialize. The GameObject must be enabled or Awake will not run and any calls to the Rewired API will throw exceptions. Any scripts in your project that have any code in them that calls any Rewired functions must run after the function that instantiates the Rewired Input Manager or you will get exceptions. You probably have an order of execution issue.
     
    Last edited: Apr 20, 2022
  36. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,499
    I won't be remaking the events for Unity's fork of Bolt. The events were always somewhat of a hack only put in place because of some user's request. Bolt and Unity scripting are designed to create functions from every part of the API so the same C# code is be used to create the visual scripting actions. Bolt was never written with the intention that an "integration" should be written that adds special functions specifically for that tool. I ran into problems doing so that required the author of Bolt to make changes after the fact because he broke the methods I was using to create the event actions in a later update. I should never have made the integration as I knew it was somewhat of a hack when the user proposed it to me. I'm not going to do that again. Unity's system can be used with Rewired using the polling function for getting input. If you must use the events for getting input, use C#.
     
    Last edited: Apr 20, 2022
  37. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,499
    "Swapping" bindings is no simple task because of all the different types of mappings involved and the potential for creating additional binding conflicts and is not a feature of Input Mapper and I have no tutorial for you to show you how to do it. Control Mapper has a swap functionality due to user demand, so I suggest you look into the Control Mapper source code to see how it was done.
     
  38. Elledan3101

    Elledan3101

    Joined:
    May 24, 2013
    Posts:
    18
    well... my problem is: when I instantiate Rewired Input Manager and ask ReInput to give me the Player with ID, ReInput tells me something like "dude, I'm not ready yet".
    when Rewired Input Manager instance is already on the scene (before I press "Play" button), Rewired initializes automatically (thanks to Script Execution Order).
    The last situation makes me set Rewired Input Manager instance for each gameplay scene in my game. I really don't like it, cause my game designer can remove this accidentally and brake the game (human factor, you know..,).
    So the ProjectContext of the Zenject lets me instantiate and initialize game systems just once before my game started. I'm talking about game systems that need to work on every scene like localization system, input system (like Rewired), save/load system, audio system, and so on...

    do you have any advice for me?
     
  39. Raul_T

    Raul_T

    Joined:
    Jan 10, 2015
    Posts:
    363
  40. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,499
    The error you're describing cannot happen if Rewired really is being instantiated before you're calling a Rewired function. Rewired runs its initialization in Awake. That means the instant the enabled GameObject is instantiated, Unity calls Awake on it and Rewired initializes. ReInput.isReady will be true on the same frame right after initialization before the next line of code executes. This is not an asynchronous process. There's no possible way it would initialize later than Awake. Awake is the only code path that can initialize Rewired.

    If you're using the Rewired Initializer, it will instantiate the specified prefab of the Rewired Input Manager on Awake. If you are manually instantiating the Rewired Initializer and it is enabled when instantiated, it will immediately instantiate the Rewired Input Manager which will in turn immediately initialize before the thread continues to the next line of code.

    So what you're telling me is happening just doesn't match with the design of the code. I think your problem is either in your prefab or the Container.InstantiatePrefab method.

    I don't know what code executes in Container.InstantiatePrefab. Is it calling Object.Instantiate immediately when called? Are you certain "rewiredInputManagerPrefab" is a valid reference to a Rewired Input Manager prefab? Are you certain this prefab's GameObject is enabled and the Rewired Input Manager component on this prefab is enabled? Unity will not call Awake on a MonoBehaviour of a disabled GameObject until it is enabled. Likewise, it will not call Awake on a MonoBehaviour component that is disabled.

    Why would you be building the Rewired Initializer manually via code? Yes, the exception is happening because Awake is called on the Rewired.Initializer component immediately when added to the GameObject, but of course it has no Rewired Input Manager prefab reference at that time and throws an exception. If you want to instantiate the Rewired Initializer in code, create a prefab out of it that has a reference to the Rewired Input Manager. Then here in this code, instantiate that prefab. Again, the GameObject and Component have to both be enabled for Awake to execute.
     
    Elledan3101 likes this.
  41. Hi_ImTemmy

    Hi_ImTemmy

    Joined:
    Jul 8, 2015
    Posts:
    174
    Hello,

    In my game, I want there to be an option that the player can use to adjust joystick sensitivity. Is there a page or an example about how to modify values of Rewired via a Unity UI? Thanks.
     
  42. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,548
  43. jesiebieszczu

    jesiebieszczu

    Joined:
    May 29, 2021
    Posts:
    21
    Pre-purchase / pre-testing question - does it work with current version of corgi engine and if yes, is there any tutorial on how to set it up to work with it?

    Thanks.
     
  44. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,499
    The purpose of Rewired's examples is not to show how to build or deal with user interfaces. UI is outside the responsibility of input the input system, so examples, while they may include UI out of necessity, are not intended to show the right way of doing UI-related things. Only getting/setting the actual sensitivity value is the responsibility of the input system. The implementation of the UI used to modify that value is up to the developer.

    There are two separate ways of managing sensitivity:

    1. Input Behavior - Applies a sensitivity multiplier to certain the Action value of all Actions associated with that Input Behavior. This applies to all controllers of the specific type (Joystick Axis Sensitivity applies to ALL controllers, not a specific controller.)
    https://guavaman.com/projects/rewired/docs/InputBehaviors.html

    2. Controller Axis - Applies sensitivity to the Controller Axis value which affects all Actions that are bound to that axis. This applies to only the specific axis on the specific controller. This is part of calibration. https://guavaman.com/projects/rewired/docs/HowTos.html#calibrating-controller-axes

    Which one you choose to use is up to your needs.

    Control Mapper shows both types of sensitivity in use.
     
    Last edited: Apr 27, 2022
  45. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,499
    I don't test every version of Corgi Engine More Mountains releases, so I don't know the answer to that.

    Set instructions are here:
    https://guavaman.com/projects/rewired/docs/Integration.html#CorgiEngine
    • Corgi Engine v4.0 (No future version compatibility is guaranteed.)
    I recently made ugly changes to the integration code because of more breaking changes made by the author. This can be seen in the release notes:

    1.1.41.4:
    - Changed Corgi Engine integration to use reflection to get value of base InventoryInputManager.InventoryOpen because of breaking changes changing the name of this field to InventoryInputManager.InventoryIsOpen with no way to branch code to support both versions.

    The best way to find out is to download the trial and see.
     
  46. Hi_ImTemmy

    Hi_ImTemmy

    Joined:
    Jul 8, 2015
    Posts:
    174
    Unity Ver: 2019.4.35f1
    Rewired Ver: 1.1.41.5.U2019 (I upgraded from 1.1.40.0.U2019. The same problem persists)
    Windows 10 Home

    I'm having problems getting a Dual Shock 4 controller to work in editor. If I build my game and play, the Dual Shock works.

    At the moment, Rewired correctly registers the connection and can see the controller, however no input values are being received when looking at the debug information. Everything works fine with an Xbox 360 controller.



    I've followed the flow of debug checks outlined here and everything seems good. The joystick appears in Rewired. The joystick is recognized. The joystick is assigned to the player. The joystick has a map. Also, worthy of note is that Windows' Game Controller properties is correctly seeing and registering all inputs from the controller.

    If I load the EightPlayers demo, the Dual Shock again fails to work in the editor.

    I'm unsure what my next step should be.
     
    Last edited: Apr 28, 2022
  47. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,548
    (1) Unity version?
    (2) Rewired version? It looks like you are using an older release. The most current is 1.1.41.5
    You should upgrade to the latest Rewired version and try again.
    (3) Is this problem only in the editor and not a build? The dualshock4 works fine a real build? For example if you build the rewired 8 player example..
    (4) Windows version?
     
    guavaman likes this.
  48. Hi_ImTemmy

    Hi_ImTemmy

    Joined:
    Jul 8, 2015
    Posts:
    174
    Please disregard this. I just tried running the project on a different PC and the Dual Shock is working fine in editor. It must be an issue with some sort of device driver.

     
  49. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,499
    Remove any 3rd party drivers / tools like DS4 Win that affect the DS4. Those tools do not work well with Steam and will very likely cause you problems. And that's probably the most important question here -- is Steam involved? If Steam is ever initialized during a Unity Editor session, it will remain hooked even after Play is stopped, so the Eight Players demo scene would behave differently if run immediately after starting the editor than it would after starting another scene first in an editor session that initializes Steam.

    https://guavaman.com/projects/rewired/docs/Troubleshooting.html#steam
     
  50. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,499
    Agreed. 1.1.40.0 is 6 months older than 1.1.41.5.