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

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,766
    I'm having issue setting up a custom theme. On the calibrate controller window, after I select a button, the button takes the "Disabled Highlighted Color". This happens to every button after I press on it. (I've attached one of the themes)

    buttonColors.jpg
    .
     

    Attached Files:

    Last edited: May 2, 2018
  2. longroadhwy

    longroadhwy

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

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    That is exactly what is supposed to happen. You have the button selected. It's now selected so the user can't press it again. It's also still highlighted so the user can navigate it with a joystick/keyboard. If it didn't do that, they could not navigate over disabled buttons.
     
  4. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
  5. Sendatsu_Yoshimitsu

    Sendatsu_Yoshimitsu

    Joined:
    May 19, 2014
    Posts:
    691
    I'm curious, do you have any guesses on when you'll have time to upgrade to Unity 2018? (I'm assuming/hoping no big changes are required on your end, but you never know :) )
     
  6. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    There are other big additions coming that are delaying the release. It will be supported in the next update.
     
  7. Sendatsu_Yoshimitsu

    Sendatsu_Yoshimitsu

    Joined:
    May 19, 2014
    Posts:
    691
    Oh cool, I'll look forward to it! Thanks for keeping us updated. :)
     
    guavaman likes this.
  8. IceBeamGames

    IceBeamGames

    Joined:
    Feb 9, 2014
    Posts:
    170
    Hey guavaman, more questions I'm afraid.

    I've implemented your basic ShowControllerGlyphs class into my project, but I'm having problems on console when there isn't a controller attached. Currently, its returning keyboard entries.

    What is the best way to get the ActionElementMap or the elementIdentifierId from the player's maps if the controller isn't connected? I've set up a simple look up class which matches the RuntimePlatform to a default HardwareJoystickMap so I have the type of controller but I'm not sure how you interrogate the player to gets maps from controllers which aren't currently connected?
     
    Last edited: May 3, 2018
  9. LitchiSzu

    LitchiSzu

    Joined:
    May 14, 2016
    Posts:
    17
    @guavaman Hi there!
    Sorry for the bother but, we've just updated yesterday to 2018.1 and it seems that Input doesn't work anymore when the app is out of focus. Was working all fine in 2017.
    Run in the Background is still checked, I've checked the InputManager too and the settings are the same as before.
    We are on Windows using Xbox/XboxOne controllers.

    Any idea of what we could do to work around that?

    Thanks!
     
  10. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
  11. FM-Productions

    FM-Productions

    Joined:
    May 1, 2017
    Posts:
    72
    You probably won't reveal this, but I am patiently waiting for a discount on Rewired in the May Mayhem sale. I just wanted to know if Rewired is participating in the sale later to or if the price stays (It's worth every cent, don't get me wrong).
    But if you can confirm that there is no sale, I can stop checking the store every day :)
    Still will buy it later eventually.
     
  12. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    Just tested myself and there's no problem. Indeed, I can think of no way that changing the Unity version would be able to affect this.

    1. Ensure "Run in Background" is set in your Unity Player settings. Rewired cannot possibly update without this enabled.
    2. Do not use IL2CPP scripting backend on Windows Standalone. This does not work at this time. IL2CPP builds on Standalone platforms will run in non-native Unity input mode and a ton of features will be unavailable.
     
  13. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    Rewired is not on sale and likely won't be participating in any Unity sales in the future. Rewired's price is already too low for the amount of time I have spent and continue to spend on it in the last 4 years. I also do not agree with the constant fire sale mentality in the digital goods industries. Selling a product for 50% or more off implies the true value of that product is half or less than the asking price. The counter argument is increased sales volume, but with developer software like Rewired, volume means increased support which takes a huge amount of time.

    Thanks!
     
  14. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    It's good to see they jumped on fixing it quickly unlike the terrible and constantly evolving Xbox One controller problems in the first 2+ years of Windows 10 and updates. Thanks for posting these!
     
  15. IceBeamGames

    IceBeamGames

    Joined:
    Feb 9, 2014
    Posts:
    170
    Don't forget my question please! :)
     
  16. LitchiSzu

    LitchiSzu

    Joined:
    May 14, 2016
    Posts:
    17
    Thank you for your reply.
    After a bit more testing, it works fine in builds, but not in the Editor. Which is a shame as the feature is mostly useful for us in Editor and is quite important (people have been moaning all day about it here haha).
    I've tested opening the project again in 2017.3 and it works fine, even in Editor, back to 2018.1 and it doesn't work if the Game window is not focused.
    We are sure that Run in Background is checked since, well, it's running.
     
  17. goat

    goat

    Joined:
    Aug 24, 2009
    Posts:
    5,182
    I think in Unity 2018.+ for UWP that only IL2CPP is available when 2018.2 is complete is on Windows platforms. 2018.1 was released recently.

    I think that rewired is already a fair price, so no sale price was needed for me to buy.
     
  18. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    You can't do that. The Player has no maps loaded if the Controller is not assigned to it. Maps are loaded at the time of assignment.

    There is no good way to do what you want to do. The reasons are myriad, but in short, there's no way Rewired can know what Controller Definition it should load from a Hardware Joystick Map until that controller is connected. The input source managers in use and specific information from the attached controller are used to determine which specific sub-definition to load from the Hardware Joystick Map. Since the controller may be handled by one of many input source managers depending on specific things about the controllers, there's just no way to know what would be loaded.
     
    IceBeamGames likes this.
  19. IceBeamGames

    IceBeamGames

    Joined:
    Feb 9, 2014
    Posts:
    170
    So what's my best choice if a person loads up a level on console and the batteries run out on the pad or something and I'm trying to show icons for a prompt?

    Can I set-up some sort of default look up?

    (At this point I'd take any hack as long as it works, even if it only shows the default controls or something).
     
  20. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    Every single thing Rewired does with regards to the editor was painstakingly figured out by trial and error for each version on each Editor platform. If Unity decided to change some internal thing with how the active game window is detected/reported or how it works with regard to window handles and input events on Windows (and they've done this in the past), that will break Rewired's ability to use that. It's a running game of cat and mouse to keep up with their undocumented under-the-hood changes. Brand new releases of the Unity editor will break Rewired's ability to do everything it wants to do in the editor. Trial and error reverse engineering and new special-case code for the new editor change have to be added for it to work again as before. I will look into it.

    And just so you know, Unity 2018 is not officially supported yet. You are running Rewired U2017 in Unity 2018. A new branch of Rewired is going to be released for Unity 2018.
     
    IceBeamGames likes this.
  21. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    IL2CPP for Windows is also in 2018.1. That's where I've done my testing and found the problems with it.

    Thanks!
     
  22. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    Followup: The issue comes down to Unity now incorrectly reporting UnityEngine.Screen.fullScreen as true in the editor at all times. This is a bug in Unity. I will come up with some kind of workaround.
     
  23. LitchiSzu

    LitchiSzu

    Joined:
    May 14, 2016
    Posts:
    17
    Thank you very much for the quick reply : ) Hopefully Unity will fix the issue on their side quick enough if you can't find a workaround.
    Thanks for your work on Rewired :)
     
    guavaman likes this.
  24. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    I tried to explain before why a default lookup for a Controller Map when the Joystick is not present is not possible due to all the factors involved (even which maps are chosen to load is dependent on the Joystick which may or may not match the guid you expect depending on the platform, the input source(s) in use, and the particulars of the connected device). I can't really explain it properly without going through a huge amount of detail about how things work at a low level. It's extremely complicated, and even more so when dealing with Controller Templates. It's impossible to do it right now without new functions specifically designed for this purpose. (All the functions required to hack something from the raw data won't work because they're not exposed publicly.) I will look into what I might be able to do about this. At this point, the only choice is to hard code defaults to display on this platform when no joystick is connected.
     
    Last edited: May 3, 2018
    IceBeamGames likes this.
  25. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    I have come up with some semi-workable solution to load a default Controller Map. It's far from perfect and there are a lot of caveats with different input source(s), etc. where it will not necessarily return the same Controller Map that it would have with the actual device plugged in, but it should probably work for your purposes. It will be an additional overload of ReInput.MappingHelper.GetJoystickMapInstance that takes a GUID instead of a Joystick object. This will not take into account any saved user XML data and will not reflect those changes.

    If you want a beta to try, please contact me on the support form on the website.
     
    IceBeamGames likes this.
  26. IceBeamGames

    IceBeamGames

    Joined:
    Feb 9, 2014
    Posts:
    170
    I appreciated this very much guavaman.

    I was thinking my other option was putting the default action names into each of the controller entries and then comparing the platform and action name. Actually, to be honest, I might try that first, as I just updated rewired and had to merge the control mapper changes we did for localisation.
     
  27. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    The error explains itself at the top and even shows you the inner exception the code is throwing:

    Rewired: An exception occurred inside an event handler or callback.
    Source: Player input event callback

    This happens if your event handler code throws an exception. It can also happen if you forget to unsubscribe to an event in a MonoBehaviour class and that object gets destroyed. Make sure you unsubscribe to events in OnDisable or OnDestroy. Rewired will attempt to continue running.

    ...

    Exception:
    System.ExecutionEngineException: Attempting to JIT compile method 'System.Collections.Generic.Dictionary`2<string, string>:Do_CopyTo<System.Collections.Generic.KeyValuePair`2<string, string>, System.Collections.Generic.KeyValuePair`2<string, string>> (System.Collections.Generic.KeyValuePair`2<string, string>[],int,System.Collections.Generic.Dictionary`2/Transform`1<string, string, System.Collections.Generic.KeyValuePair`2<string, string>>)' while running with --aot-only.

    ------------------

    The code you are executing in the Player input event callback is throwing this exception, not Rewired, unless it's another call to a Rewired method in your code, but it doesn't show that information.

    As for the exception, "System.ExecutionEngineException: Attempting to JIT compile method 'System.Collections.Generic.Dictionary`2<string, string>:Do_CopyTo<System.Collections.Generic.KeyValuePair`2<string, string>,", I can't interpret this in any other way than something is wrong with the Generic Dictionary class.
     
    Last edited: May 4, 2018
  28. IceBeamGames

    IceBeamGames

    Joined:
    Feb 9, 2014
    Posts:
    170
    Yeah, my bad. I think its because I am serializing with something that uses JIT. Weird I've never seen the error before now.
     
  29. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    Didn't notice this was Control Mapper's callback causing this error. Looking deeper.

    The important part of the stack trace:
    at UnityEngine.Events.UnityEvent.Invoke () [0x00000] in <filename unknown>:0

    This is all being fired off by UnityEngine.Events.UnityEvent.Invoke (). They have some kind of error in there that prevents UnityEvent from working on PS4 apparently. You should report this bug to Unity.

    Comes from ControlMapper.cs line 2898:
    if(_onScreenClosed != null) _onScreenClosed.Invoke();

    Edit:
    Oh I see. It's your custom serializer hooking into the serialization process. Makes sense.
     
  30. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    I would suggest you copy ControlMapper.cs and any other files you need to modify, rename them or change the namespace, and replace the components on your Control Mapper objects instead.
     
  31. allornothingJM

    allornothingJM

    Joined:
    Feb 3, 2015
    Posts:
    20
    Hi @guavaman - we're seeing some weirdness in the profiler and wondering if you can help at all. Is this normal, when using rewired to just move up and down a UI menu? This snapshot is pressing up arrow key to move a cursor once - although it's hard to debug when the names look like this in deep profile

    upload_2018-5-6_15-27-0.png
     
  32. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    If by weirdness you're referring to the GC Alloc of 17 bytes, yes that is normal, is due to a bug/change in Unity 2017, and only happens in the Editor.

    If you turn off Deep Profile, you'll see where its actually coming from:

    IsCompiling.png

    In the InputManager.cs script included in the project, this function is called:

    Code (csharp):
    1. protected override void CheckRecompile() {
    2. #if UNITY_EDITOR
    3.     // Destroy system if recompiling
    4.     if(UnityEditor.EditorApplication.isCompiling) { // editor is recompiling
    5.         if(!isCompiling) { // this is the first cycle of recompile
    6.             isCompiling = true; // flag it
    7.             RecompileStart();
    8.         }
    9.         return;
    10.     }
    11.  
    12.     // Check for end of compile
    13.     if(isCompiling) { // compiling is done
    14.         isCompiling = false; // flag off
    15.         RecompileEnd();
    16.     }
    17. #endif
    18. }
    The line "UnityEditor.EditorApplication.isCompiling" is responsible for the memory allocation. This does not generate garbage in Unity 4 or 5 but does in Unity 2017.

    I get people asking about this fairly regularly, but there's nothing I can do about it if I want to be able to detect when the Editor is compiling for various needs in the Unity Editor. Again, it happens only in the editor. Rewired generates zero garbage per frame in the normal loop (apart from doing things like control remapping, etc.)
     
    Last edited: May 6, 2018
  33. io3creations

    io3creations

    Joined:
    May 18, 2015
    Posts:
    11
    A very belated thank you for your reply. I was waiting for your reply for a while then moved on to other things and am only returning to those aspects now. Oddly, I don't recall receiving notification of your reply so it's a good thing that I went back and checked.

    I came across an interesting situation.
    I've been using
    interactionStart = player.GetButtonDown("Interaction");
    to check when the player presses the "Interaction" button (e.g. mouse left button) and
    moveVector.x = player.GetAxis("Move Horizontal");
    to check the amount of movement.

    The issue happens for the following situation. In my game, certain objects can be rotated in 3d by clicking on them and moving the mouse/finger. On PC, when the mouse button is released and clicked again, rotation is fine. But on the Android phone, the rotation will take into account the distance from where the finger last touched the screen. Is that expected behavior?

    I was thinking about a way to delay the input check with one update but found a "quick hack" that seems to do exactly that and works fine so far.
    interactionStart = player.GetButtonPrev("Interaction");
    I'm just wondering if there is a different and better way?
     
  34. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    This is Unity. Rewired uses UnityEngine.Input for all input on the Android platform. (Non-native support platform.) UnityEngine.Input.GetAxis("Mouse X") behaves exactly as you describe on Android when using a touch screen. It's giving you a pixel delta value just like a mouse normally does. How far did the mouse move this frame? Well, on Android, the mouse cursor moves to your last touch location. The next time you touch, it just moved that many pixels which is what it's returning.

    You might want to look into UnityEngine.Input.simulateMouseWithTouches.
     
  35. io3creations

    io3creations

    Joined:
    May 18, 2015
    Posts:
    11
    I see, thanks. I'll look into it.
     
  36. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    Rewired 1.1.13.0 is now available for registered users to download. If you would like access to early updates, please contact me here.

    Please see Updating Rewired before updating.

    The biggest changes in this release:
    • Unity 2018 branch released.
    • Controller Templates system has been revamped. Now you can access the template at runtime through scripting for a variety of purposes.

    Release Notes:

    1.1.13.0:

    Changes:
    - Added Unity 2018 branch.
    - Added Initializer system for spawning the Rewired Input Manager in scenes as necessary.
    - Added option to create Rewired Input Manager prefab asset file directly.
    - Added data compact, import, export tools in Rewired Input Manager.
    - Added script-accessible runtime Controller Template system.
    - Added Gamepad Template UI example (Unity 5+).
    - Rewired Editor: Constant exporter now remembers last save location and file name.
    - Updated Bolt integration for compatibility with Bolt 1.3. Bolt 1.3 is now the minimum supported version.

    Controller Templates:
    - Modified all Templates for new runtime Controller Template system.
    - HOTAS Template: Changed "Throttle Zero Detent" element identifier names to "Throttle Min Detent".
    - Flight Yoke Template: Changed "Lever Zero Detent" element identifier names to "Lever Min Detent".
    - Dual Analog Gamepad Template: Changed name to "Gamepad", changed Left Shoulder 2 and Right Shoulder 2 to Axis type elements.

    Controller Definitions:
    - Sony DualShock4: Added support for wireless mode on Android.

    API Changes:
    - Added Initializer class.
    - Added Controller.GetElementById method.
    - Added Controller.Element.id property.
    - Added Controller.Element.elementIdentifier property.
    - Added Controller.CompoundElement.id property.
    - Added Controller.CompoundElement.elementIdentifier property.
    - Added ControllerElementIdentifier.GetDisplayName method.
    - Added ControllerTemplate class.
    - Added ControllerTemplateElementIdentifier class.
    - Added ControllerTemplateElementType enum.
    - Added IControllerElementTarget interface.
    - Added IControllerTemplate interface.
    - Added IControllerTemplateAxisSource interface.
    - Added IControllerTemplateButtonSource interface.
    - Added IControllerTemplateElement interface.
    - Added IControllerTemplateButton interface.
    - Added IControllerTemplateAxis interface.
    - Added IControllerTemplateAnalogTrigger interface.
    - Added IControllerTemplateStick interface.
    - Added IControllerTemplateThumbStick interface.
    - Added IControllerTemplateDPad interface.
    - Added IControllerTemplateThrottle interface.
    - Added IControllerTemplateHat interface.
    - Added IControllerTemplateYoke interface.
    - Added IGamepadTemplate interface.
    - Added IFlightPedalsTemplate interface.
    - Added IFlightYokeTemplate interface.
    - Added IHOTASTemplate interface.
    - Added IRacingWheelTemplate interface.
    - Added GamepadTemplate class.
    - Added FlightPedalsTemplate class.
    - Added FlightYokeTemplate class.
    - Added HOTASTemplate class.
    - Added RacingWheelTemplate class.
    - Added ReInput.ControllerHelper.GetControllerTemplates method.
    - Added Player.ControllerHelper.GetControllerTemplates method.
    - Added Player.ControllerHelper.GetFirstControllerWithTemplate method.
    - Added Player.ControllerHelper.MapHelper.GetFirstElementMapWithElementTarget method.
    - Added Player.ControllerHelper.MapHelper.ElementMapsWithElementTarget method.
    - Added Player.ControllerHelper.MapHelper.GetElementMapsWithElementTarget method.
    - Player.ControllerHelper.MapHelper.GetAllMaps(..., List<ControllerMap> results) method overloads.
    - Player.ControllerHelper.MapHelper.GetAllMapsInCategory(..., List<ControllerMap> results) method overloads.
    - Player.ControllerHelper.MapHelper.GetMapsInCategory(..., List<ControllerMap> results) method overloads.
    - Player.ControllerHelper.MapHelper.GetButtonMapsWithAction(..., List<ControllerMap> results) method overloads.
    - Player.ControllerHelper.MapHelper.GetAxisMapsWithAction(..., List<ControllerMap> results) method overloads.
    - Player.ControllerHelper.MapHelper.GetElementMapsWithAction(..., List<ControllerMap> results) method overloads.
    - ControllerMap.GetElementMaps(..., List<ActionElementMap> results) method overloads.
    - ControllerMap.GetElementMapsWithAction(..., List<ActionElementMap> results) method overloads.
    - ControllerMap.GetButtonMaps(..., List<ActionElementMap> results) method overloads.
    - ControllerMap.GetButtonMapsWithAction(..., List<ActionElementMap> results) method overloads.
    - ControllerMapWithAxes.GetAxisMaps(..., List<ActionElementMap> results) method overloads.
    - ControllerMapWithAxes.GetAxisMapsWithAction(..., List<ActionElementMap> results) method overloads.
    - Added ControllerMap.GetFirstElementMapWithAction(string actionName, bool skipDisabledMaps) method overload.
    - Added ControllerMap.GetFirstElementMapWithElementTarget method.
    - Added ControllerMap.ElementMapsWithElementTarget method.
    - Added ControllerMap.GetElementMapsWithElementTarget method.
    - Added ActionElementMap.actionDescriptiveName method.
    - Added ActionElementMap.IsTarget method.
    - Added ReInput.MappingHelper.GetJoystickMapInstance(Guid joystickTypeGuid, ...) method overloads.

    Bug Fixes:
    - Constant exporter now allows periods in namespace names (for nested namespaces).
    - When deleting a Controller Map Category or a Layout, Player default Controller Map assignments that use the deleted Category / Layout are removed.
    - Controller.Elements no longer always returns null.
     
  37. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    This is a great update. So many things to try out. @Steve-Tack this is for you.
     
  38. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    I know @Steve-Tack created his own Controller Templates. That will also work with the new system including having all the template elements accessible in code by name. The last 3 lines of this topic show how to generate the code for the templates and enable using the user-defined templates instead of the defaults. (The "use user-defined Controller Templates" switch was done so you can export your own set even if it includes some of the original templates and there won't be any clashes, and you won't lose anything or have to re-do anything when updating Rewired.)

    You can even get input directly from the Controller Template elements if you want. Generally, there's no real reason to get input through Controller Templates unless you just want to program to the controller like in most traditional input systems instead of to the Action. One of the main reasons this was added though was for users who are not using Rewired's Player-Action system and have instead written their own Action binding system (I'm aware of one major game that does this.) You can still get all the benefits of Rewired's controller recognition, etc., now even if you don't use the Action system. However, there are some other subtle benefits of being able to get input from a Template such as making a "press-start-to-join" system somewhat easier to do.

    The most requested use of the Controller Template system was to display generalized UI help / glyphs using the template so they don't have to define glyphs for a million gamepads.

    The Controller Templates also show up in Debug Information.
     
    Last edited: May 9, 2018
    IceBeamGames likes this.
  39. Steve-Tack

    Steve-Tack

    Joined:
    Mar 12, 2013
    Posts:
    1,240
    Well I am still working on the same hobby game from way back then. Luckily when you released the official HOTAS template, I switched to that, and that's been working great. So I'm thinking I don't need to do anything after updating, right? I'm only using built-in templates at this point.

    I do remember some funkiness with trying to interpret HOTAS device inputs for UI glyphs, so getting the names from the templates could be helpful.

    I'll continue to use Actions for 100% of my stuff. That level of indirection to me is one of the biggest benefits of Rewired.
     
    guavaman likes this.
  40. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    Ah, okay. Good to hear the HOTAS template is working well for you. No, you don't need to do anything differently. Everything will continue to work as before. Actions are definitely the way to go for most games.
     
  41. IceBeamGames

    IceBeamGames

    Joined:
    Feb 9, 2014
    Posts:
    170
    EDIT: Removed discussion.
     
    Last edited: May 11, 2018
  42. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    Xbox One user management variables are passed through directly from UnityEngine.XboxOneInput. It's just a wrapper. These vales are managed by Unity's system. If it's giving you the wrong values, there has to be some bug in Unity. There is no procedure I am aware of to make this work or function any differently.
     
  43. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
  44. Sendatsu_Yoshimitsu

    Sendatsu_Yoshimitsu

    Joined:
    May 19, 2014
    Posts:
    691
    I have a bit of a weird input setup on my development machine, I'm using DS4Windows on Windows 8 to run a Dualshock 4 like it's an xbox controller. It works perfectly with Rewired out of the box, but I do get a warning every time it runs. I put the full error below, is this caused by an error in how I configured it, or should I just ignore it?


    Rewired: Failed to open HID device for reading. This device (Unknown) may not function.
    ------- Rewired System Info -------
    Unity version: 2018.1.0f2
    Rewired version: 1.1.3.0.U2018
    Platform: Windows
    Editor Platform: Windows
    Using Unity input: False
    Primary input source: RawInput
    Use XInput: True
    Native mouse handling: True
    Enhanced device support: True

    UnityEngine.Logger:LogError(String, Object)
    Rewired.Logger:LogErrorNow(Object, Boolean)
    Rewired.Logger:LogError(Object, Boolean)
    Rewired.Logger:LogError(Object)
    Rewired.InputManagers.Initializer:Initialize(ConfigVars)
    Rewired.InputManager_Base:InitializePlatform(ConfigVars)
    Rewired.ReInput:ZDrdlkDCTmhWXaRoSyYHUJgZicmF(Func`2)
    Rewired.ReInput:kTPdHHIvSxjBUkXxYKEXUkmlXEe(InputManager_Base, Func`2, ConfigVars, ControllerDataFiles, UserData)
    Rewired.InputManager_Base:Initialize()
    Rewired.InputManager_Base:Awake()
    UnityEngine.Object:Instantiate(Object)
    Rewired.Utils.UnityTools:Instantiate(Object, Vector3, Quaternion, Transform, Boolean)
    Rewired.Utils.UnityTools:Instantiate(Object, Transform, Boolean)
    Rewired.Initializer:Initialize()
    Rewired.Initializer:Awake()
     
  45. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    You can only ignore it. Something is going wrong when Rewired tries to open the HID device. It's probably working through XInput. Rewired can't open the HID device if Windows won't allow it for whatever reason and that's the error you are seeing. The only thing I can do is just swallow the error so you never see it, but that may make debugging other actual hardware problems more difficult. The issue is probably in DS4Win.
     
  46. Sendatsu_Yoshimitsu

    Sendatsu_Yoshimitsu

    Joined:
    May 19, 2014
    Posts:
    691
    Hmkay, thanks! And yeah, definitely don't hide the error- I'm assuming it's a pretty obscure problem... maybe it's linked to that weird RI.HID bug that Unity's native raw input processor is prone towards? I know for a fact DS4Windows triggers that guy sometimes.
     
  47. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    I can think of some ways I work with the various Throttles that scripting can be useful this could be very useful Especially when you have multiple throttle quadrants. Thanks for providing so many options with Rewired.
     
  48. jmdeb

    jmdeb

    Joined:
    Jul 28, 2017
    Posts:
    23
    Just curious to know: is there by chance some method to check if there were no button/key/mouse events for a time lapse? In other words, in the Rewired context, the time past since last action!? (I'm willing to implement a kind of screensaver...and need to run actions after X time of total (button/key/mouse) inactivity!
    Thanks
     
    Last edited: May 10, 2018
  49. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    No, Rewired does not track the last time a Player had any active input. This doesn't sound like something that would make a lot of sense to track for Player Actions, though you could do so pretty easily using Player input events:

    Code (csharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Rewired;
    5.  
    6. public class ScreenSaverTest : MonoBehaviour {
    7.  
    8.     public float timeout = 30f;
    9.  
    10.     private float lastInputTime;
    11.     private bool screenSaverActive;
    12.  
    13.     // Use this for initialization
    14.     void Start () {
    15.         Player p = ReInput.players.GetPlayer(0);
    16.         p.AddInputEventDelegate(x => { lastInputTime = Time.time; SetScreenSaverActive(false); }, UpdateLoopType.Update, InputActionEventType.AxisActive);
    17.     }
    18.  
    19.     void Update () {
    20.         if(!screenSaverActive && Time.time - lastInputTime > timeout) {
    21.             SetScreenSaverActive(true);
    22.         }
    23.     }
    24.  
    25.     void SetScreenSaverActive(bool value) {
    26.         if(screenSaverActive == value) return;
    27.         screenSaverActive = value;
    28.         if(value) Debug.Log("Start screen saver.");
    29.         else Debug.Log("Stop screen saver.");
    30.     }
    31. }
    I would be more inclined to use the Controllers to determine this because it covers all Controllers regardless of whether or not they're assigned to Players and whether or not any Action is assigned to the button / key:

    Code (csharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Rewired;
    5.  
    6. public class ScreenSaverTest : MonoBehaviour {
    7.  
    8.     public float timeout = 30f;
    9.  
    10.     private float lastInputTime;
    11.     private bool screenSaverActive;
    12.  
    13.     void Update () {
    14.         CheckAllControllers();
    15.  
    16.         if(ReInput.time.unscaledTime - lastInputTime > timeout) {
    17.             if(!screenSaverActive) SetScreenSaverActive(true);
    18.         } else {
    19.             if(screenSaverActive) SetScreenSaverActive(false);
    20.         }
    21.     }
    22.  
    23.     void CheckAllControllers() {
    24.  
    25.         // Check each controller by type instead of using
    26.         // ReInput.controllers.Controllers because this will
    27.         // generate small amounts of garbage to iterate with
    28.         // foreach because it's an IEnumerable. This should
    29.         // probably be changed to another List internally and
    30.         // exposed as an IList so as to avoid this in this use case
    31.         // so you can just check all Controllers in one loop.
    32.  
    33.         CheckController(ReInput.controllers.Keyboard);
    34.         CheckController(ReInput.controllers.Mouse);
    35.  
    36.         int count = ReInput.controllers.joystickCount;
    37.         var joysticks = ReInput.controllers.Joysticks;
    38.         for(int i = 0; i < count; i++) {
    39.             CheckController(joysticks[i]);
    40.         }
    41.  
    42.         count = ReInput.controllers.customControllerCount;
    43.         var customControllers = ReInput.controllers.CustomControllers;
    44.         for(int i = 0; i < count; i++) {
    45.             CheckController(customControllers[i]);
    46.         }
    47.     }
    48.  
    49.     void CheckController(Controller controller) {
    50.         float lastTimeActive = controller.GetLastTimeActive();
    51.         if(lastTimeActive > lastInputTime) lastInputTime = lastTimeActive;
    52.     }
    53.  
    54.     void SetScreenSaverActive(bool value) {
    55.         if(screenSaverActive == value) return;
    56.         screenSaverActive = value;
    57.         if(value) Debug.Log("Start screen saver.");
    58.         else Debug.Log("Stop screen saver.");
    59.     }
    60. }
     
  50. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    If you want to explore this thoroughly and debug to find out what's happening, please contact me via PM or on the support form on the website. Some Xbox One stuff is covered by NDA (anything I didn't find out from other sources before signing one) and shouldn't be discussed publicly here.