Search Unity

Rewired - Advanced Input for Unity

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

  1. Bhruood

    Bhruood

    Joined:
    Apr 27, 2013
    Posts:
    11
    Not the actual performance (although I've heard that it has pretty bad performance on low end machines), just the editor workflow when using C++ as your primary API, it has much slower iteration times than Unity, mostly because of much longer compile times (since its C++), but even with their nice automatic DLL reloading (not having to close the editor to make changes) the recompile time for minor changes for me seems to be around 30+ seconds (this time also fluctuates up and down depending on the current release version, so its not always that bad, in the past I had it around 10 seconds, but that increased in the most recent release). Also the C++ hook to the Unreal editor involves the use of the blueprint editor which means that you make a C++ class, then make a blueprint that inherits from it, then can modify that blueprint's values and place it in your level which (when compared to unity's setup) is just extra friction that reduces iteration time. Of course, a lot of people suggest that the "best" way to work in UE4 is to use blueprints to prototype and then convert all of that to C++ code once you have something you like, but I really dislike visual programming. At this moment I feel like its a fair deal to trade the graphical prowess of UE4 and its (potentially) better code performance (Native C++ vs an Antiquated version of Mono) for immensely better iteration times, and a much larger community (where you can find awesome plugins like yours :p).
     
    guavaman likes this.
  2. mgmhunt

    mgmhunt

    Joined:
    Apr 1, 2013
    Posts:
    62
    Is there a way of disabling the exception catching in the event handler? It's nice for final build but makes it harder to debug...maybe a checkbox in Rewired Editor to turn it off?
     
  3. Alima-Studios

    Alima-Studios

    Joined:
    Nov 12, 2014
    Posts:
    78
    Hi

    Sorry if has been posted yet ,

    Is there any progress on the future feature of remaping ui addon ¿?

    lot of thanks
     
  4. Brainswitch

    Brainswitch

    Joined:
    Apr 24, 2013
    Posts:
    270
    Future feature? The new uGUI control remapper has been released, and it's pretty nice. What future feature are you referring to?
     
    guavaman likes this.
  5. Alima-Studios

    Alima-Studios

    Joined:
    Nov 12, 2014
    Posts:
    78
    oh yes ! thats exactly what I meant !!

    I thoght it was still to be released !!

    lot of thanks

    http://guavaman.com/projects/rewired/docs/ControlMapper.html
     
  6. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    If I don't catch the exception in events like I am now, I have to catch them down at the very lowest level (Update). Either way, I have to catch the exceptions or risk problems. The previous way, Rewired would catch the exception in the event handler and shut down entirely and you wouldn't know it came from your event handler. Now, instead it throws a Debug.LogError with the message telling you its in your event handler and the exception is logged, but doesn't shut down.

    You want to completely disable all exception catching entirely?
     
  7. kloop32

    kloop32

    Joined:
    Jun 10, 2015
    Posts:
    5
    Hi,

    I just purchased Rewired so I can control my character using a wireless PS dualshock 4. I am new to Unity and i can't figure out how to do this, is there a basic example I can look at so I can get the hang of it ?

    Thanks in advance.
     
  8. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
  9. mgmhunt

    mgmhunt

    Joined:
    Apr 1, 2013
    Posts:
    62
    Well at the mo, my handler will call various parts and the exception could be anywhere in the call stack. Not sure, if you think turning off Exception handling in Rewired will make it even worse then no, but an option maybe useful as it maybe better to pinpoint where the exception is (outside of Rewired)? ie default on, as is but perhaps an option to turn off may help trace past the handler?
     
  10. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    Rewired must catch some exceptions because they can possibly occur internally when querying HID devices and/or initializing input sources. These are handled at point of failure and then at the root-most Update loop. Turning this off would be potentially dangerous.

    I don't understand why Rewired handling exceptions in event handlers causes an issue. It logs with the complete stack trace from the original exception. Further, you are perfectly free to wrap your event handlers in Try/Catch statements to catch your own exceptions (what you should be doing anyway ideally). The only reason for the special event handler exception handling is because users create code in their event handlers that throw exceptions, Rewired catches it and shuts down, then they contact me for support assuming Rewired is the cause of the exceptions. The new handling just tries to make it clear the exception is in your handler code.

    If I were to disable exception handling, the exception would just be thrown unhandled (Unity would handle it). The Rewired Input Manager's Update / Fixed Update / OnGUI events are ultimately are where the exceptions would be thrown from (because Rewired does all its work from these events) and you'd have no way to catch those as the base MonoBehaviour is contained within the DLL. Disabling the exception handling would do nothing but allow you to trace through the Rewired event call stack back to InputManager_Base.Update, which wouldn't provide you with any useful information when the error is in the event handler code anyway.
     
    Last edited: Sep 3, 2015
  11. HiVE-interactive

    HiVE-interactive

    Joined:
    Oct 11, 2013
    Posts:
    14
    Not sure what is going on this morning, but when I went to build my project I got a fresh bug?

    Line 49 of CanvasScaleFitter.cs

    rewiredBug.png
     
  12. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    You want to give me some more information about your set up?

    Unity version
    Rewired version
    OS
    Recently upgraded Unity?
     
  13. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    Are you using some 3rd party compiler or something? Nothing has changed in Rewired.

    The signature of the function is:
    public static bool IsNear(float value, float targetValue, float threshold = nearThreshold);

    Clearly your compiler is choking on the "float threshold = nearThreshold". I haven't seen this issue since around Unity 4.0 or perhaps even earlier. Unity used to not be able to handle optional parameters but that was fixed ages ago and I've never seen it cause an issue when the method is inside a DLL.
     
    Last edited: Sep 3, 2015
  14. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Just wanted to say that I added Rewired support to Platformer PRO and it was a breeze. I think it took me less than 15 minutes to go from never having seen Rewired to keyboard and controllers hooked up. Great product.
     
    guavaman likes this.
  15. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    That's great to hear! Glad you were able to get it set up so easily. Your Platformer PRO looks like a really feature rich system.
     
  16. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Heh I suppose I should connect the hit/hurt boxes to Sprite Factory now ;)
     
  17. mgmhunt

    mgmhunt

    Joined:
    Apr 1, 2013
    Posts:
    62
    - yea not sure now, was pretty sure it got up to the handler call and that was it. But wrapping the calls in my own handler would be a way to go, thanks, would nip it in the bud before Rewired has to handle it.
     
  18. HiVE-interactive

    HiVE-interactive

    Joined:
    Oct 11, 2013
    Posts:
    14
    Unity version: version 5.1.1f1
    Rewired version: version 1.0.0.67
    OS: Windows 8
    Recently upgraded Unity: No

    Very interesting. It wasn't popping up when building my project last night, only started today. Have not changed anything since last night either :/ I am not using a 3rd party compiler, allthough MonoDevelop has been acting strangely... I fixed the compile error by dropping another value into the IsNear call:

    Code (CSharp):
    1. if(ratio > breakPoints[i].screenAspectRatio && !Utils.MathTools.IsNear(breakPoints[i].screenAspectRatio, 0.01f ,0.01f)) continue;
     
  19. HiVE-interactive

    HiVE-interactive

    Joined:
    Oct 11, 2013
    Posts:
    14
    Very strange, project options was greyed out in MonoDevlop, so I set the target framework of Assembly-CSharp to Mono / .NET 4.0 and it has resolved the error.
     
  20. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    .NET 4.0 shouldn't be required and actually shouldn't be used. There are features of .NET 4.0 that Unity's version of Mono doesn't support. The highest you should set it to is 3.5.

    If you compile the project with Unity and not MonoDevelop do you see the same problem?

    I guess I'll just break it out into two functions in the next update.
     
    Last edited: Sep 3, 2015
  21. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    It should show you the stack trace down to where the exception occurred in your event handler. Here's my code that handles exceptions in input events:

    First part is where the input event is sent. If an exception is caught, it's handled immediately.
    Code (csharp):
    1. // Send the event
    2. try {
    3.     if(send) e.@delegate(data);
    4. } catch(Exception ex) {
    5.     ReInput.HandleCallbackException("Player input event callback", ex);
    6. }
    This is where the exception is logged. You can see the original exception is forwarded to this method and the exception message and stack trace are printed out.
    Code (csharp):
    1. internal static void HandleCallbackException(string source, System.Exception exception) {
    2.     string message = "Rewired: An exception occurred inside an event handler or callback.\nSource: " + source + "\n" +
    3.     "This happens if your event handler code throws an exception. Rewired will attempt to continue running.\n\n" +
    4.     "Exception: " + exception.Message + "\nStack Trace: " + exception.StackTrace;
    5.     Debug.LogError(message);
    6. }
     
  22. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    :D
     
  23. smithmj5

    smithmj5

    Joined:
    May 24, 2013
    Posts:
    143
    First off, awesome work on Rewired, it's fantastic! I've tried a few other input managers in the Asset Store, and Rewired is by far my favorite. :)

    Is there any support for the concept of "repeat rate" on an action? I looked through the documentation, but couldn't figure out if this is handled or not. I'm looking for something similar to holding down a keyboard key, and having a small delay, and then while the key is held it starts triggering repeat events every n seconds. If that's not supported, I can roll my own using GetButton and a bit of code, but wasn't sure if this was supported out of the box or not.

    Cheers!
     
  24. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    Thanks! Glad you like it!

    Re: Repeat rate

    No there isn't. Rewired handles Action axis state, button held state, button just pressed, button just released, negative button held state/just pressed/just released, button double press, button double press and held, and buffered button just pressed.
     
  25. smithmj5

    smithmj5

    Joined:
    May 24, 2013
    Posts:
    143
    Cool, thank you for the quick reply! I was pretty sure it didn't, but there's also a ton of functionality, so thought maybe I missed it.

    To be clear: definitely not complaining, I can write up my own pretty fast, and I'm super happy with all of the things that Rewired does support, it's great! :)
     
    guavaman likes this.
  26. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    My opinion is that a lot of things one may want an input system to do are really the responsibility of game logic such as button combos (because there are just sooooo many variations of how one might want to implement it.) Button repeat rate kind of falls into that category as well in my mind, though not quite as much so as some other things. Frankly, I hadn't thought of it before -- getting a button-down state intermittently while it's being held. Obviously it would have to be implemented in a different way than overriding the button-down state though or you risk issues with various types of control setups. (Would have to be it's own GetButtonRepeating function or something.)
     
  27. HiVE-interactive

    HiVE-interactive

    Joined:
    Oct 11, 2013
    Posts:
    14
    Thanks for the help @guavaman,

    I'm using Mono 4.0.1 - Ok, so I set it back to 3.5 and when compiling in unity, I get no issue.
    Back on 3.5 though, if I build the project in Mono I get the error show up.

    I'm really used to pressing F8 and building in Mono rather than saving and toggling back to Unity, for the time being I fixed the error by right clicking on CanvasScaleFitter.cs in my solution and setting the Build Action to None. Embedded resource also works to ignore the script when building.

    Strange error imo, but yeah it stems from "No overload of 'IsNear' takes '2' arguments", I guess there are is a missing parameter?
     
  28. kloop32

    kloop32

    Joined:
    Jun 10, 2015
    Posts:
    5
    Hi,

    I purchased Rewired last week and even though i've been through all the tutorials and documentation I am still unsure how to attach a controller (in my case PS Dualshock 4) to an FPS character (that's because I'm new to Unity) .. Anyone care to share a simple example / description of how to do this ? It would be highly appreciated.

    Thanks
     
  29. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    There isn't a missing parameter. The function defines a default for that parameter (a constant) when none is passed. This is standard C# syntax and perfectly legal. Unity doesn't choke on it, MonoDevelop does as you say. Are you using the latest MonoDevelop that came with Unity?
     
  30. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    You need to provide details about the FPS character script you are using. Integrating Rewired with an existing character script requires we know something about the system. If you don't have an FPS character script, the first step would be to find one. If this question is more about how to create an FPS character script, that's well outside the scope of the input system and a very large topic in and of itself. (In case you're not aware, an FPS character control script would handle all kinds of things like character movement, physics, camera, and carrying out the user's desired actions. Rewired can used to provide the input for the script to use to perform the various control actions, but it doesn't do any of the other parts required for controlling an FPS character. That's all game logic and not part of an input system.)
     
    Last edited: Sep 5, 2015
  31. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    @HiVE interactive

    I found this page that explains it:
    http://stackoverflow.com/questions/22640833/compiling-c-sharp-via-unity3d-and-monodevelop

    The C# version is not the .NET version, but the .NET version does impact what features are available:
    https://en.wikipedia.org/wiki/C_Sharp_(programming_language)#Versions

    I would add that Unity compiles to the Mono equivalent of .NET 3.5 and Rewired was compiled on .NET 3.5 as well with no issues from optional parameters.

    I'm just going to have to change this from using an optional parameter to avoid this edge case incompatibility with MonoDevelop.
     
    Last edited: Sep 5, 2015
    HiVE-interactive likes this.
  32. smithmj5

    smithmj5

    Joined:
    May 24, 2013
    Posts:
    143
    The main use is for selecting menu options or items in a game, for example, in a shop or inventory where there are multiple items to choose from - usually most games do something where if you hold the dpad in a certain direction, it will start repeatedly moving with a certain delay. But it probably almost always makes more sense to just make a custom handler for that logic, since it's not really normal behavior.

    Just finished hooking up Rewired in my game, and I've gotta say, it's fantastic! Will be leaving a review shortly! :)
     
  33. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    Actually what you describe already exists (sans the initial delay). It's a setting in the RewiredStandaloneInputModule (which is just a slightly modified version of Unity's StandaloneInputModule). You adjust the Input Actions Per Second parameter. The higher the number here, the faster the UI selection will move when held in a direction (stick or dpad, doesn't matter). The default Control Mapper setup uses 4.5 as a comfortable value for this -- fast enough to move through the selections without being too fast to make it difficult to select a specific element.

    Awesome! I appreciate it!
     
  34. _met44

    _met44

    Joined:
    Jun 1, 2013
    Posts:
    633
    Hey guys, just wanted to let you know about stuff I've seen in 5.1.3p2 changelog:
    • (none) - UI: Fixed API breaking change where GetMousePointerEventData required a parameter.
     
    Last edited: Sep 7, 2015
  35. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    Interesting. Thanks for posting that! So it was unintentional.
     
  36. vivalavida

    vivalavida

    Joined:
    Feb 26, 2014
    Posts:
    85
    Hi Guavaman,
    Is it possible to control the duration of the controller rumble?

    Thanks.
     
  37. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    This is determined by the joystick hardware. Some controllers turn themselves off after a certain amount of time, others do not. All you have to do is keep setting the vibration amount to the desired level on an interval.
     
  38. obsidian1269

    obsidian1269

    Joined:
    May 12, 2011
    Posts:
    24
    Hey guavaman, rewired is amazing and I love it. Thank you for making and supporting such an awesome thing. We've been using it for a while now and all has been working well on PC but we've been trying to get a build working on the xbox one now and we've discovered that the Main Menu/UI system utilizing the RewiredStandaloneInputModule refuses any input. I admit I haven't installed the suggested Plugins (GamePad and Storage) as I'm still figuring that out. I'm in Unity 5.1.2.
     
  39. KaldrisRelm

    KaldrisRelm

    Joined:
    Mar 8, 2014
    Posts:
    10
    Hi Guavaman,

    Awesome asset, picked it up a few days ago and it has made hotkey setup much easier to manage then the normal Unity input manager. One question for you though (apologies if this has already been asked) - Is there any way to use modifier keys with a mouse click? I have a movement manager that a player can use to execute different movement types based on Right Click + Shift/Ctrl/Alt, but I'm not sure if this is something supported by Rewired.

    Thanks!
     
  40. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    Unity’s code in the StandaloneInputModule has flawed detection for mobile platforms. The absence of a mouse denotes a “mobile platform” in their code, therefore the Xbox One is considered a mobile platform. You have to enable “Allow Activation on Mobile Devices” for it work on Xbone.

    The next release will change the detection algorithm.
     
    Last edited: Sep 10, 2015
  41. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    Not that is handled by Rewired. You can implement something like this pretty easily in a script.

    See this post and the others linked within it for details on button combos: http://forum.unity3d.com/threads/rewired-advanced-input-for-unity.270693/page-21#post-2250211
     
  42. justinluk

    justinluk

    Joined:
    Oct 31, 2012
    Posts:
    2
    Hey Augie,

    I've been having some issues with Rewired as of late. I'm not quite sure what happened. I recently bought DS4 controllers to use on my PC. I'm using InputMapper to wire them up and it seems that whenever a Rewired Input Manager is in my scene it causes Unity to crash. Here's the error I'm getting:

    Unhandled exception at 0x00007FFD693CA28C (ntdll.dll) in Unity.exe: 0xC0000374: A heap has been corrupted (parameters: 0x00007FFD69422180).

    This happens whether the DS4 controllers are connected by USB or Bluetooth. Once I disconnect them from the PC completely Unity seems to run ok. Controllers seem to work fine while playing other games.

    Happening to me in Unity 5.2 and 5.1.3. Any thoughts as to what could be going on? Running the latest version of Rewired. 1.0.0.67.
     
  43. obsidian1269

    obsidian1269

    Joined:
    May 12, 2011
    Posts:
    24
    You the man, Guavaman. Works like a charm!
     
  44. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    There's nothing in this error that I can use to diagnose the issue.

    1. What Bluetooth stack are you using?
    2. Are you running a 3rd party driver/emulation system for DS4? (Well I see you mentioned InputMapper -- this is not tested with Rewired.)
    3. Build or editor?
    4. 32 or 64 bit?
    5. Anything in the log?
    Using InputMapper is likely to throw off Rewired's ability to recognize the DS4 controllers and apply its mappings for one (if you change the button/axis mappings in InputMapper).
     
    Last edited: Sep 10, 2015
  45. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    I'm going to need more information about your configuration, OS, Rewired config, control mapper config, and anything else you can think of.

    I have tested the following:
    Windows 7 64-bit
    Unity 4.3 32-bit build w/ Rewired, Raw Input, DS4 via USB, InputMapper disabled
    Unity 4.3 32-bit build w/ Rewired, Raw Input, DS4 via USB, InputMapper X360 emulation
    Unity 4.3 32-bit build w/ Rewired, Raw Input, DS4 via USB, InputMapper enabled, no emulation
    Unity 4.3 32-bit build w/ Rewired, Direct Input, DS4 via USB, InputMapper disabled
    Unity 4.3 32-bit build w/ Rewired, Direct Input, DS4 via USB, InputMapper X360 emulation
    Unity 4.3 32-bit build w/ Rewired, Direct Input, DS4 via USB, InputMapper enabled, no emulation
    Unity 5.2 32-bit build w/ Rewired, Raw Input & XInput, DS4 via USB, InputMapper disabled
    Unity 5.2 32-bit build w/ Rewired, Raw Input & XInput, DS4 via USB, InputMapper X360 emulation

    None of the above exhibit any errors and do not crash.
     
  46. justinluk

    justinluk

    Joined:
    Oct 31, 2012
    Posts:
    2
    Hey Augie,

    I think I came across the problem and it's super weird. Whenever I start up Unity I get this error message
    "Screen position out of view frustum (screen pos 0.000000, 0.000000, 0.300000) (Camera rect 0 0 0 0)
    UnityEditor.DockArea:OnGUI()"

    For whatever reason because of this error while trying to run the scene while the Rewired Input Manager was enabled Unity would crash.

    My solution has been to close my scene tab once I start Unity, clearing out my console, and then the scene runs fine with Rewired enabled. Thanks for your prompt response to me, but I suspect the issue lies elsewhere.

    Cheers!
    Justin
     
  47. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    I see. Thanks for letting me know!
     
  48. RedRiverStudio

    RedRiverStudio

    Joined:
    Sep 8, 2014
    Posts:
    136
    Hi Guavaman, quick bug note:
    Just upgraded to 5.2 unity and 1.0.0.67 and have been getting MissingReferenceExceptions all of the sudden. Happens randomly on scene loads or when the cursor enters a particular zone on the screen.

    and when clicking on the error I get line 336 of the RewiredStandaloneInputModule.cs:

    var mouseData = GetMousePointerEventData();

    It kills all input and the error is persistent per frame.
     
  49. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    First, line 336, var mouseData = GetPointerEventData() is not active in Unity 5.2. The preprocessor ifs see to that:

    Code (csharp):
    1. // Breaking change to UnityEngine.EventSystems.PointerInputModule.GetMousePointerEventData() in Unity 5.1.2p1. This code cannot compile in these patch releases because no defines exist for patch releases
    2. #if !UNITY_5 || (UNITY_5 && (UNITY_5_0 || UNITY_5_1_0 || UNITY_5_1_1 || UNITY_5_1_2))
    3.     var mouseData = GetMousePointerEventData();
    4. #else
    5.     var mouseData = GetMousePointerEventData(kMouseLeftId);
    6. #endif
    If you don't see the above then you're not using 1.0.0.67 (or it didn't update the RewiredStandaloneInputModule source).

    Second, the nature of that error is such that it's not Rewired causing it or the RewiredStandaloneInputModule. Look at the stack trace:
    1. The call originates from UnityEngine.UI.EventSystem.EventSystem.cs
    2. Then it passes through the RewiredStandaloneInputModule briefly as it tries to get the mouse pointer event data from UnityEngine.UI.EventSystem.InputModules.PointerInputModule.cs.
    3. That call to get the mouse pointer event data ultimately ends up with the exception being thrown at UnityEngineComponentBindings.gen.cs.
    There's nothing in the RewiredStandaloneInputModule causing this. The exception is being thrown by Unity failing to get mouse pointer event data when raycasting to UI elements. It's trying to raycast to a game object that's been destroyed. The "Image" game object that's missing is obviously not part of the RewiredStandaloneInputModule. It has to be part of some UI element you're using, which I have no information about since I don't know in what context the RewiredStandaloneInputModule is being used.

    I suggest you disable the RewiredStandaloneInputModule and use the regular Unity StandaloneInputModule and see if this also occurs.
     
    Last edited: Sep 11, 2015
  50. RedRiverStudio

    RedRiverStudio

    Joined:
    Sep 8, 2014
    Posts:
    136
    Great, thanks for the quick response. I thought I had downloaded the latest version of rewired, but only the core.dll updated for some reason. Ill give it another go. Ill also check on the event system. The error is also triggered when you move the cursor to a particular area of the screen, so that might be a clue into whats missing.
     
    Last edited: Sep 11, 2015