Search Unity

Rewired - Advanced Input for Unity

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

  1. Zeblote

    Zeblote

    Joined:
    Feb 8, 2013
    Posts:
    1,102
    Oh, sorry for not clarifying, I'm not looking for a ready-to-use remap screen, an API I can use for my own is all that's needed. So that'd be fine!


    Well, damn. How come noone else releasing unity games with re-bindable controls gives a damn about this? :( While every key maps to a specific unity keycode, meaning it works, even after intensive google I still can't find any way to get a useful localized string to show in the options menu for what key the user just pressed. So if you bind ü to something the options menu tells you you just bound "Semicolon"...
     
  2. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    Some developers probably don't even have access to non-US keyboards. Couple that with the fact that Unity does not support it, so no Unity developer has any way to handle this without writing their own native keyboard handling system for every single platform Unity supports. That's a huge job in itself.

    At some point Rewired will move away from using Unity as the keyboard input source on some platforms for other reasons like framerate independent input. Until then, keyboards are passed-through from Unity. If there are system level functions available to detect the keyboard language on the current platform somewhere, then it might be possible to patch in supporting different language keyboards as long as the keys return valid KeyCode values. It would be a matter of detecting the keyboard language and loading a map that associates a Unity KeyCode to a language-specific identifier. For example, KeyCode.Semicolon = "ü". The other question would be, do all keyboards in that language map "ü" to semicolon or can that vary from model to model? Another question would be, does this mapping vary on OSX, Linux, Android, or other platforms. With some answers in these areas, I might be able to add different languages. Or you could do the same on your end provided you have some way of detecting the keyboard language.
     
    Last edited: Oct 22, 2014
  3. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    From: http://en.wikipedia.org/wiki/Keyboard_layout

    "The QWERTZ layout is fairly widely used in Germany, Austria, Switzerland and much of Central Europe. The main difference between it and QWERTY is that Y and Z are swapped, and some special characters such as brackets are replaced by diacritical characters."

    I think this is just the tip of the iceberg and probably a good indication as to why international keyboards are not widely supported in game engines like Unity. Just take a look at all the variants on that Wikipedia page.

    What languages are you interested in supporting?
     
    Last edited: Oct 23, 2014
  4. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
  5. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    Ideally, this would be useful to have on all platforms, not just Windows. However, even without fully supporting keyboards natively and still using Unity's keyboard for input, native calls would be required on each platform to get information about the keyboard being used. Obviously the method would differ for each platform.
     
  6. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    Rewired 1.0.0.9 has been released. This is a minor update that works around a Unity bug I discovered that affects input handling in the OnGUI update loop. It also affects axis detection when polling for axes in a user remapping screen if doing your polling in OnGUI.

    Registered users can download the update immediately. Contact me if you have purchased Rewired and want early access.

    Note: The workaround slightly changes the result of GetButtonDown calls when made in an OnGUI loop. Now GetButtonDown will return TRUE for both the Layout event and subsequent Repaint events until the next Layout event occurs.
     
  7. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    Announcement: If you have tried to download the latest version of Rewired through the website but were unable to, this is due to an outage in the Unity Asset Store invoice verification system. I apologize for this inconvenience. I will update this thread when the invoice verification system has been fixed by the UAS team.
     
  8. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    The Asset Store Invoice verification system has been fixed and 1.0.0.9 is available for download for registered users again.
     
    Last edited: Oct 25, 2014
  9. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    Rewired 1.0.0.8 is finally available on the Unity Asset Store for download!

    1.0.0.10 is available for registered users to download immediately from the website and will be uploaded to the asset store today and will become available in 7-10 days.

    IMPORTANT REMINDER:
    If you are upgrading from a version prior to 1.0.0.6, you must run the installer again to add entries to the Unity Input Manager required for 4.6 beta.

    After installation, go to the menu:
    Window -> Rewired -> Setup -> Run Installer

    And proceed with the installation allowing Rewired to replace the InputManager.asset file.

     
    Last edited: Oct 27, 2014
  10. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    What version of Unity are you using? I am wondering if most people are using Unity 4.5.4 or later these days.
     
  11. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    What type of controllers are you currently using?
     
  12. electroflame

    electroflame

    Joined:
    May 7, 2014
    Posts:
    177
    I'm currently using the 4.6 Beta, but I started on one of the Unity 4.5 versions and it still worked great.

    I haven't tried the Unity 5 beta yet, so I can't comment on that, sorry.
     
  13. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    Unity 5 works, but there's currently an issue when importing the DLL where it can take up to 2 minutes to import into Unity because of Unity 5's automatic obsolete code detection/upgrade feature. This feature is also causing a problem that makes you have to re-import the DLL several times before MonoBehavior references will work correctly and I have confirmed with other developers this is not unique to Rewired. This is a pretty big bug with Unity that's going to have to be fixed or they risk causing a lot of problems for a lot of asset store packages, or else I'm going to have to find a workaround if there is one. Stay tuned.
     
  14. shkar-noori

    shkar-noori

    Joined:
    Jun 10, 2013
    Posts:
    833
    I'm really impressed with how far you have gone with this, I've had a similar input manager for my projects, but I couldn't use SharpDX's DirectInput because when i create a new JoystickDevice it gives me an error '
    The parameter is incorrect.', how did you implement DirectInput I may ask?
     
  15. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    Thanks! I use a heavily modified version of SharpDX. Had to make a lot of changes for various reasons to make it compatible with Mono, eliminate GC issues, reduce the size, and other things. If you need specific help, PM me.
     
    shkar-noori likes this.
  16. dkoontz

    dkoontz

    Joined:
    Aug 7, 2009
    Posts:
    198
    How would you suggest handling the situation where you want to be able to reassign which inputs are going to which player? This is for a local co-op game where all the players are on screen at the same time. It is a fairly common thing to at the beginning of a game assign out the keyboard + controllers to different players. Sometimes they may want keyboard + a controller to a player, maybe it's just the controllers to the players, etc. I've got my map set up with all the actions and that works fine so long as Player1 always wants keyboard + controller 1.
     
  17. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    You would have to make some kind of mapping screen or a more simplified controller assignment screen. Assigning mouse, keyboard, joysticks, custom controllers, and maps are all done through scripting. The best place to start is the documentation.

    http://guavaman.com/projects/rewired/docs/HowTos.html#controller-mapping-screen
    http://guavaman.com/projects/rewired/docs/HowTos.html#assigning-joysticks
    http://guavaman.com/projects/rewired/docs/api-reference/html/T_Rewired_Player_ControllerHelper.htm

    The controller mapping example shows all the parts of the API related to mapping and assignment.
     
  18. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    Thanks. I am on 4.5.4 and was thinking of skipping 4.5.5 and going to 4.6 Beta.
     
  19. electroflame

    electroflame

    Joined:
    May 7, 2014
    Posts:
    177
    No problem, you shouldn't have any issues upgrading to the 4.6 beta, but if you do I'm sure @guavaman will help you out with any Rewired-related issues.

    His support really is top-notch, so I wouldn't worry too much if it comes down to that.
     
    guavaman likes this.
  20. shkar-noori

    shkar-noori

    Joined:
    Jun 10, 2013
    Posts:
    833
    +1
     
  21. DaneC020

    DaneC020

    Joined:
    Mar 19, 2010
    Posts:
    191
    Do you have an open source version? I am always scared to buy something that is closed incase support ever stops. I really like the sound of this plugin but I would hate to start a project using it as our solution and then 3 years or so down the line it is no longer working for whatever reason. Without source we would be put in a position where we would have to abandon the solution.

    Not saying this will be the case, but it is always a concern.

    Thanks
    Dane
     
  22. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    Hi Dane,

    Thanks for asking! There is no plan to offer a source code option for Rewired. I do understand your concerns, however, and I can only say that I stand by my work and will continue to improve it over time. I've been working in Unity for over 5 years now with published assets on the store for over a year now. I plan to continue working in Unity for the foreseeable future and will do my best to keep up with the changes as they come along.
     
  23. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    Rewired 1.0.0.12 is now ready for download for registered users! If you purchased Rewired and would like to get access to all the latest downloads immediately, please contact me here with your email address and I'll send you a download link. The Unity Asset Store update will show up in 7-10 days.

    This update adds a bunch of new controller definitions including the very exciting Arcade Guns G-500 AimTrak Light Guns for up to 4 guns at once (!), Xbox One, the PSM Vita platform, and an important bug fix for iOS.

    Release Notes:
     
    Last edited: Nov 4, 2014
  24. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    Agreed his support is excellent. Are you using 4.6 Beta build 21 or build 20?
     
  25. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    rewired_arcade_guns.JPG
    Wow! Light guns at last. Now I can make Disneyland's shooting gallery at home. Well almost with only 4 light guns. :) This will be perfect to use with Ultimate FPS.

    Thanks for all of your hard work on Rewired.
     
    Last edited: Nov 30, 2014
    guavaman likes this.
  26. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    Rewired 1.0.0.13 is available for registered users to download immediately from the website. If you purchased Rewired and would like to get access to all the latest downloads immediately, please contact me here with your email address and I'll send you a download link. The Unity Asset Store update will show up in 7-10 days.

    This is a minor bug fix for native mouse handling in Windows Standalone when switching to and from full screen mode.

     
  27. DarkMagicCK

    DarkMagicCK

    Joined:
    Dec 25, 2012
    Posts:
    8
    Hello! I'm really happy to see an framerate independent input solution! But the big problem is the keyboard: we're making a rhythm game, which really needs framerate independent on keyboard.

    Are you planning to do this in near future? Or on a far roadmap? We will buy Rewired as soon as it support keyboard events!
     
  28. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    Hi!

    What platforms are you looking to publish on? Native keyboard support is important to have a complete frame-rate independent input solution, so it is near the front of the Todo list. It's likely this feature would only be available on Windows and OSX initially.
     
    shkar-noori likes this.
  29. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    Rewired 1.0.0.14 is ready for download for registered users. If you purchased Rewired and would like to get access to all the latest downloads immediately, please contact me here with your email address and I'll send you a download link. The Unity Asset Store update may take 2+ weeks to appear because 1.0.0.13 is currently in the queue and I cannot submit 1.0.0.14 until the current one is approved or it will push it to the back of the queue.

    1.0.0.14 Release Notes:
     
  30. DarkMagicCK

    DarkMagicCK

    Joined:
    Dec 25, 2012
    Posts:
    8
    Hi~ We're gonna publish on Windows and OSX. Glad to hear that it will be implemented soon! So can we buy it now and use your keyboard API to make games first?(Will keyboard API change after implement frame-independent?)

    And about API, can all input events raise as soon as the player press the key? Like a callback "OnKeyPressed" which is independent from Update loops and can be called directly after player press the key(even if the OnKeyPressed is in another thread, it's OK). As a rhythm game, we're trying to calculate the player's press time as accurate as possible to evaluate the time between the standard time and player's press time. Is this possible? Or true frame-independent is just impossible in Unity?
     
  31. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    A number of issues may have to be worked out for native keyboard support, so I can't say for sure if it will happen in the next couple of months. I will try to evaluate this soon and let you know.

    As for the usage, actually there isn't a way to do the kind of frame-rate independent input in Unity as you describe because that would require multi-threading. It's possible to receive an event from another thread (and Rewired does do this internally), but you would not be able to access any of Unity's API to do anything with that event because Unity's API can only be accessed in the main thread. Additionally, any exception that occurs in that thread will cause Unity to crash.

    Rewired can update input independently in the Update, FixedUpdate, or OnGUI loops. So when you get input in the FixedUpdate loop, the update will happen at the FixedUpdate rate regardless of what's happening with the graphics update loop (Update). If you set the FixedUpdate loop to 100fps, you will get 100fps input.

    As for events, Rewired has event-based input as well, so you can register for the GetButtonDown state of a certain action and receive a callback when that occurs. The update loop that is used to fire the event is up to you to choose when registering for it.
     
    Last edited: Nov 6, 2014
  32. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    Just a little bit more information:
    It is also possible to get input in both Update and FixedUpdate. You could poll for input or receive events in both loops and use the first received to determine the press time more accurately. This way, if VSync is off and the frame rate is extremely high, Update would be the more accurate of the two. As the graphics framerate drops, FixedUpdate would become more accurate.
     
  33. DarkMagicCK

    DarkMagicCK

    Joined:
    Dec 25, 2012
    Posts:
    8
    Hi~ Thanks for you reply. We're not gonna publish in near future, so we decide to believe in you and buy it! Besides keyboard frame-independent, it's still a very good solution for input control!

    As for multi-thread, we know we can not access Unity's API, the only thing we want to do is calculating the realtime, and do other logics in main thread.

    As for FixedUpdate, according to this thread(http://forum.unity3d.com/threads/the-truth-about-fixedupdate.231637/), it's simpled called bunch of times before Update, so if my game runs at 40-50fps, the Input in fixedUpdate(even 100fps) still share the same lag as the Update, which make no sense to get input in high fps fixedUpdate. Our goal is calculating the real time, so if you can provide any way to access the realtime between the device event and the access in fixedUpdate or Update call, like Input.realTimeSinceLastKeyDown/Up(KeyCode), there's no need to use multi-thread for it.
     
  34. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    Thank you for pointing out that information. That's very unfortunate. I will have to change all my product information and videos.

    Rewired does receive real-time events on Windows (RawInput devices and mouse) and on OSX. Direct Input and XInput are based on polling, so getting higher frequency updates would not be possible for those. I can make it so the latest input values are pushed in immediately, but for the user to actually use this information in real-time is problematic. I can add events that will be fired on the same thread the event was received from, but users will have to be very careful how they use this or risk crashes.
     
  35. DarkMagicCK

    DarkMagicCK

    Joined:
    Dec 25, 2012
    Posts:
    8
    Looking forward to this! I'll keep watching the updates. If you need any assistant or help, please tell me, we've already made a simple framework for testing input lags!
     
  36. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    Thanks for the offer of assistance! I will let you know if I need any testing.

    I need to decide what the most effective way of exposing this information is. Events fired at the time of receipt or an event queue. The event queue carries far less risk because it doesn't open up the possibility of crashes, but it also doesn't allow you to receive the event immediately outside of a Unity update loop, only look back on the events that were received between frames to make some kind of decision with the timing information.
     
  37. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    Quick update on the framerate independent update situation:

    I'm currently planning to offer two options:

    1) An optional fixed time step input update loop running in a separate thread. The time step will be set to a specific frame rate defined by the user. It will also have an optional high-accuracy timer options which uses much more CPU resources but provides a more accurate time step. So if you want a fixed 60 or 100+ fps input update step, this would be the way to go. It should handle nicely the input sources that require polling for updates. This will allow you to register for an update event such as OnFixedInputUpdate and poll for events in the input thread. Obviously, you will not be able to call Unity's API from this thread. Also, this option will not be available on platforms that do not support multi-threading such as Webplayer (which really doesn't change anything since Webplayer is tied to Unity's input and cannot be updated faster than Update anyway).

    2) Exposing public events that will fire input events immediately as they are received. Threading issues apply here. This will only work for input sources that supply events as opposed to requiring polling for input updates. (Currently Raw Input and OSX should work with this method.)

    A third possible addition would be to record input active and inactive times for the events as they are received and expose this.
     
    Last edited: Nov 6, 2014
  38. DarkMagicCK

    DarkMagicCK

    Joined:
    Dec 25, 2012
    Posts:
    8
    This is a great!

    I think this addition is also a great one. If you offer this, in most situations we can avoid using multi-thread. Considering when player press the key, even using multi-thread we still cannot play a "HIT" AudioClip in our input thread. For our situation, the only meaning to use multi-thread is calculating the time, so if you offer this we can calculate the time right in Unity's update loop.
     
  39. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    Just downloaded 1.0.0.13 from the asset store.
     
  40. Limyc

    Limyc

    Joined:
    Jan 27, 2013
    Posts:
    29
    All three of those options sound very useful depending on your use case. For my current project, I'm mostly looking forward the to exposed events.
     
  41. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    @Limyc

    I'm still evaluating the feasibility of these approaches because some may require the entire API to be thread-safe which it is not, but could I ask you how you plan to use the events? Since this would be in another thread, you would not be able to use an of Unity's API, so you could record the information, etc. to make decisions, but could not act on those decisions immediately in most cases. Would a queue of events that took place between the previous Update and the current update be equally as useful to you? This would give you access to the information, but would prevent all the issues involved in dealing with other threads in the public API.

    Keep in mind that Rewired is player-centric, so I would likely be sending events based on changes to the Actions in Player, not necessarily the controller elements directly (or possibly both). For example, a button press on a joystick contributes value to an Action in Player entitled "Fire". When the change occurs, I would send an event for the state change of "Fire". This would differ from sending controller element events directly which have no direct correlation to Actions.

    Just FYI, Rewired already has an event system which you can use instead of polling for input, however the events are sent on the Update, FixedUpdate, and/or OnGUI loop so they're not frame rate independent.

    @DarkMagicCK

    I imagine an event queue would also work for your purposes, am I correct?

    Thanks for your help.
     
    Last edited: Nov 7, 2014
  42. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    Yes, the update was approved late last night. So 1.0.0.13 is out on the Asset Store ready for download now. The update includes the following changes since 1.0.0.10 (the last version on the Asset Store).

    The current version on the website is 1.0.0.14.
     
    Last edited: Nov 8, 2014
  43. Limyc

    Limyc

    Joined:
    Jan 27, 2013
    Posts:
    29
    Primarily, I would be using it to determine if a player moved or used an action too soon at certain points in the game. What's available now will probably work fine since we're talking small fractions of a second and the chance of missing an input is incredibly small, but if I can have a more accurate timestamp of when the action was pressed, I don't see why I wouldn't want to go that route.

    I guess a queue of events with some sort of timestamp or delta would be fine in my case. I think the raw events could still be useful in rare cases, but it's probably for the best if users don't need to worry about threading issues when it comes to standard Rewired workflow.
     
    Last edited: Nov 7, 2014
  44. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    Okay, thanks for the info!

    Agreed.
     
  45. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    The Unity Asset Store team has outdone themselves and approved 1.0.0.14 the same day it was submitted! So now 1.0.0.14 is live on the asset store.

    Release Notes:
     
  46. DarkMagicCK

    DarkMagicCK

    Joined:
    Dec 25, 2012
    Posts:
    8
    Yes if I can access the accurate time of each event in queue.
     
  47. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    This is the plan, but it looks like it will have to be time provided by a separate timer because Time.realTimeSinceStartup and Time.time are not available from another thread.
     
  48. BuildABurgerBurg

    BuildABurgerBurg

    Joined:
    Nov 5, 2012
    Posts:
    566
    Hello,

    Does this come with virtual mobile joystick?

    And does this work with Unity 5 Beta?

    Thanks
     
  49. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    Hi,

    Rewired only comes with an example touch screen joystick to show you how to do it using the CustomController system. The example isn't drop-in ready. You should be able to modify existing thumb controllers to work with Rewired pretty easily though.

    Unity 5: It works but with issues. Currently, because of Unity 5's automatic code updating system, importing Rewired can take up to 2 minutes to complete as it searches for outdated code in the DLL even though the code is all up to date and ready for Unity 5. After it imports, the links to objects and Monobehaviors are broken and you have to manually re-import the Rewired_Core.dll for the links to be fixed. It's an issue with DLL-based assets that is affecting a number of asset store developers at present and I'm hoping they will be able to resolve it before the final release.
     
    Last edited: Nov 11, 2014
  50. BuildABurgerBurg

    BuildABurgerBurg

    Joined:
    Nov 5, 2012
    Posts:
    566
    Ok thanks for the explanation.

    Do you think it will be easy enough to use uGui for the virtual controls with this system?

    Thanks