Search Unity

Rewired - Advanced Input for Unity

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

  1. MostHated

    MostHated

    Joined:
    Nov 29, 2015
    Posts:
    882
    Awesome thanks, that is much appreciated!
     
  2. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,459
    It looks like you have a couple more versions of Rewired now there is 1.1.19.9 available on the asset store now.

    1.1.19.9:

    Changes:
    - Mouse delta values in Fixed Update are now processed to be consistent with Update on platforms and input sources that use UnityEngine.Input as the underlying input source. Fixed Update must be enabled under Rewired Input Manager -> Settings -> Update Loops.

    1.1.19.8:
    Bug Fixes:

    - Windows Standalone, Raw Input/Direct Input + Native Mouse Handling: Fixed bug introduced in 1.1.19.1 causing mouse input values to be cleared in Update after Fixed Update runs if Fixed Update is enabled in Rewired Input Manager settings.
     
    guavaman likes this.
  3. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,886
    Thanks!
     
  4. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,886
    Looking into the causes of all of this more deeply, I have come to the conclusion that Unity's UI system is incredibly inefficient as it comes to memory allocations. For example, simply disabling or enabling a UI element with a Text, Selectable, or Image component on it causes a lot of garbage to be generated (nearly 1K per object on disable, over 2K per object on enable):

    UnityUIGC.jpg

    Further compounding this, enabling or disabling a UI element also triggers a Canvas rebuild which itself generates a bunch of garbage:

    UnityUIGC2.jpg

    Because of these facts, I see no way possible to avoid garbage using Unity's UI system when dynamically building a UI programatically.
     
    Last edited: Sep 12, 2018
  5. jorge89

    jorge89

    Joined:
    May 28, 2015
    Posts:
    2
    When I use a SteelSeries Nimbus on tvOS I have iOS MFi Gamepad setup and it works perfectly. I'm just having trouble finding a way to not quit my game on tvOS when I use the "B" button. Is there a way Rewired can accomplish this?
     
  6. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,886
    Rewired does not manage anything low-level on iOS or tvOS. Rewired uses UnityEngine.Input for all input on iOS. See the native library platform support list:
    http://guavaman.com/projects/rewired/docs/Overview.html#tested-platforms

    Rewired isn't causing the B button to go back. That would an iOS native setting which can be controlled through Unity's API wrappers. See their documentation on input on iOS:
    https://docs.unity3d.com/Manual/tvOS.html

    I don't see anything that that says the B button should exit the application, but there is behavior that changes depending on the setting of UnityEngine.Apple.TV.Remote.allowExitToHome. That is most likely the cause if B also functions as the Menu button.

    There is also this:

    Warning: due to the Apple TV Remote “Menu” button being reported as joystick button 0 when UnityEngine.Apple.TV.Remote.allowExitToHome is set to false, and the default Input Manager binding “Submit” virtual button being mapped to the same joystick button 0, this button triggers actions on UI
    elements when pressing the “Menu” button. To work around this issue, remove or modify the “Submit” virtual button bindings in the Input Manager
    .
     
    Last edited: Sep 12, 2018
  7. MostHated

    MostHated

    Joined:
    Nov 29, 2015
    Posts:
    882
    I wonder if it would make a difference just to keep the game object enabled but then disable the canvas object on it, I believe that doesn't cause it to trigger a full on redo of everything like onEnable/Disable would. The again, it's not like people are heading into the settings menus to hang out and what not.
     
  8. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,886
    If you're talking about the whole menu, that's one thing, but enabling and disabling individual objects has to happen every single time anything changes on the UI including switching Players, Categories, opening and closing windows, selecting different controllers, and much more. And when Control Mapper is opened and closed, it has to do all that anyway to update the UI to show all the current information, so I don't think it would save anything.
     
  9. IceBeamGames

    IceBeamGames

    Joined:
    Feb 9, 2014
    Posts:
    119
    Hey chaps. Just to chime in, this is a good talk on optimising Unity's UI. It might be worth a check if you want to improve the controller mapper screen.


    One thing I remember him mentioning is to created a lot of nested canvases for each element, so when you update an element, it doesn't update the entire screen.
     
  10. MostHated

    MostHated

    Joined:
    Nov 29, 2015
    Posts:
    882
    I just watched that actually, some really good info in there.
     
  11. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,886
    Thanks for the link.

    Really the only thing in here about UI optimization that would make any difference at all is using nested Canvases, but even then, it would really only be a minimal reduction in the number of objects that have to be redrawn when something changes. And using multiple canvases has the tradeoff of increasing draw calls. So best case, I can see avoiding having to redraw the static buttons on top when some mapping is made, but that's about it. That would add an extra draw call or two impacting real-time performance to save a few objects in the rebuild queue on the canvas when remapping or changing a page. I don't see this as significant.
     
  12. Haapavuo

    Haapavuo

    Joined:
    Sep 19, 2015
    Posts:
    43
    Unity 2018.3.0b1 causes me some issues. Rewired Input Manager spams errors in the console when it is selected in the Hierarchy:

    MissingMethodException: UnityEngine.Object UnityEditor.PrefabUtility.GetCorrespondingObjectFromSource(UnityEngine.Object)
    Rewired.Editor.InputManagerInspector_Internal.OnInspectorGUI () (at <834f04e2bf044420941f2d9a38234238>:0)
    Rewired.Editor.CustomInspector_External.OnInspectorGUI () (at Assets/Rewired/Internal/Scripts/Editor/CustomInspectors/CustomInspector_External.cs:19)
    UnityEditor.InspectorWindow.DoOnInspectorGUI (System.Boolean rebuildOptimizedGUIBlock, UnityEditor.Editor editor, System.Boolean wasVisible, UnityEngine.Rect& contentRect) (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1599)
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)
     
  13. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,886
    Rewired does not support beta Unity releases or beta/experimental features of Unity.

    They obviously made a breaking API change to UnityEditor.PrefabUtility.
     
  14. Haapavuo

    Haapavuo

    Joined:
    Sep 19, 2015
    Posts:
    43
    I don't expect you to support a beta version of Unity. I inform you of this so you know that you will have to find out a way to fix this before 2018.3 goes out of beta. Reporting bugs that occur when using a beta version of Unity gives you a headstart on development. Keep customers happy by taking care of problems early on. :)
     
  15. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,886
    Thanks, I understand. I'm just informing you that betas are not officially supported so you should expect problems.

    What version of Rewired are you using? I just tested with the latest (1.1.19.9) and have no issues. Are you using the 2018 branch? I have a feeling this was fixed 13 releases ago in 1.1.16.0:

    Bug Fixes:
    - Unity 2018.2.0x-ImprovedPrefabs: Fixed exception thrown by the Rewired Input Manager inspector.

    They probably committed these changes in 2018.3.
     
  16. Haapavuo

    Haapavuo

    Joined:
    Sep 19, 2015
    Posts:
    43
    I am using 1.1.7.8.U2017. I didn't know about a 2018 branch. Unity Asset Store only shows me an Import button, not an Update button so I assumed that this is the newest version.
     
  17. Haapavuo

    Haapavuo

    Joined:
    Sep 19, 2015
    Posts:
    43
    Okay. I re-imported the asset from the Asset Store and now it is up to date and working properly. Sorry for the inconvenience!
     
    guavaman likes this.
  18. KrzysztofX10

    KrzysztofX10

    Joined:
    Aug 12, 2017
    Posts:
    7
    Hi everyone,
    I'm having a problem with my Rewired Input Manager (Unity version 2018.1.9f2, Rewired version 1.1.19.9.U2018). After I started adding some more action categories to it (after Menu Navigation and Gameplay Shared), I realised that actions in these new categories were never registering. It turns out that if I create any new action category with any actions in it, these actions are completely unresponsive, even though actions in Gameplay Shared and Menu Navigation are fine. I am attaching a screenshot where you can see my Input Manager setup and the debug inspector screen during play mode - at that particular moment I was pressing square on my PS4 controller, which was mapped both to "Menu Special Action 1" and "Test Square Action", and yet only "Menu Special Action 1" was responding.
    What should I do about this? Has anyone encountered this problem as well?
     

    Attached Files:

  19. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,886
    Action Categories have zero impact on anything in-game. They are strictly organizational.

    Map Categories do.

    You've created a Map Category called Test and created a Joystick Map in the Test category. Did you forget to assign this to your Player on start?

    PlayerControllerMaps.jpg

    You can see the Controller Maps currently loaded in the Player in the Debug Information.

    RewiredPlayerControllerMaps.jpg
     
    Last edited: Sep 14, 2018
  20. KrzysztofX10

    KrzysztofX10

    Joined:
    Aug 12, 2017
    Posts:
    7
    Oh, I did forget to assign the new categories to the player, that's much simpler than I thought! Now this looks quite silly in retrospect, I spent so long trying to debug this - I'm still learning :)
    Thank you very much for your quick reply.
     
    guavaman likes this.
  21. CausalBitGames

    CausalBitGames

    Joined:
    Sep 7, 2016
    Posts:
    10
    Hi @guavaman,

    For some reason we can't get controller vibration working on Xbox One. We are using Unity 2017.4.9f1, Rewired version 1.1.19.9.U2017, May 2018 QFE1 XDK.
    Things we've tried:
    • Calling Player.SetVibration;
    • Calling Joystick.SetVibration;
    • Calling XboxOneGamepadExtension.SetVibration;
    • Setting input source in Rewired manager Xbox One settings to either native or Unity
    • Both a wireless and a wired controller.
    It does work on every other platform. We pass 1 for both duration and motor level. Vibration is enabled in the controller settings on the devkit. Also vibration works when we call the GamepadPlugin's functions. Any help will be greatly appreciated

    Thanks
     
  22. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,886
    See the Xbox One setup documentation:
    http://guavaman.com/projects/rewired/docs/SpecialPlatformSupport.html#xbox-one

    You're probably missing Gamepad.dll.
     
    Last edited: Sep 16, 2018
  23. CausalBitGames

    CausalBitGames

    Joined:
    Sep 7, 2016
    Posts:
    10
    guavaman likes this.
  24. Jayme65

    Jayme65

    Joined:
    Dec 11, 2016
    Posts:
    73
    Hi,
    My application is essentially a launcher for external applications.
    In those "external" applications the user uses the keyboard/gamepad.

    The problem is:
    if the user quits the "external" application after having pressed (voluntary or not) some keys on the keyboard,
    those key presses (if used by the main "Rewired" application) will be intercepted when the "Rewired" application gain focus again.

    My question: is there a way to flush the keyboard/gamepad buffer ?
    Or: what would you advice to do to allow the "Rewired" application to not catch the keyboard/gamepad buffer for a certain time (how long!?) when the "Rewired" application get focused again?
    Thanks
     
  25. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,886
    If Ignore Application when Not Focused is set to True, Rewired will ignore all input when the application is not focused. Keys pressed before losing focus will not be detected after regaining focus and keys pressed while out of focus will not be detected after regaining focus.

    What platform is this?
    What version of Rewired is this?

    No. This is done automatically when the application loses focus.
     
  26. Jayme65

    Jayme65

    Joined:
    Dec 11, 2016
    Posts:
    73
    Thanks for you reply!
    'Ignore Application when Not Focused' is already checked...but I can affirm you that if deliberately choose to press a key that is not handled in the "external" application, that key will be caught by my "Rewired" application when getting focus back!
    Platform: Windows
    Rewired #: 1.1.19.6
     
  27. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,886
    I cannot reproduce this, but I may not be understanding what you are saying.

    This is my understanding:
    1. External application has focus.
    2. User presses some keys on the keyboard.
    3. User then closes the external application.
    4. Rewired application then receives the key presses they made before closing the application.

    However it occurred to me you may instead by referring to this situation:
    1. External application has focus.
    2. User closes the application by pressing some key such as Enter.
    3. Rewired automatically receives focus and the Enter key which was pressed to close the external application also triggers an enter during the same frame Rewired receives focus.

    If it's #1, that should not be happening. Try updating to the latest version of Rewired.

    More questions:
    What version of Unity?
    Is Run in Background enabled in Unity Player settings?
    Fullscreen or windowed?
    What Fullscreen mode is chosen in the Unity Player settings?
    Is Visible in Background enabled in the Unity Player settings?
    Is Allow Fullscreen Switch enabled in the Unity Player settings?

    If it's #2, there's no way around that. Rewired will not negate or cancel out a key press that was activated before it received focus but is currently pressed after it receives focus. Whether or not it processes this event depends entirely on the input source in use for that particular input. Unity Input, XInput, and Direct Input are all polling-based systems and the event would be processed because the button is held. Raw Input is an event-based system and the event would not be detected because the initial down state would have happened when the application did not have focus so it wouldn't process it.

    To deal with #2, you would have to just ignore processing input for some amount of time after the application receives focus.
     
  28. Rob-Fireproof

    Rob-Fireproof

    Joined:
    Dec 18, 2012
    Posts:
    18
    Hi there,

    First off, Rewired is awesome!

    I've got a case that I'm struggling to map neatly, and I haven't managed to find any other similar questions (apologies if this has already been asked and I've missed it).

    For a controller with a clickable trackpad (e.g. Vive), is there a neat way to have clicking the cardinal directions on the pad (up, down, left, right) show up as button presses? Generally, clickable pads expose two different inputs, the touch position (as two axes) and a button for "clicked".

    Basically, I want to be able to easily map "Axis [X] > 0.5 and Button [X] pressed" in the same way as I could map "Pressed the X button" on a different controller. This is all using Unity input, rather than XInput.

    I think one way might be to modify the hardware joystick map to make a new button which uses a "Multiple button" button and somehow map the axis to a button, and combine it with the click button. Or to use the Custom Calculation, but I'm struggling to find documentation on whether I could do it with that.

    This seems like something someone else has already done though, so I thought I'd ask in case I'm missing something obvious.

    Thanks!
    Rob.
     
  29. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,886
    No, there's no way you can do this in the Joystick class. HardwareJoystickMap does not support such a arbitrary type of mapping. There is no CustomCalculation that would do it either. A new one would have to be made, but it still may not be possible since CustomCalculation wasn't designed with this type of processing in mind. None of this low-level stuff is documented because it really isn't intended for user use.

    The provided way to do things like this is through Custom Controllers. Read the axis values from the touchpad and activate buttons on the Custom Controller when it meets the criteria.

    The only other way is to process it in code in your script and read the axis x and y values, then determine whether buttons have been pressed. This would not let you use the touch pad to bind actions to those "buttons" however.
     
  30. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    140
    Hi @guavaman
    Here is the problem. If I press a keyboard button during the scene loading, Player.GetButtonDown returns true as soon as scene is loaded, which is obviously not a desired behaviour.
    "Button Buffer Down" is set to 0.
    Are there any settings I missed which could help in solving this problem? Or is there some method to reset/refresh the state of buttons which I could call when the scene is loaded?
     
    Last edited: Sep 19, 2018
  31. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,886
    There is no way to clear Rewired's hardware-based input values.

    Rewired is not allowed to process during a synchronous load. The Update function does not run in Rewired, so it cannot update any values. The operating system will queue up the input events during this load and will deliver them to Rewired when the thread continues.

    One way to avoid this is to skip processing input for the first frame after the level loads or after a set timeout. You could also disable all the Controllers before loading the level and re-enable them after, but that is likely more trouble.
     
  32. Rob-Fireproof

    Rob-Fireproof

    Joined:
    Dec 18, 2012
    Posts:
    18
    Thanks for the answer! Custom Controllers look good - I'll go with that.
     
  33. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    140
    Thanks for quick reply. While I was waiting for you reply, I tried a workaround you described: before loading a new scene I 'lock' my InputManager (which just sets a flag for InternalPlayer class) and at the end of the next frame I unlock it.
    So here how it looks like (pay attention to the frame index)
    upload_2018-9-19_10-12-53.png
    For some reason Player.GetButtonDown returns true on the next frame after unlocking.
    I could keep InputManager locked for several frames but it does not look like a clean solution.
     
  34. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,886
    Rewired would not be returning GetButtonDown true for multiple frames. That's not possible because the value of GetButtonDown is directly calculated based on the Action value in the previous frame vs the current frame. If the previous frame was on, GetButtonDown cannot be true. If the button state was On or Down during the first frame after Rewired was re-enabled, it will not be Down on the next frame.

    How are you determining whether GetButtonDown is true or not? Are you logging it or are you watching some character react to the result of other input code? Might this input code have something in it causing the character to react in a circumstance other than the direct result of player.GetButtonDown? Try logging the value of player.GetButtonDown the frame you disable input and every frame after. Is your input using Update or FixedUpdate?
     
    Last edited: Sep 19, 2018
  35. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    140
    In this situation GetButtonDown causes loading of the new scene. There are no other factors which may cause this.
    On the image above:
    1 (frame 506) - locking of the internal InputManager right before loading the new scene;
    2 (frame 507) - new scene is loaded, internal InputManager is unlocked at the end of the frame;
    3 (frame 508) - in some of Updates GetButtonDown returns true causing loading of the next scene.

    Rewired is configured to use Update.
     
  36. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,886
    Is the Rewired Input Manager set to Don't Destroy On Load?

    Please log the values of your Action's GetButtonDown on each of those frames and post the results.
     
  37. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,886
    @dotsquid

    My testing shows the following using this script to load a new, very large level file:

    Code (csharp):
    1. using UnityEngine;
    2. using UnityEngine.SceneManagement;
    3. using System.Collections;
    4. using Rewired;
    5.  
    6. public class LoadLevelTest : MonoBehaviour {
    7.  
    8.     bool loaded = false;
    9.  
    10.     void Awake() {
    11.         DontDestroyOnLoad(this.gameObject);
    12.         SceneManager.sceneLoaded += OnLevelLoaded;
    13.     }
    14.  
    15.     void OnLevelLoaded(Scene scene, LoadSceneMode mode) {
    16.         Debug.Log("Level loaded at " + Time.frameCount);
    17.     }
    18.  
    19.     void Update () {
    20.         bool down = ReInput.players.GetPlayer(0).GetButtonDown("Go");
    21.         if(down) Debug.Log(Time.frameCount + " GO down");
    22.         if(down && !loaded) {
    23.             loaded = true;
    24.             SceneManager.LoadScene(0);
    25.         }
    26.         bool firedown = ReInput.players.GetPlayer(0).GetButtonDown("Fire");
    27.         if (firedown) Debug.Log(Time.frameCount + " FIRE down");
    28.     }
    29. }
    Procedure. Press G (Go) to trigger the level load and then press F (Fire) during the synchronous level loading process.

    Log results:
    245 GO down
    246 Level loaded at 246
    246 FIRE down

    This is as I would expect to see.
    "Go" was logged as Down on the frame G was pressed and never again regardless of whether I hammered the key during loading, held it, or just pressed it once.
    The level finished loading at frame 246.
    Because Fire was pressed during the sync level load, the input was caught and processed on the same frame the level loading finished, 246.

    What version of Rewired are you using?
     
  38. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    140
    It does not really differ from the previous image.
    upload_2018-9-20_9-54-56.png
    The code for logging is straight forward:
    Code (CSharp):
    1. private void Update()
    2. {
    3.     var isUse = InputManager.I.primaryPlayerInternal.inputPlayer.use;
    4.     if (isUse)
    5.         Debug.Log("< USE >");
    6. }
    I noticed an interesting thing. I put
    Debug.Break();
    right after unlocking of the InputManager to check the Rewired's info in the Inspector and surprisingly GetButtonDown did not return false as before.
     
  39. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    140
    Thanks for your involvement.
    Your results are looking logical and I really want to get the same on my side.
    Rewired version is 1.1.19.9.U2017 (the latest one I guess?)

    I mentioned Debug.Break() in previous message. It was also used to check if Rewired's GameObject and MonoBehaviour are active and enabled (otherwise that could cause that delay), but they are ok.

    Just to clarify, this problem is solved with a workaround in which I use not a one-frame delay, but a three-frames delay before unlocking the InputManager. But it's unclean and ugly, so I tried to find the real reason of this behaviour. Unfortunately I have no much time now to continue the investigation. As well as I can't demand greater involvement from you. So if you have no other clues (I have no more) let's keep it as it is.
     
  40. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,886
    Thanks for the additional details. Checking the Rewired Input Manager's enabled state was something I was going to suggest, so it's good you did that.

    Is anything happening with regard to enabling or disabling any Controller Maps?

    To dig deeper, I would want to log the key values of the keyboard keys directly instead of the Action values. This would indicate whether something is happening at a lower level than the Action system. I would need to see the values each frame of ReInput.controllers.Keyboard.GetKeyDown for the key in question. The only possibility I can think of is that Raw Input is not sending the input events immediately on your system. This shouldn't happen and doesn't make any sense. Keyboard events are sent on the main thread and Windows should be queuing them up during the level load and delivering them on the next thread update.

    If you don't have time to do so, I understand.
     
  41. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    140
    The log is identical to the one with GetButtonDown: true is returned on the next frame after the scene is loaded.

    I believe the real reason is simple and dumb: I'm missing something obvious but can't figure out what exactly.

    Thanks for your efforts! I'll keep a stupid workaround until I realize what's really going on.
     
  42. Rockwall33

    Rockwall33

    Joined:
    Mar 4, 2016
    Posts:
    186
    Hello!

    I got the Corgi Engine recently, and I bought Rewired a bit ago! I am enjoying it!!

    For some reason I had trouble getting 8 players. I followed the instructions. But my controllers didnt work. They are Xbox 360 controllers from Ebay, might be different software, I am unsure. Will there be a built in 8 players (not 1 or 4 as of now)?

    Thank you!!
     
  43. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,886
    Glad you're liking Rewired!

    No. The 4-player Input Manager just a pre-configured Rewired Input Manager that gives you a starting point. Adding 4 more Players should not be difficult at all if you understand how Rewired works. Please see the documentation:

    http://guavaman.com/projects/rewired/docs/

    Go through the Quick Start:
    http://guavaman.com/projects/rewired/docs/QuickStart.html

    See the Troubleshooting docs:
    http://guavaman.com/projects/rewired/docs/Troubleshooting.html#joystick-problems

    4 controllers is the maximum when using XInput:
    http://guavaman.com/projects/rewired/docs/KnownIssues.html#more-than-4-xbox-controllers
     
    Rockwall33 likes this.
  44. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,886
    Thanks. So it's definitely not the Action system causing it.

    The best way to determine if it's Rewired or something in your project is to create a new scene or project and test that. You can use the script I posted above if you want. Just create a very large scene file for it to load so you have time to press other keys. I just created a scene with hundreds of empty GameObjects. If the new scene functions correctly then you know it's something in your code/project causing it.
     
  45. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,886
    I just discovered something very significant.

    Unity 2017 behaves as your example.
    Unity 2018 behaves as my example.

    I haven't determined yet if there is some setting in Unity causing this, but I suspect it's a bug that probably has to do with Script Execution Order. Rewired always runs before other scripts with a Script Execution Order of -32000. I haven't confirmed it yet, but I suspect Unity is skipping Rewired's Update entirely on Unity 2017 after a level load. If this is true, there is no workaround possible.

    Edit: Rewired's update is running on the frame after a load. I'm going to have to dig in with debug logging into the code and figure out what's happening.
     
    Last edited: Sep 20, 2018
  46. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,886
    I've discovered what's happening and there's no workaround possible.

    Rewired is not receiving the Raw Input events until the frame after the level was loaded. This should not be possible because of how Windows message queue works. Therefore, I have to guess that Unity must be doing something strange after a level load in Unity 2017 that they changed in 2018. The only way I can imagine this result being possible is if Unity either just skips updating the Windows message pump the frame a load level finishes or else it runs another consecutive Update sequence after the level loads on the same thread update after loading, including incrementing Time.frameCount. If this is what's happening, it would explain why the Raw Input messages are delayed. The messages are not delivered to the message window until the beginning of the frame after loading finishes.

    The only thing I can think of doing would be to watch for level loading and clear any key events for 2 frames after it completes. Edit: I don't see any way to do this because there is no information about the scene loading method that was used in the callbacks available. I would not want to clear input on an asynchronous scene load because input may still be needed, only synchronous, but there's no way to get that information from Unity. I do not want to add a method to Rewired like BeginSceneLoad. That's not acceptable.
     
    Last edited: Sep 20, 2018
  47. Rockwall33

    Rockwall33

    Joined:
    Mar 4, 2016
    Posts:
    186

    I went through the documentation. I think it was a controller issue. When I tried it again and it seemed to work. As I said I got them from Ebay so the third party software didn’t register in well till after.

    Thank you!!!
     
    guavaman likes this.
  48. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    140
    Whoa! Thanks for the investigation. I haven't admit the possibility of different behaviour on 2017 and 2018.
    Well, it appears my workaround is not that dumb now :D
     
    guavaman likes this.
  49. indieDoroid

    indieDoroid

    Joined:
    Jan 25, 2016
    Posts:
    226
    hi,

    I mapped my game to an Xbox One scheme, but my friend is using an Xbox360 controller and couldn't play.

    Is it possible to copy\paste controller mappings across different joysticks? Or do I need to manually set this up?

    Thanks
     

    Attached Files:

    • 11.jpg
      11.jpg
      File size:
      456.6 KB
      Views:
      376
  50. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,886
    Delete the blank controller map for the Xbox 360 controller. You are preventing it from loading the Gamepad Template.


    http://guavaman.com/projects/rewired/docs/ControllerMaps.html#xinput-devices-windows

    Special Considerations for XInput gamepads on Windows Standalone, Windows App Store, and Windows 10 Universal:

    On Windows Standalone builds and in the Windows Unity Editor, when Use XInput is enabled, and always on Windows App Store and Windows 10 Universal builds, Rewired uses XInput for all XInput-compatible controllers instead of the chosen primary input source. This has some implications on creating Joystick Maps:

    When using XInput, Rewired has no way of determining the actual controller type because this information is not available through XInput. The only information Rewired has to identify the controller is that it is XInput-compatible. Therefore, all XInput devices are treated as "XBox 360 Controller". This means, with Use XInput enabled, if you plug in a XBox One Controller, Rewired cannot identify that it's an XBox One Controller and load the Joystick Maps you created specifically for the XBox One Controller. Instead, it identifies it simply as an "XInput Gamepad" and loads the Joystick Maps from the XBox 360 Controller maps you've created. This is an inherent limitation in XInput.

    But because Rewired has the Gamepad Template that is compatible with these controllers, it's easiest to just create a Dual Analog Gamepad Joystick Map instead and it will work for any XInput device when Use XInput is enabled. This way, you don't have to worry about making separate maps for XBox 360 Controller, XBox One Controller, etc. and everything will just work. This also works cross-platform.