Search Unity

Rewired - Advanced Input for Unity

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

  1. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,632
    @Feydwin

    Thanks Feydwin! I'm really glad to hear Rewired's working out so well for you. It's really nice to hear from you guys who are making use of my work!

    As for the remapping screen, that could prove to be a pretty big challenge for a novice programmer as you describe yourself. Fortunately, I am working on a drop-in remapping screen you may be able to use in your game (or modify it to work) that should be ready in a few weeks. There are some details on it in the previous couple of pages on this thread.
     
  2. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    Rewired is amazing. It is nice to hear reports about how others are using it. I am sure most of us have not used most of Rewired capabilities yet. It will be very nice once @guavaman is finished with his controller mapping screens for Rewired. There is discussion of future mapping screens starting http://forum.unity3d.com/threads/rewired-advanced-input-for-unity.270693/page-14 msg #666 if you have not seen anything about it yet.
     
    Last edited: Jun 8, 2015
    guavaman likes this.
  3. MornFall

    MornFall

    Joined:
    Jan 11, 2013
    Posts:
    160
    Alright, so i had a look at your script example for the rebinding...
    But that's all i had... haha , a look. It's wayyyy over my skill. So i am gonna wait for your example with the uGui. In the meantime i already designed the screen with all the buttons and all... and i ll see if i can adapt.
     
  4. Brainswitch

    Brainswitch

    Joined:
    Apr 24, 2013
    Posts:
    270
    While waiting for the new UI remapping I simply use the old OnGUI version even though the rest of my UI is using the new Unity UI.
     
  5. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,632
    Thanks for your patience!
     
  6. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    Have you seen the new scrawk ocean asset that is being developed?

    http://forum.unity3d.com/threads/scrawks-ocean.323545/

    That sounds like a perfect reason to get a Ship Console controller (since Rewired supports it out of the box) just to use with that future asset.
     
  7. Carpe-Denius

    Carpe-Denius

    Joined:
    May 17, 2013
    Posts:
    842
    Your overview video looks very interesting and promising, but I still have a question:
    how would you do small button changes?
    Let's say I want to press the right action button (O or B) to crouch, but if I press the aim button while holding a grenade, I want to drop the grenade (or shout something...doesn't matter).
    Do I have one general controller map and have to enable a controller map "GrenadeAim", which overrides the button presses? Or do I use 2 full maps and switch them? Or something other?
     
  8. sballew7

    sballew7

    Joined:
    Sep 3, 2013
    Posts:
    76
    First off, Rewired is pretty awesome. Thanks for the asset.

    Secondly, does anyone know the best way to check for a button combination? I don't mean modifier keys, but more like pressing "left-trigger + right-trigger + d-pad-down + A" at the same time. Say, for example, this were to open a debug menu.

    It looks like I can only map a single button to an action, so it'd be like DebugMenu1, DebugMenu2, DebugMenu3, DebugMenu4. Then my code would check that all four actions are present.
    Is there a way to somehow combine all of this into a single action?
     
  9. cowtrix

    cowtrix

    Joined:
    Oct 23, 2012
    Posts:
    322
    As of 5.1, we're getting some issues with mouse input in Rewired. We're trying to isolate the bug, but nothing seems to be working so we're hoping you could look on your end. Pretty much the whole mouse stops working, all axis. This is happening across multiple computers, multiple copies of Unity and multiple mice.

    Edit: Okay, standalone works fine, so I think it's something to do with Editor interaction. Losing and regaining focus in the Game view seems to trigger it.
     
    Last edited: Jun 11, 2015
  10. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,632
    You don't have the latest version. This was patched for U 5.1 in 1.0.0.50 when 5.1 was still beta.
     
  11. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,632
    Using separate maps for that sounds too convoluted. It would work, but would be more trouble than it's worth unless being in Crouch mode changes many controls apart from just the grenade one.

    The easiest thing in this situation would be simply to not use a separate Action for Grenade Aim and just check for the combination of the two Actions in your code. You're basically using Actions as buttons in a way. The other nice thing about this approach is that if the user remaps the Aim button, everything automatically follows. If you were to use separate maps and separate Actions for this, it could get very troublesome because the user could remap Aim but not remap GrenadeAim, throwing all your controls out of sync.
     
    Last edited: Jun 11, 2015
  12. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,632
    There's no button combo system in Rewired. That's left up to you to implement outside Rewired. Why? Because there are pretty much infinite combinations of how a system like this could possibly work depending on your use case. You have so many possible variables such as timings, whether buttons have to be pressed simultaneously or in sequence, what order they have to be pressed in, if the "combo button" is invalidated when one of the individual buttons is released only to be allowed again after all individuals are released, whether these buttons should still return values for Actions mapped to the individual buttons in the combo or silence the values if multiple buttons start to be pressed that are part of a combo, the timings for all of that, how this meshes with axis movements and axes treated like buttons, plus far, far more possibilities for all kinds of use cases. It's much simpler for the developer to implement the system they want for their specific needs. Keep in mind, there's no reason you can't name your Actions more like buttons and use them as such for cases like this. As in Street Fighter 2, Jab + Strong + Fierce = Spin Punch.

    You can use the time properties in Player in combination with GetButton to help with time issues since using GetButtonDown will not work well for this case as nobody will be able to hit multiple buttons EXACTLY at the same time (same frame).

    http://guavaman.com/projects/rewire...rload_Rewired_Player_GetButtonTimePressed.htm
    http://guavaman.com/projects/rewire...oad_Rewired_Player_GetButtonTimeUnpressed.htm

    Apart from all that, as mentioned above, user control remapping with button combos treated as a single Action could be a really big problem. You'd have users remapping the individual underlying buttons to different Actions but the combo Action's buttons would remain unchanged causing all kinds of possible side effects.
     
    Last edited: Jun 11, 2015
  13. trooper

    trooper

    Joined:
    Aug 21, 2009
    Posts:
    748
    Is there a way to use Rewired completely from code instead of using the supplied editor?

    cInput has "cInput.SetKey" and "cInput.SetAxis".

    Does Rewired have "SetAction"
     
  14. cowtrix

    cowtrix

    Joined:
    Oct 23, 2012
    Posts:
    322
    Thanks Guavaman, that was the issue. As a note to anyone else upgrading, make sure Rewired is in the root folder or all hell is going to break loose.
     
  15. robertwahler

    robertwahler

    Joined:
    Mar 6, 2013
    Posts:
    43
    Oh noes. I really hate cluttering the top level Assets folder with vendor folders. I hope this is a temporary issue.
     
  16. Candescence

    Candescence

    Joined:
    Aug 26, 2014
    Posts:
    107
    Any way to get mouse axis working properly, such as for camera control? It's not working for me.
     
  17. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,632
    This is true only during updating. Rewired had a lot of work put into it to allow it to work in any folder, including Plugins which runs under a different assembly. What you are experiencing is the issue with updating a Unitypackage in Unity 5. This is not a Rewired issue -- Unity's unitypackage system does not search for the root folder in your project before unpacking files. And now in Unity 5, they changed the way it works even further. In 4.x it used to find existing files by GUID and then replace those files even if they weren't in the same location as in the Unitypackage. Not so anymore in U5. If you unpack a file that already exists in the project but it's not in the expected location, it will just unpack a copy into the root instead of replacing the one you moved, change all the GUIDs, and yes "all hell will break loose." Blame Unity, not Rewired. There's no way around this. Unitypackage is their format and we asset store devs cannot change the way it works. This will happen with every single package out there. Asset store devs are frustrated with this, but there's nothing we can do.

    You need to have Rewired in the root folder only when updating. The same goes for all asset store packages now.

    Also, Rewired stores no data in its folder so you are safe to just delete it and reinstall it in any situation where problems occur. You won't lose your input configurations.
     
    Last edited: Jun 11, 2015
  18. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,632
    No there isn't. Rewired was designed for you to set up your initial inputs from the editor. Changing assignments in your Players after the fact is a different story though. That is all run-time modifiable. The Rewired Editor itself isn't.

    cInput has one simple centralized input configuration. Rewired is vastly more complicated (and powerful). Rewired Editor configurations are pre-runtime configurations. At runtime all maps are instantiated and copied into your Players. At that point, nothing is centralized anymore. All objects including Input Behaviors, Actions, and maps are instantiated per-player. Having a "Set Key" would make no sense in this situation. Instead you change the assignments in the particular controller map in the particular Player you're interested in modifying. Rewired comes with a demo scene ControlRemapping1 which shows from A-Z how to achieve any possible remapping scenario.
     
    Last edited: Jun 11, 2015
  19. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,632
    Nope, sadly. This is Unity 5's problem. There is no workaround. See my message http://forum.unity3d.com/threads/rewired-advanced-input-for-unity.270693/page-16#post-2154870. Let me restate -- Rewired runs perfectly in any folder you choose. However, before you update, you must move it back to the root (or just delete the Rewired folder) or else Unity will unpack duplicate files and not overwrite those in the folder you moved. This is a Unity 5 issue, not a Rewired issue and nothing can be done to "fix" it.
     
    Last edited: Jun 11, 2015
  20. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,632
    Please explain your problem more clearly. Mouse axes in Rewired behave exactly as they do in Unity unless you change the mode in the Input Behavior for that Action.
     
  21. Candescence

    Candescence

    Joined:
    Aug 26, 2014
    Posts:
    107
    Nevermind, turns out I somehow didn't assign the relevant mouse map to the player. Weird. Though, now the mouse movement is causing bizarre spikes in sensitivity that weren't occurring with the regular Unity input (and also not occurring with a controller).
     
  22. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,632
    Does your Input Behavior mouse sensitivity setting match the sensitivity you defined in the Unity input manager axis? If these don't match, your result will not match between the two systems. If they match, the output will be identical. If in doubt, disable Native Mouse Input in the Rewired Editor settings and you'll get nothing but pass-through Unity values. If you're seeing spikes then, you can be sure it's your settings or something else you're doing.
     
  23. Candescence

    Candescence

    Joined:
    Aug 26, 2014
    Posts:
    107
    Okay, after some testing, I've discovered that mouse movement in any case causes noticeable sensitivity spikes (and brief but noticeable screen pauses as well). That's very strange, and a bit worrying.
     
  24. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,632
    I'm guessing you mean in Unity with or without Rewired here. To be sure, you should test the mouse movement without any sort of game logic going on. Just modify a GUIText showing the current value. If you don't see the slowdowns, you'll know it's something else in your game code causing it.
     
  25. Karearea

    Karearea

    Joined:
    Sep 3, 2012
    Posts:
    386
    guavaman likes this.
  26. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Any chance of performance improvements? Rewired consumes way too much CPU time for just an input system.
    Firstly, it takes 1 second and 3 MB of allocated garbage just to initialize itself:


    That's more or less okay, since it only happens once, but still annoying enough. What's not so okay is that Rewired consumes around 1 ms of CPU time each time it's updated:


    1 ms per frame is a lot. It's pretty much 1/16 of the whole time budget for CPU and GPU to render a frame. And sometimes it jumps as high as 3 ms. Note that these screenshots are from the Editor. It's probably worse on mobile.

    Would be nice to see some improvements in this area in the future updates.
     
    Last edited: Jun 13, 2015
  27. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,632
    Umm... Try profiling without Deep Profile enabled. Rewired is highly optimized already.

    0.10 ms

    You're just seeing Unity's substantial added overhead of profiling every nested function call in the DLL. (A lot of reflection going on here.)

    Your test:
    rewiredperf1.png

    My test without Deep Profile: 0.10 ms

    rewiredperf.png

    My test with Deep Profile enabled: 3.29 ms (32.9X slower than before)

    rewiredperf2.png

    The memory allocation is the dynamically loaded assembly for the current platform. You're obviously on Windows as that has by far the largest assembly (882k). OSX's is only 186k. FYI, no mobile platform uses dynamic assemblies as of the current version.

    Again, the initialization process is far faster without Deep Profile enabled:
    w/ DP (Windows): 1909.77 ms
    w/o DP (Windows): 170.85 ms
     
    Last edited: Jun 13, 2015
  28. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Right, I've forgot to turn Deep Profile off, stupid me. I still get occasional spikes that go up to 1.2 ms, but those are rare, so that's fine. Thanks!
     
  29. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,632
    There should never be a case where Rewired comes anywhere close to 1.2ms per update unless you have an unbelievable number of players, maps, and controllers being evaluated per frame. There's no memory allocation ever per update frame and there's no variance in what methods are being called from one frame to the next. One thing that can cause odd spikes in the profiler is having VSync enabled. This isn't related to Rewired, but I have noticed the profiler can show a frame to frame variance of up to 2x occasionally even in Rewired's update time if VSync is enabled. Try disabling VSync and see what your frame to frame variance is. This may just be an artifact of Unity's WaitForTargetFPS.

    Also, if you don't need it, disable input in Fixed Update in the Rewired Input Manager settings page.
     
    Last edited: Jun 13, 2015
  30. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Well, this all depends on the machine, I guess. For example, the lowest time I've saw for Input Manager update to take on my machine is 0.2 ms, while on average it's around 0.3-0.5 ms, and I only have two players and two maps. 1.2 ms spikes are really rare, maybe once in 3 seconds or so. But yes, those fluctuations are certainly induced by profiler or some other external factors. Unity Profiler is not that good when it comes to accurately measuring small intervals.
     
  31. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,632
    That is true that speed will depend on the machine of course. My previous speed tests were done with a 6 year old desktop, so not exactly cutting edge. But yes, there's a ton of factors at play here. These were also tests in the editor, so don't really accurately reflect build speed. Anyway, glad everything's working!
     
  32. MornFall

    MornFall

    Joined:
    Jan 11, 2013
    Posts:
    160
    Hey Guavaman, Little warning with the last Unity Update 5.1.0f3 :

    Assets/Rewired/Integration/UnityUI/RewiredStandaloneInputModule.cs(159,40): warning CS0618: `UnityEngine.EventSystems.EventSystem.lastSelectedGameObject' is obsolete: `lastSelectedGameObject is no longer supported'

    Not a big deal... if you have a quick fix i can apply, please let me know.
     
  33. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,632
    I am aware of this warning and there is nothing I can do about it at this time. That is in the RewiredStandaloneInputModule.cs file which is used to control Unity GUI events with Rewired. I cannot change this call because Rewired supports versions of Unity down to 4.3. Unity deprecated this property in 5.1. There is no way to set a preprocessor directive that will do something such as #if UNITY_VERSION < UNITY_51. This would be required to be able to support the changing UI system fully on all versions. Even if I detect the platform version at runtime and run different code paths based on the version, the deprecated call will still remain in the source and will still show you the warning. The "solution" I can see is to silence the warning.

    FYI, most of that file was written by Unity and is taken from their open source Unity GUI StandaloneInputModule.cs. RewiredStandaloneInputModule was provided as a convenience. You can get the latest version of the Unity StandaloneInputModule.cs source if you like and modify it to use Rewired.

    Or just add this to the top of the class:
    Code (csharp):
    1. #pragma warning disable 0618
     
    Last edited: Jun 14, 2015
  34. MornFall

    MornFall

    Joined:
    Jan 11, 2013
    Posts:
    160
    Alright. I ll deal with warning then .
     
  35. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,632
  36. MornFall

    MornFall

    Joined:
    Jan 11, 2013
    Posts:
    160
    All good guavaman, dont mind it. Please focus instead on the keyboard remapping :)

    Btw, please don't make your example over complicated. Your system is a lot easier to use than , i guess, everyone would imagine. I know i did think that when i checked your "Overview " video of rewired. May be a little : Assign your action, do your keyboard mapping, and use it in your code, video would be good. That s just a suggestion.
    So for the remapping : here is a box, click on it, remap this key to this action. Simple, would be awesome.
     
  37. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,632
    :D

    The new uGUI remapping system is meant to be a fully-functional system that you can just drop into your game, provided your game's control scheme doesn't have special requirements that it doesn't meet. So by definition, it's going to be very complicated because it will handle any kind of remapping situation that Rewired can. It won't be just focused on keyboards, it will cover keyboard, mouse, and controllers for multiple players.

    As for a video, if I make one about it, I'll try not to get too overly detailed in the explanation. I tend to do that, I know. It's impossible to show all the features of Rewired that make it different from every other system out there without going into the gritty details though.
     
    Last edited: Jun 14, 2015
  38. electroflame

    electroflame

    Joined:
    May 7, 2014
    Posts:
    177
    Couldn't you make use of the Platform Dependent Compilation preprocessors that Unity provides? I don't know if they have one for Unity 5.1 specifically (should probably be UNITY_5_1 if it exists) but you should be able to do something like this:

    Code (CSharp):
    1. #if UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_5_0
    2. //Use the deprecated method
    3. #else
    4. //Do the new method
    That should be forward-compatible with any future versions as well, as it's explicitly targeting the old versions of Unity that Rewired supports.

    I've no idea if that would cover it (or if it will, if it would be plausible if the deprecated method is used in multiple places) but I figured I'd bring it up. You're probably way more on top of it than I am, so it's entirely possible that you've already thought of this and dismissed it.
     
  39. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    Really looking forward to these new UI controller mapping screens. This will be wonderful for all those flight controllers that you support in Rewired.
     
  40. movra

    movra

    Joined:
    Feb 16, 2013
    Posts:
    566
    It does, you can check it yourself in the .csproj file.

    http://forum.unity3d.com/threads/sk...s-authoring-tools.240996/page-11#post-2140853

    We did something like that for UniRx: https://github.com/neuecc/UniRx/blob/master/Assets/UniRx/Scripts/UnityEngineBridge/ObservableWWW.cs

    This is for versions lower than 4.5, except for Windows Store/Phone platforms.

    Code (CSharp):
    1. #if !(UNITY_METRO || UNITY_WP8) && (UNITY_4_4 || UNITY_4_3 || UNITY_4_2 || UNITY_4_1 || UNITY_4_0_1 || UNITY_4_0 || UNITY_3_5 || UNITY_3_4 || UNITY_3_3 || UNITY_3_2 || UNITY_3_1 || UNITY_3_0_0 || UNITY_3_0 || UNITY_2_6_1 || UNITY_2_6)
     
    guavaman likes this.
  41. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,632
    Yes, this is what I was referring to when I mentioned it above. I was saying if it were possible to do a < version here it would help things tremendously, but it's not possible.

    Using this method, you have to chain together every possible release before they deprecated the item. For Unity 5 this includes at the very least:

    Code (csharp):
    1. #if UNITY_5
    2. #if (UNITY_5_0_2 || UNITY_5_0_1 || UNITY_5_0_0)
    3. // old code
    4. #else
    5. // new code
    6. #endif
    7. #endif
    I'm unsure yet whether Betas or Patch releases have their own defines as well and those have to be covered or I will get support messages about it.

    Of course, this assumes the code inside "new code" won't ever be deprecated. If it were, that would be a problem and require this code segment to be wrapped again in every release that it works for instead of being in the #else.

    One problem I have with this approach is Unity is still making 4.6 releases. I have no idea how many more they will continue making, and I can't predict what those releases those will be and if / when they will deprecate this property in the Unity 4.x branch. (Not mentioned in 4.6.5 or 4.6.6 release notes).

    Anyway, the bigger problem here is I have no idea what the "new code" should be at this point. Unity has not released the open source code for 5.1's StandaloneInputModule.

    For now I'm just going to use #pragma warning disable. The property is deprecated, but it does not throw an error and it does not affect the functioning of the script.
     
    electroflame likes this.
  42. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,632
    As am I. It will be great to have a functional remapping and calibration system most people can just use, especially those without the coding skills to make their own. This goes along with my plan to add the PlayMaker, Behavior Designer, and Node Canvas actions next.
     
    Karearea likes this.
  43. electroflame

    electroflame

    Joined:
    May 7, 2014
    Posts:
    177
    Ah, alright. Not having the source for the 5.1 alternative is the larger issue here, and the one that's totally out of your control.

    Thanks for clarifying!
     
  44. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,632
    Rewired 1.0.0.54 is live on the Unity Asset Store. This is a minor update that addresses an extremely (extremely) rare issue in Raw Input.

    Release Notes:

    1.0.0.54:
    Changes: - Added more detailed debug code to track down a rare issue in Raw Input.

    1.0.0.53:
    Bug Fixes: - Malfunctioning HID devices in Raw Input will no longer cause all input to stop functioning.
     
  45. cowtrix

    cowtrix

    Joined:
    Oct 23, 2012
    Posts:
    322
    Hey guavaman. We're trying to reduce mouse latency at low framerates in our FPS game. At low framerates (<50) there's a delay (small but noticeable) between when the mouse input is sampled in Update(), and when the frame is pushed to the monitor. Optimally, we'd like to force the mouse to sample again at OnPreCull(), and update the camera matrix manually. We haven't been able to figure out a way to get Rewired to sample the mouse a second time during OnPreCull(), as it seems to be bound to the Update() loop. Is this possible?
     
    Last edited: Jun 17, 2015
  46. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,632
    There's no way to do this at this time. Sorry. Rewired performs its updates in one or more of the chosen update loops in the Settings page of the Rewired editor. Your options are Update, Fixed Update, and OnGUI.

    At present, there's no way to do this and no easy way to expose something like this because each update loop's input data is tracked and updated independently. Forcing an update of Rewired's input data would force an update of all Actions, but only in the last update loop that was evaluated. (OnPreCull isn't one of them, so even getting input in this update loop would just give the last values of whichever update loop type was last evaluated.). It would also have the side effect of breaking OnButtonDown/Up events because they would be re-evaluated at this time as well so you'd miss them in your next update frame. Even if there were a way to do this, it would only have an effect in Windows as OSX does not implement native mouse input and uses Unity's mouse input instead which is also updated in Update.

    Edit: One possibility that _might_ help would be for me to add LateUpdate as an additional update loop for input evaluation.

    Edit 2: Actually, thinking about it, I don't believe this would help anything. Mouse input in windows is handled through messages which are queued for the current thread. The current thread being Unity's main thread. You wouldn't be able to get a fresher mouse position without implementing input on a separate thread.
     
    Last edited: Jun 17, 2015
  47. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,632
    I'm not sure if you saw my edited post above (because you didn't quote it), but this isn't possible without updating the mouse in a separate thread.
    • All Monobehavior updates run in Unity's main thread.
    • Rewired runs in the same main thread off a Monobehaviour update.
    • Windows messages are are delivered to the main thread before Unity's main update occurs.
    • No new messages are delivered until the next update of the main thread.
    https://msdn.microsoft.com/en-us/library/windows/desktop/ms645601(v=vs.85).aspx
    "The mouse generates an input event when the user moves the mouse, or presses or releases a mouse button. The system converts mouse input events into messages and posts them to the appropriate thread's message queue. When mouse messages are posted faster than a thread can process them, the system discards all but the most recent mouse message."

    The mouse position cannot be refreshed in the middle of the main thread as it's busy processing all the game code, etc. Monobehaviour.OnPreCull runs during this same frame in the main thread, so there is no chance to get another mouse position value until the next frame. My tests confirm this.

    I had plans to implement some form of multi-threaded input, but they've been pushed back due to other improvements that will help many more users.
     
    Last edited: Jun 17, 2015
  48. BTables

    BTables

    Joined:
    Jan 18, 2014
    Posts:
    61
    I figured you were using DirectInput if available to read the mouse given the DirectInput setting in the dropdown.

    Edit: Is it not possible to use DirectInput to query the mouse as it already spins up a new thread for you?
     
  49. FreebordMAD

    FreebordMAD

    Joined:
    Mar 15, 2013
    Posts:
    633
    I'm trying to integrate Rewired into my game, but I'm getting this error when I try to setup my Input Manager:
    "Message: Cannot cast from source type to destination type." this seems to be the problem. This error is instatly visible after starting the scene. Also "Rewired.ReInput.players" returns always null... I don't know what I'm missing? Please tell me what I could try to fix this.

    [EDIT:] I have found out that this error occurs as soon as I switch to Windows Universal build.
     
    Last edited: Jun 17, 2015
  50. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,632
    No, the mouse is never read with Direct Input. If Native Mouse Handling is enabled, Raw Input is used for it. Regardless, Rewired's Action system isn't designed to update itself on a separate thread. Implementing multi-threaded input would take a non-trivial amount of time and I cannot work on it before my current list planned additions:

    Any bug fixes that come up
    Finishing new user mapping screen
    Creating Playmaker, Behavior Designer, and Node Canvas actions
    Better Xbox One support
    Better PS4 support
     
    Last edited: Jun 17, 2015