Search Unity

Rewired - Advanced Input for Unity

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

  1. FreebordMAD

    FreebordMAD

    Joined:
    Mar 15, 2013
    Posts:
    633
    I'm sorry writing one post after another, but somehow while everything worked great in the editor, there are a lot of things that do not work now in the WSA build...

    I understand now that WSA supports XInput only, which makes the work of the last few weeks more or less completely useless. I should have informed my self about this before I started to work...

    Besides that, I'm not able to let the save/load functionality of the ControlRemapping1 example work. In the editor changing a key or joystick entry and clicking the ESC button would save the changes. The changes would be visible after restarting the demo. However, in the WSA build it does not work. The player prefs are not empty, but much too small to contain all the maps.

    [EDIT 1:]
    The problem seems to be that saveData.map.ToXmlString() in the code below returns an empty string.
    Code (CSharp):
    1.  
    2.         IList<Player> allPlayers = ReInput.players.AllPlayers;
    3.         for(int i = 0; i < allPlayers.Count; i++)
    4.         {
    5.             Player player = allPlayers[i];
    6.          
    7.             // Get all savable data from player
    8.             PlayerSaveData playerData = player.GetSaveData(true);
    9.          
    10.             // Save controller maps
    11.             foreach(ControllerMapSaveData saveData in playerData.AllControllerMapSaveData)
    12.             {
    13.                 string key = GetControllerMapPlayerPrefsKey(player, saveData);
    14.                 PlayerPrefs.SetString(key, saveData.map.ToXmlString()); // save the map to player prefs in XML format
    15. ...
    [EDIT 2:]
    saveData.map.ToXmlString() from the example above returns empty strings for keyboard maps and incomplete XMLs for joystick maps. See how the map below ends with <modi
    Code (CSharp):
    1. <?xml version="1.0" encoding="utf-16"?><JoystickMap dataVersion="1" hardwareGuid="d74a350e-fe8b-4e9e-bbcd-efff16d34115" hardwareName="XInput Gamepad" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://guavaman.com/rewired http://guavaman.com/schemas/rewired/1.0/JoystickMap.xsd" xmlns="http://guavaman.com/rewired"><sourceMapId>0</sourceMapId><categoryId>0</categoryId><layoutId>0</layoutId><name></name><hardwareGuid>d74a350e-fe8b-4e9e-bbcd-efff16d34115</hardwareGuid><enabled>true</enabled><buttonMaps><ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>3</actionId><elementType>1</elementType><elementIdentifierId>6</elementIdentifierId><axisRange>0</axisRange><invert>false</invert><axisContribution>0</axisContribution><keyboardKeyCode>0</keyboardKeyCode><modifierKey1>0</modifierKey1><modifierKey2>0</modifierKey2><modifierKey3>0</modifierKey3></ActionElementMap><ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>4</actionId><elementType>1</elementType><elementIdentifierId>7</elementIdentifierId><axisRange>0</axisRange><invert>false</invert><axisContribution>0</axisContribution><keyboardKeyCode>0</keyboardKeyCode><modifierKey1>0</modifierKey1><modifierKey2>0</modifierKey2><modifierKey3>0</modifierKey3></ActionElementMap><ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>4</actionId><elementType>1</elementType><elementIdentifierId>8</elementIdentifierId><axisRange>0</axisRange><invert>false</invert><axisContribution>0</axisContribution><keyboardKeyCode>0</keyboardKeyCode><modifierKey1>0</modifierKey1><modifierKey2>0</modifierKey2><modifierKey3>0</modifierKey3></ActionElementMap><ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>3</actionId><elementType>1</elementType><elementIdentifierId>9</elementIdentifierId><axisRange>0</axisRange><invert>false</invert><axisContribution>0</axisContribution><keyboardKeyCode>0</keyboardKeyCode><modifierKey1>0</modifierKey1><modifierKey2>0</modifierKey2><modifierKey3>0</modifierKey3></ActionElementMap><ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>2</actionId><elementType>1</elementType><elementIdentifierId>16</elementIdentifierId><axisRange>0</axisRange><invert>false</invert><axisContribution>0</axisContribution><keyboardKeyCode>0</keyboardKeyCode><modifierKey1>0</modifierKey1><modifierKey2>0</modifierKey2><modifierKey3>0</modifierKey3></ActionElementMap><ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>0</actionId><elementType>1</elementType><elementIdentifierId>17</elementIdentifierId><axisRange>0</axisRange><invert>false</invert><axisContribution>0</axisContribution><keyboardKeyCode>0</keyboardKeyCode><modifierKey1>0</modifierKey1><modifierKey2>0</modifierKey2><modifierKey3>0</modifierKey3></ActionElementMap><ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>2</actionId><elementType>1</elementType><elementIdentifierId>18</elementIdentifierId><axisRange>0</axisRange><invert>false</invert><axisContribution>1</axisContribution><keyboardKeyCode>0</keyboardKeyCode><modifierKey1>0</modifierKey1><modifierKey2>0</modifierKey2><modifierKey3>0</modifierKey3></ActionElementMap><ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>0</actionId><elementType>1</elementType><elementIdentifierId>19</elementIdentifierId><axisRange>0</axisRange><invert>false</invert><axisContribution>1</axisContribution><keyboardKeyCode>0</keyboardKeyCode><modifierKey1>0</modifierKey1><modifierKey2>0</modifierKey2><modifierKey3>0</modifierKey3></ActionElementMap><ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>6</actionId><elementType>1</elementType><elementIdentifierId>13</elementIdentifierId><axisRange>0</axisRange><invert>false</invert><axisContribution>0</axisContribution><keyboardKeyCode>0</keyboardKeyCode><modifierKey1>0</modifierKey1><modifierKey2>0</modifierKey2><modifierKey3>0</modifierKey3></ActionElementMap></buttonMaps><axisMaps><ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>0</actionId><elementType>0</elementType><elementIdentifierId>0</elementIdentifierId><axisRange>0</axisRange><invert>false</invert><axisContribution>0</axisContribution><keyboardKeyCode>0</keyboardKeyCode><modifierKey1>0</modifierKey1><modifierKey2>0</modifierKey2><modifierKey3>0</modifierKey3></ActionElementMap><ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>2</actionId><elementType>0</elementType><elementIdentifierId>1</elementIdentifierId><axisRange>0</axisRange><invert>false</invert><axisContribution>0</axisContribution><keyboardKeyCode>0</keyboardKeyCode><modifierKey1>0</modifierKey1><modifierKey2>0</modifierKey2><modifierKey3>0</modifierKey3></ActionElementMap><ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>0</actionId><elementType>0</elementType><elementIdentifierId>2</elementIdentifierId><axisRange>0</axisRange><invert>false</invert><axisContribution>0</axisContribution><keyboardKeyCode>0</keyboardKeyCode><modifierKey1>0</modifierKey1><modifierKey2>0</modifierKey2><modifierKey3>0</modifierKey3></ActionElementMap><ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>2</actionId><elementType>0</elementType><elementIdentifierId>3</elementIdentifierId><axisRange>0</axisRange><invert>false</invert><axisContribution>0</axisContribution><keyboardKeyCode>0</keyboardKeyCode><modifierKey1>0</modifierKey1><modifierKey2>0</modifierKey2><modifierKey3>0</modifierKey3></ActionElementMap><ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>4</actionId><elementType>0</elementType><elementIdentifierId>4</elementIdentifierId><axisRange>1</axisRange><invert>false</invert><axisContribution>0</axisContribution><keyboardKeyCode>0</keyboardKeyCode><modifierKey1>0</modifierKey1><modifierKey2>0</modifierKey2><modifierKey3>0</modifierKey3></ActionElementMap><ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>4</actionId><elementType>0</elementType><elementIdentifierId>5</elementIdentifierId><axisRange>1</axisRange><invert>false</invert><axisContribution>0</axisContribution><keyboardKeyCode>0</keyboardKeyCode><modi
     
    Last edited: Jul 9, 2015
  2. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    I would hope that's not the case. The Xbox 360 controller and the slew of XInput compatible controllers like Logitech's are still by far the most popular gamepads for the PC. Unless you are making your game specifically for flight sticks or steering wheels, I don't think making a WSA conversion could be completely useless.

    The ControlRemapping1 example simply uses PlayerPrefs to store and retrieve strings. I just did a bunch of test builds and each time playerprefs.dat does show the strings inside it. It's about 8kb. When I tested by running the app from within Visual Studio, it didn't load the data back, but it did save it to playerprefs.dat. I haven't tested from a complete deploy because my Windows is acting up and I can't get the program icon to show up in the list of apps. A reboot would work, but I have a lot of unfinished work I'm keeping open for tomorrow. (It's very late here.)

    If WSA has a problem saving to or loading from PlayerPrefs, you should file a bug report with Unity. The ControlRemapping1 example makes mention that saving to PlayerPrefs isn't a very good idea anyway, so you might want to implement a different system.
     
  3. FreebordMAD

    FreebordMAD

    Joined:
    Mar 15, 2013
    Posts:
    633
    Ok, it will not be completely useless, but still it is kind of disappointing that Microsoft again supports only their own stuff.

    Please check the edits of my prior post, the problem is not in the player prefs. The player prefs contain only the keys not the data, because the data returned in the WSA build is empty. ControllerMapSaveData.map.ToXmlString() is empty for keyboard maps and incomplete for joystick maps. It would be great if you could take a look at this tomorrow.

    Have a nice evening!
     
  4. MarioRuiz

    MarioRuiz

    Joined:
    Nov 7, 2009
    Posts:
    161
    Hi Guavaman, I'm making a build for android trying to test a game with an ouya controller and a shield wireless controller, doesn't seem to recognize any, is this related to that Android remotes are not detected thing?
    This is what I'm getting when testing on the editor (build set to android)
    warning nullref.png
    On android I get no response at all from the controllers.
     
  5. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    No, this is not related to remotes. There is an exception there. Show me the stack trace and all the information from that exception.

    1. What Unity editor platform is this?
    2. What version of Unity?
    3. What version of Rewired?
    4. What does the Android build log say?
     
    Last edited: Jul 9, 2015
  6. MarioRuiz

    MarioRuiz

    Joined:
    Nov 7, 2009
    Posts:
    161
    latest unity version,
    latest version of rewired, just did an upgrade from demo version to the full one (maybe upgrading problem?)
    chosen platform: android
    build logs meaning unity console logs or warnings?


    this is the stack trace

    Rewired: An exception occured during update (FixedUpdate). Input will not function.

    Message: Input Axis MouseAxis1 is not setup.
    To change the input settings use: Edit -> Project Settings -> Input

    Stack Trace: at (wrapper managed-to-native) UnityEngine.Input:GetAxisRaw (string)
    at Rewired.UnityUnifiedMouseSource.UpdateMouseInputData (Rewired.ControllerDataUpdater dataUpdater) [0x00000] in <filename unknown>:0
    at aFgHgYeDkRghZoMOxQMLeIexyNbu.LRMZQeOFMyNpgOdRgEPvNtoJrGD (UpdateLoopType ) [0x00000] in <filename unknown>:0
    at aFgHgYeDkRghZoMOxQMLeIexyNbu.gghcdYtKaoJOWhytnSFlUDSWtwY (UpdateLoopType ) [0x00000] in <filename unknown>:0
    at Rewired.ReInput.gghcdYtKaoJOWhytnSFlUDSWtwY (UpdateLoopType ) [0x00000] in <filename unknown>:0
    at Rewired.ReInput.gghcdYtKaoJOWhytnSFlUDSWtwY (UpdateLoopType , System.String ) [0x00000] in <filename unknown>:0
    at Rewired.InputManager_Base.DoUpdate (UpdateLoopType updateLoopType) [0x00000] in <filename unknown>:0
    UnityEngine.Debug:LogError(Object)
    Rewired.InputManager_Base:HandleException(String, Exception)
    Rewired.InputManager_Base:DoUpdate(UpdateLoopType)
    Rewired.InputManager_Base:FixedUpdate()
     
  7. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    No. Upgrading from the demo does nothing but replace the DLLs.

    Something you did cleared Rewired's required Input Manager settings. You either skipped the installation step or you installed some other package that overwrote ProjectSettings/InputManager.asset

    Run Window -> Menu -> Rewired -> Setup -> Run Installer

    And allow it to replace InputManager.asset when it asks.
     
  8. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    Is this from the log file or the editor log window? The log window can't display infinite characters and truncates after a certain number. This line was over 6000 chars before it truncated. The log file won't truncate.

    After testing in WSA, none of the XML to string method return any data. There's absolutely nothing special about these methods. They're simply calls to StringWriter and XMLWriter. Looks like I'm going to have to replace a bunch of functionality for WSA compatibility (again). This is the most problematic, error prone, not-cross-platform platform that Unity supports, bar none. Seems like every new Unity release breaks something in WSA also.

    Edit: Found the problem. WSA requires you to Flush the XML writer or you will get 0 bytes returned. No other platform requires this.
     
    Last edited: Jul 9, 2015
    FreebordMAD likes this.
  9. MarioRuiz

    MarioRuiz

    Joined:
    Nov 7, 2009
    Posts:
    161
    did it and it did make the controllers work.
    I'm running ouya controllers on a nvidia shield console and now it seems that the left and right triggers are mapped to what should be the right stick, and the right stick won't work at all, the nvidia shield controller is ok but the ouya ones are not
    Edit: already made sure the maps were correct.
     
  10. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    Nvidia told me that the Shield console's joystick handling was identical to the Shield Tablet. If the engineer was wrong, then controllers may be mapped differently on that device than other Android devices. There is no way I can know without an Nvidia shield to test on.

    Use the Rewired/DevTools/UnityJoystickElementIdentifier tool to find out what the axes are assigned to.

    See this for help on how:
    http://guavaman.com/projects/rewired/docs/HowTos.html#new-controller-definitions


    If these values don't match what I have defined for the Android platform, the controller will not work correctly.
     
  11. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    Rewired 1.0.0.59 is available for download for registered users now on the website. If you've bought Rewired and want to get access to the latest downloads immediately, contact me with your email address. The update will be live on the asset store in 5-10 days.

    1.0.0.59:

    API Changes:
    - Added ControllerMap.DeleteElementMapsWithAction
    - Added ControllerMap.DeleteButtonMapsWithAction
    - Added ControllerMapWithAxes.DeleteAxisMapsWithAction
    - Added InputBehavior.Reset

    Changes:
    - Changed Saitek P990 FPS button mapping in Dual Analog Gamepad Template from Center 2 to Center 1.

    Bug Fixes:
    - Fixed XML string output always returning 0 bytes on WSA platform.
     
    FreebordMAD likes this.
  12. FreebordMAD

    FreebordMAD

    Joined:
    Mar 15, 2013
    Posts:
    633
    Dude, I just have to say again, I don't know how you manage to give such epic support, but you do! It's the second time that I report a problem and it is fixed within 48h hours!
     
  13. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    Easy! I have no life! :p
     
    Gua, FreebordMAD and hopeful like this.
  14. Steamroller

    Steamroller

    Joined:
    Jan 2, 2013
    Posts:
    71
    Quick question, Is it possible to have two or more actions assigned to the same button but differentiated either tap, double tap or hold in your system? Also, do you support button combos?
     
  15. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    No. This kind of super-specific implementation is left up to the developer to implement. You can implement this easily though.

    1. Assign an Action to your button.
    2. Check GetButtonDown("Action") and execute your "tap" code.
    3. Check GetButtonDoublePressDown("Action") and execute your "double tap" code.
    4. Check GetButtonDoublePressHold("Action") and execute your "double tap and hold" code.

    Of course you're going to have to manage filtering out "tap" from the beginning of a "double tap" if that's the desired behavior for your game with a timed buffer. You'd also have to do the same for "double tap" if the user intent is double tap and hold and you don't want "double tap" returning true.

    (The same methods above have GetNegativeButton... equivalents for getting negative buttons. That is, a button that returns a negative value when pressed such as pressing S in a typical WASD control setup for the axis-type action Move Forward/Back. For reading an axis as a +/- button.)

    No. Again, they're up to you to implement because there are practically infinite desired behavior nuances to try to cover this in a general system. See the below posts for information on implementing a basic 2-button combo using Actions:

    http://forum.unity3d.com/threads/rewired-advanced-input-for-unity.270693/page-18#post-2187987
    http://forum.unity3d.com/threads/rewired-advanced-input-for-unity.270693/page-18#post-2188023
    http://forum.unity3d.com/threads/rewired-advanced-input-for-unity.270693/page-18#post-2188177
     
    Last edited: Jul 13, 2015
    andreiagmu likes this.
  16. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
  17. Spy-Shifty

    Spy-Shifty

    Joined:
    May 5, 2011
    Posts:
    546
    Hi, your tool looks great!

    Does Rewire support Force Feedback and Rumble? (and how)
     
  18. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    Rewired supports vibration only on XInput devices in Windows and Xbox One gamepads on Xbox One.

    Nearly every single PC device that supports vibration has its own unique SDK which you have to use to interact with the device. Rewired does not incorporate any of these SDKs.
     
  19. FlaxSycle

    FlaxSycle

    Joined:
    Oct 6, 2012
    Posts:
    232
    I recently implemented Rewired and have been really impressed with the whole thing, although currently running into an issue in Unity 5.1 in Linux where some controllers (eg Dualshock 4 and Logitech 310 (either mode)) are either failing to be detected or have inputs coming through wrong.

    I'm still investigating, but is there any reason these controller types wouldn't work correctly under Linux in Unity 5.1 or is it likely something on my side?
     
  20. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    Unity has a ton of input issues in Linux. It's the worst of all Unity platforms. Rewired uses Unity input for the underlying input source in Linux at present. That means Unity's bugs will affect Rewired as well. There have always been problems in Linux such as incorrect auto-calibration on first start which renders most axes useless without a manual recalibration, keyboards showing up as joysticks, zero hot-plugging capability, etc. But a recent Unity update introduced even more bugs in Linux input. They introduced new keyboard bugs as well as more joystick bugs such as when you unplug and replug joysticks the Input.GetJoystickNames array keeps growing and growing (even though hot plugging still doesn't work). These bugs are so severe there's no way to fix them from a layer on top. The only solution will be for me to write a native input library for Linux which is on my list of things to do. It's unfortunate, but it's the current situation on Linux.

    I haven't re-tested these joysticks in 5.1.1 to determine if any button mappings changed, but if they did, Rewired doesn't support per-Unity-version button mappings at present if that's the issue (I've never seen this happen before). If you want to investigate and see what's happening with the joystick names or the buttons, use the DevTools/UnityJoystickElementIdentifier tool, put it in a scene with a Rewired Input Manager and build it on Linux. You'll see the joystick names as seen by Input.GetJoystickNames and you'll see what buttons and axes align to.

    Additionally, the Linux mappings are based on Ubuntu. I will see if they have changed and get back to you.
     
    Last edited: Jul 16, 2015
    hopeful likes this.
  21. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    @FlaxSycle

    EDIT: Support for Unity pre-configured joysticks was added in 1.0.0.63

    Yep. It's just what I feared. Unity has done it again. They've done the impossible. They just made Linux input even worse than it was before.

    Unity 5.1 has made some major breaking changes to Linux input.

    First of all, all keyboard key codes stick from the first time you press them and never release again rendering keyboard input completely useless.

    Second, they're trying to make hot-plugging work it looks like and totally botching everything up in the process. The F310 pretty much doesn't work anymore. It is never detected on Unity start. You can force it to be detected (after a long delay) by removing and and plugging it back in, but it will then make two identical entries. Even then, the controls don't work.

    Third, the Sony Dual Shock 4 pad now returns completely different values than it did in 4.x and 5.0. All mappings are wrong. They've changed some underlying input library I'm guessing. This could very well have broken all 45+ Linux controller mappings I created.

    All the old bugs are still there too. Axes map to ranges of 0.5 - 1.0 at random. Some devices show up with multiple name entries. Etc.

    All the above testing was done using tools that show raw data from Unity using Input.GetJoystickNames and getting the joystick button and axis values directly.

    Due to the fact that Unity Linux is essentially unusable and now and probably requires that I remap all the controllers all over again with no guarantee they won't continue breaking things as they slowly try to make Linux input usable, I believe I'm going to leave it as is for now until I can fix the problem right as I did for Windows and OSX.
     
    Last edited: Jul 25, 2015
  22. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    @FlaxSycle I had more time to do some testing today and found out a few things in Linux:

    1. This breaking change happened at 5.x. Still TBD if the 4.x branch has it and what version that happened on (if it did).
    2. It does not affect all controllers. Thus far I've tested the following controllers:
    • Microsoft Xbox 360 Wired - Works
    • Saitek P880 - Works
    • Saitek P990 - Works
    • Ouya Controller - Works
    • Amazon Fire Controller - Works
    • Sony DualShock 4 - Axis mappings do not match
    • Logitech F310 (D & X modes) - Controller does not function
    I'm taking this to mean that most of my mappings will probably still work correctly, but all will have to be tested. There's no way to support the F310 because it simply doesn't return any data, but I will have to add a per-unity-version mapping option to the controller definition system to support the DS4. This will not be in the next release as I already have enough to test in this release which is due out today or tomorrow I hope.

    Even adding proper mapping for the DS4, there's nothing that can fix the random and very common Axis calibration issue without manual user intervention, which to me is enough of a problem to write off Unity's Linux input support as broken, as it has been from day 1.

    EDIT: Support for Unity pre-configured joysticks was added in 1.0.0.63
     
    Last edited: Jul 25, 2015
  23. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    I believe this explains the issue with the DS4:

    Unity 5 Upgrade Guide
    Input.IsJoystickPreconfigured

    Unity introduced a new internal gamepad mapping system in Unity 5 that maps certain devices to standard layout in Linux. Surprisingly, the Xbox 360 gamepad wasn't affected. The DS4 was however and the gamepad's axis layout matches what is shown in the IsJoystickPreconfigured page.

    This would mean to accommodate these devices, I would have to check IsJoystickPreconfigured on the device and then load a generic Linux Gamepad map that is set up to follow that pattern outlined in the Input.IsJoystickPreconfigured page. That would probably help with the controllers that Unity has created standard mappings for, but nothing will help with the problem that as you add and remove devices the Input.GetJoystickNames array continues to grow and grow with multiple copies of the same joystick being plugged and unplugged. Rewired will see this as many joysticks and there's no way to filter those out because Unity's Input API is so bare bones as to give you nothing else but an array of names to work with.

    EDIT: Support for Unity pre-configured joysticks was added in 1.0.0.63
     
    Last edited: Jul 25, 2015
  24. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    More fun facts on the state of Unity's Linux input system (Unity 5):

    • Sony DualShock 4 shows up as pre-configured SOMETIMES. I haven't found a pattern yet, but one moment it shows up as a pre-configured joystick with one button/axis layout, the next moment it shows up not-pre-configured with a totally different button/axis layout.
    • Sony DualShock 3 shows up pre-configured, but the right stick vertical axis doesn't work.

    Seriously guys??
     
  25. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    Okay, finally, I am happy to announce that Rewired 1.0.0.60 has been released on the website for registered users. (Contact me if you want to register to get early access to updates.) This includes the much belated uGUI remapping system, Control Mapper -- a customizable, responsive runtime control remapping system that you can drop in and use in your games. Also included is a new user data interface for saving and loading user data. If your needs are straightforward, just use the included component and have all user control data saved automatically to PlayerPrefs. (Or customize to your own data storage system of choice.) Also worth noting is the addition of Axis 2D, which allows for smooth radial deadzones on "analog" joysticks.

    Control Mapper has many options which you can customize to fit your game's needs:
    • Responsive layout that fits to various size displays.
    • Full joystick, mouse, and touch control support.
    • Support for user-customizable controller maps, full axis calibration, sensitivity settings, and more.
    • Optional display of Players for multiplayer games.
    • Optional support for multiple controllers per-player.
    • Optional Input Behavior customization.
    • Optional Map Category display.
    • Customizable list of Actions to show per category.
    • Optional display of Action category names.
    • Optional Keyboard, Mouse, and Controller support.
    • Choose the number of alternate fields per controller type.
    • Customizable theme settings for changing colors and button styles.
    • Customizable language settings for changing button and window labels and messages.
    • Menu control by your choice of Rewired Player(s).
    • Customizable Actions for screen control display.
    • Example scenes included.
    • Documentation is here.

    ControlMapper_Complex.png ControlMapper_SimpleLight.png ControlMapper_Calibrate.png ControlMapper_Sensitivity.png ControlMapper_Inspector1.png


    Release Notes:

    1.0.0.60:

    Changes:
    - Added Control Mapper, ready-to-use, customizable control remapping system.
    - Added UserDataStore system for saving and loading control configuration data. Can be customized to use any data storage system you choose.
    - Added UserDataStore_PlayerPrefs component for simple saving and loading of control configuration data using PlayerPrefs.
    - Added Axis2D element which binds two axes together as an 2D axis so deadzone can be computed from the combined axes.
    - All recognized game controllers updated with Axis2D on all joysticks on all platforms.
    - All joysticks in recognized controllers now use a radial deadzone.
    - Added Compound Element to Hardware Joystick Map.

    API Changes:
    - Added Controller.Axis2D class
    - Added Controller.Element.isMemberElement property
    - Added Player.GetAxis2D method
    - Added Player.GetAxis2DPrev method
    - Added Player.GetAxis2DRaw method
    - Added Player.GetAxis2DRawPrev method
    - Added CompoundControllerElementType enum
    - Added ControllerElementIdentifier.compoundElementType property
    - Added ControllerElementType.CompoundElement
    - Added InputBehavior.ImportData method
    - Added UserDataStore class
    - Added UserDataStore_PlayerPrefs class
    - Added Interfaces.IUserDataStore interface
    - Added ReInput.userDataStore property
     
    Last edited: Jul 19, 2015
  26. electroflame

    electroflame

    Joined:
    May 7, 2014
    Posts:
    177
    Looks amazing! Congratulations on getting it out, and thanks for all of your hard work on Rewired!
     
    guavaman likes this.
  27. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    Wow! This is going to be so much fun. It will be interesting to see all of the different designs your customers come up with the new Unity UI Control Mapper mapping screens. Along with Native Input on Windows and OS/X this is a great addition to Rewired.

    Keep up the great work!
     
    Last edited: Jul 19, 2015
    guavaman likes this.
  28. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551

    @Steve Tack just in time for the those who like Flight controller mapping.
     
  29. Steve-Tack

    Steve-Tack

    Joined:
    Mar 12, 2013
    Posts:
    1,240
    Such a great bonus feature.

    <insert happy dance>
     
    guavaman likes this.
  30. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,364
    Guavaman,
    Played with the trial and didn't find any mapping touch screen -> action so I'd like to ask a few questions to wrap my head around how you implement touch state, delta position, and how click/tap on object is detected.
    How would I implement the following:
    • touch camera controls a-la clash of clans+: one finger slide = pan, two finger pinch = zoom on the center of the fingers, and two finger rotate = roll around the center of the finger projected to the world ground, tap on object = select, drag on object = pan camera, tap select then drag object = drag object.
    • mouse camera control a la command and conquer+: left click drag on ground = pan, mouse wheel = zoom, right click drag on ground = rotate around click point, click on object = select,drag on object = pan camera, select then drag in object = drag object.
    Thanks.
     
    Last edited: Jul 19, 2015
  31. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    Rewired does not have any kind of built-in touch, swipe, gesture detection system. At present, the only way to associate any kind of touch taps or gestures or mouse gestures to a Rewired Action is by using a CustomController: http://guavaman.com/projects/rewired/docs/CustomControllers.html

    You are in full control over what data you feed to the CustomControllers buttons and axes. This works very well for on-screen touch joysticks and buttons and gyroscope control. As for gestures, you would need a system to read the finger/mouse movements, determine what the user is doing, then you could input that as a button or axis into a touch control. However this is not ideal for most touch/swipe/gesture needs and certainly wouldn't handle complex gestures like pinch zoom well or things like drag-and-drop. That's not the intention.

    Mouse control like C&C:
    That's simply a matter of making the proper Actions and doing something in your code based on them. Make a zoom Action and map it to the mouse wheel. If this has to be context sensitive (what is selected determines what happens when the wheel is zoomed), then you'd have to make that determination in your code. Instead make the wheel Action "Mouse Wheel" or something that doesn't specifically state the purpose of the action then decide what to do with that input based on the context.

    As for click for pan, detect a mouse click over your target area (either via the usual fixed left mouse button means or via an Action assigned to the left mouse button), then set a flag in your code. When that flag is set and the mouse is moved, pan the screen. You can either read the mouse movement delta directly or assign Actions to the mouse X/Y axes and choose an appropriate mouse handling mode on the Action's Input Behavior based on your needs. Read the value of the Actions and move the camera. http://guavaman.com/projects/rewired/docs/RewiredEditor.html#InputBehaviors

    >> how click/tap on object is detected

    This is totally up to you to decide how to implement this. There are many ways to do so in Unity: Using colliders and raycasting from the mouse/finger position, the new UI system's Graphic Raycaster, reading the pixel values at a position on the screen, etc. Depends on your specific needs.

    This is all game logic implementation which is up to the developer and not built into Rewired.
     
    Last edited: Jul 20, 2015
  32. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    Rewired 1.0.0.61 has been released on the website for registered users. (Contact me if you want to register to get early access to updates.)

    You can now disable keyboard input for various reasons if you choose to do so. This can improve performance slightly on mobile platforms if keyboard input is not required. Also, it provides a solution for an issue with joysticks on Android that return both joystick buttons and keyboard key codes for certain buttons. (See docs for details on the Android joystick issue.)

    1.0.0.61:

    API Changes:
    - Added ReInput.ControllerHelper.keyboardEnabled

    Changes:
    - Improved performance of joystick input on Unity fallback platforms.
     
    Last edited: Jul 20, 2015
  33. _MGB_

    _MGB_

    Joined:
    Apr 24, 2010
    Posts:
    74
    Hi,

    I must have missed something here, but I just can't get my joystick working with ReWired. Keyboard and mouse Maps work fine, but joystick and pads fail to do anything.
    I've read the docs, read the faq, read the troubleshooting part: map is created (all default), elements assigned, assigned to player (tried both players), ticked: Settings.Auto-assign joysticks & Player.StartEnabled.
    The ReWired remapping demo scene can read my joysticks fine (Saitek Cyborg / 360 win pad).
    Is there something beginners perhaps miss out that could explain this? (Using Unity 5.1.2f1, ReWired v1.0.0.59)

    Ed: calling 'AddController(ControllerType.Joystick, 0, true)' from script at startup makes it work finally! I've definitely assigned it to the player in the editor though...
     
    Last edited: Jul 20, 2015
  34. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    What's the Max Joysticks Per Player setting?: http://guavaman.com/projects/rewired/docs/RewiredEditor.html#Settings

    You probably have multiple controllers connected to your machine and not enough Players to assign them all to. Rewired's default settings will only assign ONE joystick per player. If you only have 1 player and 2 joysticks, the 2nd joystick is going to be left unassigned. You cannot know which joystick will be assigned to which Player from the editor. It is determined by the settings in the Rewired Input Manager auto-assignment area and by the order the joysticks appear to the system. (Raw Input will sort by USB port (or Bluetooth), XInput will sort by the controller light number, Direct Input is sorted however Microsoft decided to do that, etc.)

    It's easy to check what's been assigned to what Player:

    Code (csharp):
    1. foreach(Player p in ReInput.players.Players) {
    2.   foreach(Joystick j in p.controllers.Joysticks) {
    3.   Debug.Log(p.name + " is assigned Joystick \"" + j.name + "\" (" + j.id + ")");
    4.   }
    5. }
     
    Last edited: Jul 21, 2015
  35. _MGB_

    _MGB_

    Joined:
    Apr 24, 2010
    Posts:
    74
    1 joy per player, yes it was getting assigned to player 0.
    I see the problem now: I was regarding assignment to players and assignment of a joy map in the editor as the same thing.
     
  36. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    For Flight Controllers and HOTAS systems this will be extremely useful. Glad Rewired supports all the good Flight controllers out of the box too.
     
  37. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    So per your request it does support potentially unlimited controllers per player (limited mostly by screen space). It should easily be able to support your dream set up of multiple players each with 4-5 flight devices attached. That would be some serious USB spaghetti! :)

    I even made sure that it supports handling assigning devices with no buttons like the flight pedals. (There were some special things to take into account there.)
     
  38. Cubic_Creo

    Cubic_Creo

    Joined:
    Oct 13, 2014
    Posts:
    47
    I'm using player.controllers.maps.ClearMaps and player.controllers.maps.AddMapsFromXml to load my player's control settings when the game loads (as shown in your examples). It works fine, but the problem I'm having is that I want to add a new element to the controller map via the Rewired Editor. Since the new element is not in the saved XML, when I call AddMapsFromXml, the new element doesn't get added, and the player doesn't have access to it. The new element is not returned from controllerMap.GetElementMapsWithAction(inputAction.id), and player.GetButton(actionName) always returns false. Besides re-implementing AddMapsFromXml myself, is there any way to get it to recognize the new element I've added to the controller map?
     
  39. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    Is this project under development or published? If it's not published and you don't have to worry about invalidating user data, just clear your saved controller data. Far simpler than the alternatives.

    If it's PlayerPrefs, this is of course would be a problem if you store other data in PP also because Unity gives you no access to list your stored data and clear only what you want to. The alternative is to change your key prefix.

    It's gone because you're loading a new map in place of the one you defined in the editor. The Rewired Editor maps are nothing but a default set of maps that load on startup to give the players something to start with. When you load a saved XML map over it, those defaults are gone by definition.

    You have 3 options as I see it:

    1. Manually merge the existing map (the default that gets loaded on startup) with the one you're loading from xml and then add that map to the Player. That's obviously going to require you doing some version tracking, etc. because you don't want to be modifying people's maps after they've done the update that adds the element. (And it also has the problem that you can't know what the user's assignment intention was. Are you going to overwrite one of their assignments with your new Action? If they've already assigned it to that button, where would you then assign it to? How will you know which mappings on that map that do exist in the default map but don't exist in the saved map should be added back?)

    2. Go through all your stored data (assuming it's not saved in PlayerPrefs, in which case you have no way of accessing it randomly) and run an upgrade on the saved XML data adding the mapping you want. This may be very difficult though because you won't know which elements need to have the maps added because there is no longer any relation to the template (assuming Dual Analog Gamepad).

    3. Since you're saving and loading maps, I assume you have a control mapping system set up. If so, just let the user choose to map this new action themselves. You can warn them if they don't have the action mapped and it's absolutely necessary to gameplay.
     
    Last edited: Jul 21, 2015
  40. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    Another workaround would be to add it as a new map in a different category. So now you'd have an extra controller map being loaded in a new category that contains your new action. It won't be replaced because you have no saved XML maps in that category to replace it. Of course, you still have the problem that your new mapping may conflict with one the user changed.
     
  41. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    Rewired 1.0.0.61 is now live on the Unity Asset store!

    1.0.0.61:

    API Changes:
    - Added ReInput.ControllerHelper.keyboardEnabled

    Changes:
    - Improved performance of joystick input on Unity fallback platforms.

    1.0.0.60:

    Changes:
    - Added Control Mapper, ready-to-use, customizable control remapping system.
    - Added UserDataStore system for saving and loading control configuration data. Can be customized to use any data storage system you choose.
    - Added UserDataStore_PlayerPrefs component for simple saving and loading of control configuration data using PlayerPrefs.
    - Added Axis2D element which binds two axes together as an 2D axis so deadzone can be computed from the combined axes.
    - All recognized game controllers updated with Axis2D on all joysticks on all platforms.
    - All joysticks in recognized controllers now use a radial deadzone.
    - Added Compound Element to Hardware Joystick Map.

    API Changes:
    - Added Controller.Axis2D class
    - Added Controller.Element.isMemberElement property
    - Added Player.GetAxis2D method
    - Added Player.GetAxis2DPrev method
    - Added Player.GetAxis2DRaw method
    - Added Player.GetAxis2DRawPrev method
    - Added CompoundControllerElementType enum
    - Added ControllerElementIdentifier.compoundElementType property
    - Added ControllerElementType.CompoundElement
    - Added InputBehavior.ImportData method
    - Added UserDataStore class
    - Added UserDataStore_PlayerPrefs class
    - Added Interfaces.IUserDataStore interface
    - Added ReInput.userDataStore property
     
  42. Cubic_Creo

    Cubic_Creo

    Joined:
    Oct 13, 2014
    Posts:
    47
    Thanks. The game is published. I like your third option, and it sparked an idea. I run an update script on the first run of every new version. Since I know which elements I added to which maps, I'll just add them manually in the update script via controllerMap.CreateElementMap. That way new users will get the complete mapping based on what I set up in the Rewired Editor, and existing users will get their old mappings upgraded.
     
  43. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    Sounds like a good idea, but the maps won't appear in the Players unless the user connects that joystick. You would have to go through all saved maps and modify them that way to get them all.

    I suppose you could add a version number to your save data so if you load an XML file without a version #, you make the change, then the next time it's saved you save it with the new version number. That would work because it would just update the map at the time they connect the controller.
     
  44. Cubic_Creo

    Cubic_Creo

    Joined:
    Oct 13, 2014
    Posts:
    47
    Ah. I see what you mean. In this case it's the keyboard and I'm assuming the first keyboard found is what I want, but I suppose I should go in and make it a little more flexible.
     
  45. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    Oh, keyboard makes it easy. Rewired doesn't support multiple keyboards anyway (yet). And you don't have to worry about the headaches of trying to match up element identifiers on different gamepads. Keyboard is always "connected" too.
     
  46. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    Thank you!

    Just tried the Controller Mapper demo with CH FighterStick and it works very well. I need to get all of the other controllers hooked up and see how well that works too. This is so much fun.

    @Steve Tack will definitely like this.

    This will also be very useful for UFPS too. So many possibilities.
     
  47. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    Glad you like it! Don't come back with bug reports when you have 32 flight yokes hooked up plz... haha!

    One user has already implemented it with UFPS. I hope it went well (AFAIK it did).
     
  48. Gua

    Gua

    Joined:
    Oct 29, 2012
    Posts:
    455
    Thank you for making Controller Mapper!

    I've already implemented it in UFPS game and updated game is live on Steam. I've cut some corners to implement it as fast as possible, so I'm sure it might be implemented even better. But even with that implementation, users are happy.



    The only noticeable problem I had is that sensitivity in that menu affects only mouse and don't affect gamepad. So I had to use my own solution to adjust sensitivity. But it's probably not Rewired fault, cause my FPS player is a mix of scripts from old UFPS and new UFPS. That's what may be a source of a problem.
     
    Last edited: Jul 22, 2015
    guavaman likes this.
  49. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    It looks like all is well based on the message he just posted.

    Saitek cockpit (that they sell fully loaded) is about 21 usb devices I believe. So someone in theory could hit 32 usb devices without too much work.

    In my much simpler use case I just picked up some Flight Controllers and a gamepad to see how well it works with the screen size available. Actually it works very nicely with 6 controllers. (see screen shot).


    Rewired_1.0.0.61_ControlMapper.JPG
     
  50. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    Wow! That was fast! Great to hear they're happy with it. :)

    Control Mapper provides 2 possible sensitivity options for Actions, one for the mouse and one for joysticks for each Input Behavior. These are related to the Actions that are assigned to these elements, so the Action must have the appropriate Input Behavior assigned to it for this to affect anything.

    There is also a hardware joystick sensitivity setting in the Calibration page for changing the sensitivity of the joystick axes themselves. Changing this would affect all input from this joystick axis.

    To set up Input Behaviors for Mouse and Joystick sensitivity do the following:

    1. Set up an Input Behavior you want to use for the Sensitivity setting.

    inputbehavior.gif

    2. Assign that Input Behavior to the Action you want to adjust sensitivity for.

    actions.gif

    3. Set up the Input Behavior in Control Mapper enabling both Show Joystick Axis Sensitivity and Show Mouse XY Axis Sensitivity.

    cmsettings.gif

    4. This is the result. Changing the top slider will adjust the sensitivity of Actions that use this Input Behavior when the input comes from a joystick axis. The bottom one will adjust the sensitivity of Actions that use this Input Behavior when the input comes from a mouse X/Y axis.

    sensitivity.gif
     
    Last edited: Jul 22, 2015