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,625
    I'm glad you found the answer.
     
  2. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    Thank goodness the Asset Store rushed through the update for 1.1.8.3. It's now live on the asset store for download and the 1.1.8.1 installer issue is no more.

    dancingbanana_sm.gif

    Be sure to read Updating Rewired before updating.

    Release notes since the last Unity Asset Store version:

    1.1.8.3:

    Changes:
    - Removed .asmdef files due to issues with asset integration dependencies.

    1.1.8.2:

    Bug Fixes:
    - Reverted changes to editor system in 1.1.8.0 which caused installation problems in Unity 5.x.

    1.1.8.1:

    Changes:
    - Changes to editor code to prevent potential installation problems on some systems.

    Bug Fixes:
    - Fixed incorrect assembly names in addon .asmdef files.

    1.1.8.0:

    Changes:
    - Updated RewiredStandaloneInputModule to match changes to StandaloneInputModule made in Unity 2017.1 where UI input events are not sent when the application does not have focus.
    - When updating Rewired in Fixed Update, Direct Input and XInput now refresh low-level input values every Fixed Update instead of only the first update per frame.
    - Rewired Editor: Changed name of "User Assignable" checkbox in Actions and Action Categories to "Visible in Lists."
    - Added .asmdef files to Rewired and all addons to compile loose scripts into libraries in preparation for the Unity 2017.3 asmdef system.
    - Filtered out duplicate devices on OSX and Linux when Steam is creating emulated Steam Controllers from other gamepads when using Steam's PS4, Xbox, and Generic Gamepad Configuration Support.
    - Windows, Direct Input w/ Use XInput disabled: Added support for Steam emulated controllers.
    - Added Universal Fighting Engine integration pack.

    API Changes:
    - Added ReInput.PreShutDownEvent event.
    - Added ReInput.ShutDownEvent event.
    - Added ReInput.ConfigHelper.updateLoop property.

    Modified Controller Definitions:
    - Steam Controller: Added Direct Input definition.

    Bug Fixes:
    - Windows UWP, Native w/ Use XInput: Fixed rare exception when disconnecting an XInput-compatible controller.
    - Windows UWP, Native: Fixed issue added in 1.1.7.8 causing it to poll for new devices every frame.
    - Fixed bug in ControllerMapWithAxes.ctor(ControllerMapWithAxes) constructor overload causing axis maps to not be copied.
    - Removed redundant Right Trigger mapping in the Xbox 360 controller Dual Analog Template definition causing the right trigger to be mapped twice.

    1.1.7.9:

    Bug Fixes:
    - OSX, Native: Fixed bug preventing Steam Controller from working the primary input source is set to Native.
    - Sony DualShock 2 definition, Super Dual Box Pro variant: Fixed Select and Start mappings.
     
    Last edited: Dec 1, 2017
  3. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    That is great news that the Asset store released it so quickly. Thanks for all your hard work that you put into Rewired.
     
  4. Discmage

    Discmage

    Joined:
    Aug 11, 2014
    Posts:
    60
    I seem to be having trouble with a couple of things with Rewired...loving it when it works though so hopefully these will be simple issues that I must be missing.

    1. I seem to have an 'Unknown' controller on my computer...I have a lot of peripherals and it could be any one of them...rather than always try to plug and unplug everything...how would I just do a check for 'Unknown' controllers and then connect the first non unknown controller to player0? At the moment I am just setting the [1] controller to player one which is fine for now, but eventually I will have to work around this.

    2. My keyboard mapping for "Jump" works fine, but pressing the equivalent button on the controller ('A' in this case) doesn't seem to work. I believe I had it working, but then it stopped. Can't think of why. I have 5 : A (Jump +) in the Xbox 360 controller Element box.

    3. I have set up a 'Slide' Action in the Input manager. But it says it says 'ArgumentException: Input Button Slide is not setup. To change the input settings use: Edit -> Project Settings -> Input' As an example the Joystick map has '6 : B (Slide +)' in the Element: section. This is set up in the same way as jump is, to my knowledge, but comes up with the error. If I comment the slide code out then Rewired works fine (except for problem 2)

    4. More an odd thought, but the default Input Manager has HEAPS of added inputs. I assume Rewired adds this to it?

    Sorry for so many issues...I'm stumped to figure them out and have been trying to fix them for the last couple of nights.
     
    Last edited: Dec 3, 2017
  5. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    The answers to these questions will help answer some of the others

    What version of Unity are you using?
    What version of Rewired are you using?
    What operating system are you building for?

    2. You should map the dual analog template as mentioned in the Rewired Best Practices instead of just a single controller.

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

    The specific section the dual analog template is found here and it has a diagram on how the gamepad is setup too.

    http://guavaman.com/projects/rewired/docs/ControllerMaps.html#dual-analog-gamepad-template

    4. Yes. Rewired adds those during Installation.
     
    guavaman likes this.
  6. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    No, there is no way to make Rewired ignore Unknown Controllers when assigning Joysticks to Players. The only way to do this would be to disable Joystick Auto-Assignment and assign them yourself. This is absolutely not recommended, however. Unknown Controllers are extremely important to support. If someone uses any Joystick other than the ones recognized by Rewired listed here, it will show up as an Unknown Controller. If you ignore Unknown Controllers, you are effectively limiting Rewired to only working with that specific list of controllers. There are many, many controllers on the market that can never be added as recognized controllers to Rewired due to bad manufacturing practices. If you do not support Unknown Controllers, your users will not be able to use any of these controllers. If new controllers come out that are not supported by Rewired yet, they wouldn't be able to use those either.

    The correct way to approach Unknown Controllers is to provide users a means of A) remapping their controls and B) assigning Joysticks to Players. You can do this this yourself with a custom remapping implementation or by using Control Mapper.

    If your game is 1-player, you should set Max Joysticks Per Player to some large value so all Joysticks found are assigned to that Player as recommended here.

    See this checklist for determining why Joystick control doesn't work:
    http://guavaman.com/projects/rewired/docs/Troubleshooting.html#joystick-problems

    If that doesn't help, see this on how to determine the source of your problem:
    http://guavaman.com/projects/rewired/docs/Troubleshooting.html#debug-information

    In general, you should use the Dual Analog Gamepad Template and not the specific gamepad to map controls unless you need to map an element that is not available on the Dual Analog Gamepad Template such as the DS4 touchpad click. Using the Dual Analog Gamepad Template allows you to create a map once and cover all these gamepads cross-platform. It also avoids issues such as this one. See Best Practices for more recommendations.

    If you are getting "'ArgumentException: Input Button Slide is not setup." messages, that means you are using Unity's input system and not Rewired. That exception is generated directly by Unity when you call Input.GetButton/Up/Down("Slide"). Rewired does not throw an exception when you try to use an Action that does not exist in the Rewired Input Manager. It shows a warning in the console one time the first time you call the non-existent Action. You do not need to create any entries in the Unity input manager related to any of your Rewired Actions.

    Check your code everywhere and make sure you are actually using Rewired for all your input. If you used Unity Input Override to allow you to leave your scripts calling Input.Get___() and still use Rewired, make sure the script is still there in Plugins/Rewired and set to be enabled.

    Your problem of button A not working and this exception lead me to the conclusion that Rewired is not being used for input. Please check all your scripts and if necessary reinstall Rewired:

    How to do a clean reinstall of Rewired:

    1. Close the Unity editor if it is open.
    2. Open the Unity editor.
    3. Delete the Rewired folder.
    4. Close the Unity editor without saving if asked.
    5. Open the Unity editor.
    6. Install Rewired from the Unity Asset Store.
    7. Close the Unity editor without saving if asked.
    8. Open the Unity editor.
    9. Test.

    This is explained during the Rewired installation process in the UI prompt and also here. They are required because this is the only possible way to get joystick and mouse axes from Unity input in the case of platforms that Rewired does not have native input libraries for (Android, iOS, PS Vita, Tizen, etc.) or those that use Unity input partially (Xbox One, PS4) or any when native input is disabled or the primary input source is set to "Unity".

     
    Last edited: Dec 4, 2017
  7. Discmage

    Discmage

    Joined:
    Aug 11, 2014
    Posts:
    60
    Thank you for your quick and thorough answer! Everyone was right in that the support for this is excellent! :)

    I fixed the issue with the fact that I stupidly hadn't set Rewired as the actual input, as WASD and the controller were already working due to 'previous' Input parameters I thought everything was working through Rewired as I added new inputs until the Slide mechanic...so that is now sorted.

    I think as I was having issues with the unknown controller, THEN figured out the fact it existed and then moved to setting the xbox controller settings to make that work AFTER changing from the dual Analog Gamepad template in order to make it work at all...I will take it back to the Dual Analog Gamepad then see if I can force player0 to use the xbox controller (which I am currently doing by using controller[1] rather than [0] ) rather than the unknown in my particular case/testing.

    I'll have to unplug everything one by one one day to see what this mystery unknown device actually is :)

    Thanks again for your help! Can't wait to get my game working on EVERYTHING! :D
     
    guavaman likes this.
  8. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    Thanks and I'm glad it's resolved.

    You can use the Debug Information foldout to view the joysticks Rewired sees. Debug Information -> Controllers -> Joysticks. You can see the name being returned by the HID driver there under hardwareName. This may give you a clue about what the device is. Sometimes they're not even physical devices. Controller emulation software like VJoy, DS4Win, etc., often creates XInput or HID devices that stay present even when no controller is plugged in. These phantom devices won't ever return any inpput values, but there's no way Rewired can know that and filter them out.
     
  9. ratking

    ratking

    Joined:
    Feb 24, 2010
    Posts:
    350
    With the latest update I now get the following error whenever I press Play for the first time after loading the project. After that there is no error anymore.

    Screenshot_1.jpg

    The top line in the stack trace points to: "string deviceModel = SystemInfo.deviceModel ?? string.Empty;"
     
  10. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    What version of Unity are you using?
     
  11. ratking

    ratking

    Joined:
    Feb 24, 2010
    Posts:
    350
    Ah sorry. Unity 5.6.
     
  12. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    That stack trace seriously makes no sense. The way that looks, OnApplicationFocus is being triggered by the call to SystemInfo.deviceModel. OnApplicationFocus is a MonoBehaviour callback and is never called by anything in code and only by Unity itself when the application receives or loses focus. That would mean OnApplicationFocus is running before Awake finishes. I have never seen this before and cannot reproduce it. What operating system are you using?
     
  13. ratking

    ratking

    Joined:
    Feb 24, 2010
    Posts:
    350
    Windows 10. I didn't get the error anymore for a few hours, maybe the problem was elsewhere. I will report if it comes back.
     
  14. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    Then I can only guess that Unity has some kind of weird handling of OnApplicationFocus events, possibly dependent on a static constructor internally judging by the behavior of it getting called when SystemInfo.device model is called. There would appear to be no way to predict the order of this event, triggering the first OnApplicationFocus either before Awake, after Awake, or when various parts of the API are accessed like SystemInfo.deviceModel. Because I can't reproduce this, I'm going to consider the order of OnApplicationFocus calls unknowable and put in some kind of workaround code to deal with either scenario. There is no information in the execution order documentation or the OnApplicationFocus documentation that I can find that explains this behavior.
     
    Last edited: Dec 4, 2017
    ratking likes this.
  15. sailorsoft

    sailorsoft

    Joined:
    Oct 29, 2016
    Posts:
    4
    I have problem i have 3 scene

    1 menu Rewired is work ok
    2 loading scene
    3 racing scene Rewired controller Not work
    If run scene number 3 racing dirctly then Rewired is work ok
    But the problem come if run game from scene 1


    I try everything I checked and uncheck “don’t destroy on load “
    But no way to slove this problem
     
  16. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    This almost always happens because you have two different Rewired Input Manager configurations. Your first scene has one Rewired Input Manager and your 3rd scene has another.

    1. If your Rewired Input Manager is a prefab and the same prefab is used in both scenes, then you have modified the saved data one one prefab instance and not the other. Rewired shows an obvious warning in the inspector and in the editor window when you have a prefab instance selected and are making changes to that instance and not the parent prefab. Rewired Input Managers are GameObjects and therefore follow all the same rules all GameObjects follow. This includes the fact that data can be overridden in a prefab instance and that overridden data will not be present in other instances of that prefab. The solution is to get all your prefab instances in sync by applying the modifications to the parent prefab or reverting them depending on which one is the correct configuration. Go to each Rewired Input Manager, look at your configurations in the editor, and determine which is the correct one. Press "Apply" on the correct one and "Revert" on the others so they will go back to an unmodified state. From your description, it sounds like the Rewired Input Manager in the 3rd scene has the correct input configuration and 1st scene does not.

    prefab_apply.png

    2. If your Rewired Input Manager is not a prefab and you have a different GameObject in each scene, then these two Rewired Input Managers contain completely different data. Make a prefab out of the correct one, delete the other, and add a prefab instance in place of it.

    Prefabs documentation
     
    Last edited: Dec 6, 2017
  17. sailorsoft

    sailorsoft

    Joined:
    Oct 29, 2016
    Posts:
    4
    Still have problem i make new prevab it work on pc but on ps4 platform with same control not work same before problem
    Work on menu but not working on race scene

    Is there plugin need add it for make control run on ps4 it platform?
     
  18. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    There is no plugin for PS4.
    1. To use the PS4, make your map for the Dual Analog Gamepad Template.
    2. See this Troubleshooting topic that talks about a common problem on console platforms.
    3. Check the log for any useful information.
    4. If you are using Control Mapper or User Data Store, see this important note about saved XML data. If your saved data on PS4 was saved with invalid mappings, they will be loaded and override whatever you are defining in the Rewired Input Manager.
    5. Use the information on this Troubleshooting topic to see visually all the Rewired objects at runtime. You can determine what isn't working and why. Is a Joystick being detected? Is it assigned to your Player? Does your Player have any Joystick Maps for that joystick? Are they mapping elements to Actions? It will even show you the values of Actions for a Player in real-time.
    Are you using the Rewired Standalone Input Module? You say the Menu works, but it's a quite common problem when the normal Unity Standalone Input Module is being used, you think Rewired is working on menus and UI but you are actually not using Rewired at all because you are using the Standalone Input Module instead of the Rewired Standalone Input Module. Knowing this will help narrow down the issue.

    It could be any of the problems above, but it still sounds to me like you've got some problem with your prefab setup. If none of the above lead to anything useful:
    1. Verify your first scene's Rewired Input Manager has the right configuration in the Rewired Input Manager editor.
    2. Select that Rewired Input Manager in the main scene and press "Apply" in the inspector so the parent prefab on disk is updated to that configuration.
    3. Go to each of your other scenes, select the Rewired Input Manager, and press "Revert" to make them synchronize with the parent prefab.
    4. Whenever you edit the Rewired Input Manager settings, select the prefab in the Project pane instead of the instance in the Hierarchy pane.
     
    Last edited: Dec 7, 2017
  19. aeonphyxius

    aeonphyxius

    Joined:
    Jun 16, 2013
    Posts:
    13
    Hi @guavaman I am working on key bindings for a PC game and I have a doubt. Let me explain you our setup first.

    We have an action called Fire and another one called Switch. Lets say that in our keyboard mappings we have the following:
    Fire: Z
    Switch: X

    I have implemented a simple keybindings screen, following a bit your example "ControlRemappingDemo1", using the InputMapper class more or less as follows:
    Code (CSharp):
    1.  InputMapper inputMapper = new InputMapper();
    2.  
    3.             inputMapper.options.timeout = 5.0f;
    4.             inputMapper.options.allowAxes = false;
    5.             inputMapper.options.allowKeyboardKeysWithModifiers = false;
    6.             inputMapper.options.checkForConflictsWithSystemPlayer = true;
    7.             inputMapper.options.defaultActionWhenConflictFound = InputMapper.ConflictResponse.Replace;
    8.             inputMapper.ConflictFoundEvent += OnInputMapperConflictFoundEvent;
    9.             inputMapper.InputMappedEvent += OnNewKeyMapped;
    10.             inputMapper.TimedOutEvent += OnInputMapperTimedOutEvent;
    11.            
    12.             InputMapper.Context context = new InputMapper.Context()
    13.             {
    14.                 actionId = GetActionFromName(GetActionForPosition(selectedOption)).id,
    15.                 controllerMap = IOController.Instance.GetPCController().GetControllerMap()
    16.         };
    17.             inputMapper.Start(context);
    Lets say that I make this new mappings:

    Fire:A
    Switch:S

    Everything works fine, I can Fire using A and Switch using S. The odd thing is that I still can Fire using the original bindings, Fire:Z and Switch:X
    If I try to for example exchange the bindings (using Fire X and Switch Z), everything works like a charm (not double actions or anything).
    Is there something that I might be missing?
    As a side note, the InputMappedEvent callback, just does some visual things on my UI, and the defaultActionWhenConflictFound just checks if it is trying to use some forbidden keys, otherwise will
    _conflictFoundEvt.responseCallback(InputMapper.ConflictResponse.Replace);

    Any tips on what I might be doing wrong here?
     
  20. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    You are not replacing the existing binding, you are adding a new one because you are not setting the Context.actionElementMapToReplace property. Look at the code to SimpleControlRemapping.cs:

    Code (csharp):
    1. // Called by the input field UI Button when pressed
    2. private void OnInputFieldClicked(int index, int actionElementMapToReplaceId) {
    3.     if(index < 0 || index >= rows.Count) return; // index out of range
    4.     if(controller == null) return; // there is no Controller selected
    5.     // Begin listening for input
    6.     inputMapper.Start(
    7.         new InputMapper.Context() {
    8.             actionId = rows[index].action.id,
    9.             controllerMap = controllerMap,
    10.             actionRange = rows[index].actionRange,
    11.             actionElementMapToReplace = controllerMap.GetElementMap(actionElementMapToReplaceId)
    12.         }
    13.     );
    14.     statusUIText.text = "Listening...";
    15. }
    Line 11 shows replacing an existing mapping. If no actionElementMap is passed in, it will make a new binding because it has no idea which binding you want to replace.

    You can always see what's happening visually to your mappings using the Debug Information foldout in the Rewired Input Manager inspector. If you look at that, you'd see you have two mappings for each key. This should be the first thing you check when something weird starts happening. It can usually clue you in on the problem.
     
    Last edited: Dec 6, 2017
  21. aeonphyxius

    aeonphyxius

    Joined:
    Jun 16, 2013
    Posts:
    13
    Really, thank you !

    I have been going around this issue all day.

    It worked like a charm (probably after a while I got obfuscated with the problem, and its simple solution).

    Cheers
     
    guavaman likes this.
  22. TommiH

    TommiH

    Joined:
    Jan 14, 2008
    Posts:
    253
    Here's something I'd find very useful: "GetButtonDoublePressMissed" or something like that. That is, the button was pressed once and then the maximum double press delay was exceeded. Would make it easier to set up something to happen on single click and another thing on double click.
     
  23. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    Thanks for the suggestion! I'll think about this and try to determine if it would be good to add something like this or what other approaches might be appropriate.
     
  24. MrG

    MrG

    Joined:
    Oct 6, 2012
    Posts:
    368
    One would expect the distinction between single click and double click to be handled at the OS level. Put another way, in a high-level development environment, we shouldn't have to solve for this, it should be sent to us as OnClick / OnDoubleClick.
     
  25. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    The problem is, if you always have to check for a double click before handling a single click, you will get noticeable lag because you're waiting to see if a double click has occurred before sending a single click. The vast majority of Actions do not need double click detection, so ButtonDown is good enough with no lag. Only in the case where you want to check an Action for both a single and a double click and do something different in each case would you ever want to wait for the double click to expire before sending a single click. And consider this is not just for mouse buttons. A double press on a joystick, a keyboard key, an axis as a button, or any other virtual control also applies. And you can set your own individual timing for double clicks as well on a per-Action or per-call basis.

    Handling this with a new GetButtonSinglePress method/event might work. So if you want a lag-free version, use GetButtonDown. Only if you need to check for both single and double press would you use GetButtonSinglePress which would wait until the double press timeout expires before returning true and wouldn't return true if a double press does.
     
    Last edited: Dec 9, 2017
  26. room710games

    room710games

    Joined:
    Oct 3, 2017
    Posts:
    7
  27. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    No. Here's the array for the element identifiers, but normally you would use the KeyCode instead.

    Code (csharp):
    1. private static readonly string[] keyboardKeyNames = new string[] {
    2.     "None",
    3.     "A",
    4.     "B",
    5.     "C",
    6.     "D",
    7.     "E",
    8.     "F",
    9.     "G",
    10.     "H",
    11.     "I",
    12.     "J",
    13.     "K",
    14.     "L",
    15.     "M",
    16.     "N",
    17.     "O",
    18.     "P",
    19.     "Q",
    20.     "R",
    21.     "S",
    22.     "T",
    23.     "U",
    24.     "V",
    25.     "W",
    26.     "X",
    27.     "Y",
    28.     "Z",
    29.     "0",
    30.     "1",
    31.     "2",
    32.     "3",
    33.     "4",
    34.     "5",
    35.     "6",
    36.     "7",
    37.     "8",
    38.     "9",
    39.     "Keypad 0",
    40.     "Keypad 1",
    41.     "Keypad 2",
    42.     "Keypad 3",
    43.     "Keypad 4",
    44.     "Keypad 5",
    45.     "Keypad 6",
    46.     "Keypad 7",
    47.     "Keypad 8",
    48.     "Keypad 9",
    49.     "Keypad .",
    50.     "Keypad /",
    51.     "Keypad *",
    52.     "Keypad -",
    53.     "Keypad +",
    54.     "Keypad Enter",
    55.     "Keypad =",
    56.     "Space",
    57.     "Backspace",
    58.     "Tab",
    59.     "Clear",
    60.     "Return",
    61.     "Pause",
    62.     "ESC",
    63.     "!",
    64.     "\"",
    65.     "#",
    66.     "$",
    67.     "&",
    68.     "'",
    69.     "(",
    70.     ")",
    71.     "*",
    72.     "+",
    73.     ",",
    74.     "-",
    75.     ".",
    76.     "/",
    77.     ":",
    78.     ";",
    79.     "<",
    80.     "=",
    81.     ">",
    82.     "?",
    83.     "@",
    84.     "[",
    85.     "\\",
    86.     "]",
    87.     "^",
    88.     "_",
    89.     "Back Quote",
    90.     "Delete",
    91.     "Up Arrow",
    92.     "Down Arrow",
    93.     "Right Arrow",
    94.     "Left Arrow",
    95.     "Insert",
    96.     "Home",
    97.     "End",
    98.     "Page Up",
    99.     "Page Down",
    100.     "F1",
    101.     "F2",
    102.     "F3",
    103.     "F4",
    104.     "F5",
    105.     "F6",
    106.     "F7",
    107.     "F8",
    108.     "F9",
    109.     "F10",
    110.     "F11",
    111.     "F12",
    112.     "F13",
    113.     "F14",
    114.     "F15",
    115.     "Numlock",
    116.     "Caps Lock",
    117.     "Scroll Lock",
    118.     "Right Shift",
    119.     "Left Shift",
    120.     "Right Control",
    121.     "Left Control",
    122.     "Right Alt",
    123.     "Left Alt",
    124.     "Right Command",
    125.     "Left Command",
    126.     "Left Windows",
    127.     "Right Windows",
    128.     "AltGr",
    129.     "Help",
    130.     "Print",
    131.     "SysReq",
    132.     "Break",
    133.     "Menu"
    134. };
    There are a bunch of Playstation controllers for PS 2, 3, and 4. Look under Sony.
     
    Last edited: Dec 9, 2017
  28. room710games

    room710games

    Joined:
    Oct 3, 2017
    Posts:
    7
  29. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    Rewired 1.1.9.0 is now available for download to registered users. If you'd like to register for early access to updates, please contact me here. The Unity Asset Store will get the update as soon as they approve the submission.

    Please see Updating Rewired before updating.

    Release Notes:

    1.1.9.0:

    Changes:
    - Rewrote CustomControllersTouch example to use Unity UI instead of legacy GUI system in Unity 5+.
    - Added Bolt integration.

    API Changes:
    - Added Player.GetButtonDoublePressUp method.
    - Added Player.GetNegativeButtonDoublePressUp method.
    - Added Player.GetButtonSinglePressHold method.
    - Added Player.GetButtonSinglePressDown method.
    - Added Player.GetButtonSinglePressUp method.
    - Added Player.GetNegativeButtonSinglePressHold method.
    - Added Player.GetNegativeButtonSinglePressDown method.
    - Added Player.GetNegativeButtonSinglePressUp method.
    - Added InputActionEvent.ButtonDoublePressJustReleased enum value.
    - Added InputActionEvent.NegativeButtonDoublePressJustReleased enum value.
    - Added InputActionEvent.ButtonSinglePressed enum value.
    - Added InputActionEvent.ButtonJustSinglePressed enum value.
    - Added InputActionEvent.ButtonSinglePressJustReleased enum value.
    - Added InputActionEvent.NegativeButtonSinglePressed enum value.
    - Added InputActionEvent.NegativeButtonJustSinglePressed enum value.
    - Added InputActionEvent.NegativeButtonSinglePressJustReleased enum value.
    - Added InputActionEventData.GetButtonDoublePressUp method.
    - Added InputActionEventData.GetNegativeButtonDoublePressUp method.
    - Added InputActionEventData.GetButtonSinglePressHold method.
    - Added InputActionEventData.GetButtonSinglePressDown method.
    - Added InputActionEventData.GetButtonSinglePressUp method.
    - Added InputActionEventData.GetNegativeButtonSinglePressHold method.
    - Added InputActionEventData.GetNegativeButtonSinglePressDown method.
    - Added InputActionEventData.GetNegativeButtonSinglePressUp method.

    Bug Fixes:
    - Added workaround for intermittent null reference exception thrown due to inconsistent order of MonoBehaviour.OnApplicationFocused execution by Unity.
    - Fixed issue in Player.AddInputEventDelegate causing double press events with speed argument passed in to fail.
    - Fixed null reference exception thrown during runtime recompiling.

    New PlayMaker Actions:
    - RewiredPlayerGetButtonDoublePressUp
    - RewiredPlayerGetNegativeButtonDoublePressUp
    - RewiredPlayerGetButtonSinglePressHold
    - RewiredPlayerGetButtonSinglePressDown
    - RewiredPlayerGetButtonSinglePressUp
    - RewiredPlayerGetNegativeButtonSinglePressHold
    - RewiredPlayerGetNegativeButtonSinglePressDown
    - RewiredPlayerGetNegativeButtonSinglePressUp

    New Behavior Designer Actions:
    - RewiredPlayerGetButtonDoublePressUp
    - RewiredPlayerGetNegativeButtonDoublePressUp
    - RewiredPlayerGetButtonSinglePressHold
    - RewiredPlayerGetButtonSinglePressDown
    - RewiredPlayerGetButtonSinglePressUp
    - RewiredPlayerGetNegativeButtonSinglePressHold
    - RewiredPlayerGetNegativeButtonSinglePressDown
    - RewiredPlayerGetNegativeButtonSinglePressUp
     
    Last edited: Dec 14, 2017
  30. Givago

    Givago

    Joined:
    Oct 22, 2015
    Posts:
    27
    I am making a menu, where you will have the Inputs options, however there may be a keyboard with joystick or just a joystick, however the keyboard is always considered active and as the player 1.

    My idea is to do a keyboard check?

    if anyone has a better idea, I accept suggestions.
     
  31. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    I don't understand what you are asking. Can you please clarify your scenario?
     
  32. facundogalella

    facundogalella

    Joined:
    Mar 5, 2016
    Posts:
    59
  33. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    Sandcastle has always been a problem. It never exports everything. I would change to another system but that would break every link to the API reference. I managed to get them to export.

    You can always see the inline documentation in MonoDevelop or Visual Studo by typing the class and member.
     
    facundogalella likes this.
  34. Givago

    Givago

    Joined:
    Oct 22, 2015
    Posts:
    27
    I want to have a keyboard controller too, is there a method to verify this?
     
  35. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    I am sorry but I simply do not understand what you are asking. You are going to have to provide more detail as to exactly what you are trying to achieve. Explain it as clearly as you can and in as much detail as you can.

    The Keyboard is explained in the documentation here:
    http://guavaman.com/projects/rewired/docs/Controllers.html#keyboard

    If I were to guess what you are trying to do, I would say it is this:

    1. You want the Keyboard to be treated as if it is a Joystick.
    2. You don't want the same Player that has access to the Keyboard to have access also to a Joystick.
    3. You want Joysticks to be assigned to other Players but not the one that is assigned the Keyboard.

    This control scheme is not automatically supported by Rewired. Keyboard is not a Joystick and is not treated the same as a Joystick. The Keyboard is not auto-assigned. A Player having access to the Keyboard has no effect on whether or not Joysticks will be assigned to that Player.

    If you want to treat the Keyboard as if it's a Joystick, you have to manage the assignment of Joysticks and Keyboard Maps.

    1. Assign the Keyboard to some Player: http://guavaman.com/projects/rewired/docs/HowTos.html#assigning-controllers
    2. Assign the appropriate Keyboard maps to that Player in the Rewired Input Manager -> Players page.
    3. Exclude that Player from Joystick Auto-Assignment: http://guavaman.com/projects/rewired/docs/HowTos.html#excluding-players-from-joystick-assignment
     
  36. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
  37. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    Last edited: Dec 14, 2017
  38. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    Yes. I forgot to add it to the release notes.
     
  39. Mormel

    Mormel

    Joined:
    Jan 15, 2015
    Posts:
    6
    Hi,
    I am a little confused. Is there a reason for my 8Bitdo gamepad not defaulting to the Dual Analog Template mapping? I realize that these controllers dont have Analog Sticks and are missing some shoulder buttons, but it would be nice to use some sort of template to configure them. Basically the controller only works if a make a specific mapping in "8Bitdo SNES30/SFC30".
    Also, if there is a particular reason behind doing this, which other gamepads do I also have to map manually?
    My other controllers all work flawlessly. Thank you for your work.
     
  40. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    The 8Bitdo gamepads are all compatible with the Dual Analog Gamepad Template. Every single gamepad listed on this page is: http://guavaman.com/projects/rewired/docs/SupportedControllers.html

    If you have created an individual mapping for the 8Bitdo gamepad, it will override a mapping for the Dual Analog Gamepad Template. Delete the individual mapping. If you have multiple mappings in different Map Categories / Layouts, delete all of them for the individual 8Bitdo gamepad because if it tries to load a mapping for that pad and finds one for the individual controller in that Map Category and Layout, it will use that instead even if it has no bindings.

    Edit: I just retested all connection modes on the SNES 30 and they are all recognized and all use the Dual Analog Gamepad Template. Testing on Windows.

    Edit 2: I just updated it to the final 4.01 firmware and all supported modes still work.
     
    Last edited: Dec 14, 2017
  41. Mormel

    Mormel

    Joined:
    Jan 15, 2015
    Posts:
    6
    Thank you for the quick reply.
    I have checked for all these things, but the problem persists.
    Maybe it's a Linux Unity problem. I'll check tomorrow if it works under Windows for some reason.
     
  42. Mormel

    Mormel

    Joined:
    Jan 15, 2015
    Posts:
    6
    Ah okay, I found the issue. The DPad of the 8Bitdo does not get mapped on the DPad of the Dual Analog, but on its Left Stick.
    I understand that this was probably done for compatibility reasons.
    Since I only use DPads in my game, I will probably map them by hand.
    Thank you for your helpfulness
     
  43. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    I see. Yes, the D-Pad is mapped to Left Stick because the left stick is used for movement on the vast majority of gamepads. Without a stick on the gamepad, the D-Pad takes on the role of movement.
     
  44. Cleverlie

    Cleverlie

    Joined:
    Dec 23, 2013
    Posts:
    219
    hi @guavaman , I'm currently struggling with save load of keyboard mappings:

    the UserDataStore player prefs implementation works fine, but I wanted to make a simplified version of this.

    I only need to save changed mappings into the keyboard controller of player 0 only, my game is pretty simple in that we don't have emore than one player and the editable bindings are only for keyboard (we don't even use joysticks, we only use rewired for keyboard and mouse).

    UserDataStore is a bit of an overkill for our scenario, nonetheless it works, the problem comes when I try to understand how the playerprefs implementation works since I need to do my own implementation to save the data in a custom text file instead of the registry, and I need to save the data in a per player profile basis, this means we don't have multiple players, we don't use other player than Player 0, but we do have player profiles, which when the user loads one, the system loads all the player saved data, including custom settings, keyboard mappings etc.

    so what I need to do is to create an implementation of UserDataStore that only stores keyboard modified mappings of player 0 since I don't want to fill the save file with unneeded info about other controllers and/or players.

    the problem is that I'm having a hard time understanding how the playerprefs implementation works (1200+ lines of code) and I'm not sure what I might be doing wrong or fine, if only I could do something like

    Code (CSharp):
    1. Rewired.ReInput.controllers.Keyboard.GetMappingDeltasInXML()
    or something similar that gives me whatever I need to save in a file, to later load and override the default mappings again the next time the player loads his own profile.
    I tried implementing my own class but there is something, some dependency, some step that I'm missing, because it's not working.


    for now I'm just using the UserDataStore_PlayerPrefs and doing Save() and Load() at custom points in the game through scripting, it works fine, but I'm lacking the power of saving this to a custom file for each custom player profile (and later save the custom bindings to steam cloud for example in a per player profile basis).

    also I have another important problem, I have no way to restore everything to default.
    Imagine a button in the "Input Settings" menu that says "restore all keys to default", when you click it the code should do something like UserDataStore.RestoreToDefault() which erases any custom mappings and goes back to the clean keyboard mappings defaults, is there any way to achieve this?

    TL;DR
    so to summarize I'm asking if you can make a tutorial or provide a simplified version of UserDataStore that stores to a custom file, secondly I'm asking if you can implement a function such as UserDataStore.RestoreToDefault().

    thanks in advance.
     
  45. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    The problem is, what you want to save with UserDataStore is not the same as what someone else may want to save with UserDataStore. Also, where and how you want to save this data and even the keying of it isn't the same for your case vs other cases. Just like you mention, you only want to save Keyboard maps for a single Player and you have very specific needs, the system cannot be designed for every possible use case. The source code was given and an interface used for the express purpose of allowing you to customize the system exactly how you want for your specific use-case.

    Essentially, what you are asking me to do is to create for you a special implementation of UserDataStore specifically for your needs. This just isn't feasible for me to do custom implementations for customers. It would take an inordinate amount of time for me to do this for everyone that needs a custom implementation.

    Your specific implementation needs:
    1. Save/Load to text files.
    2. Save data on a player-profile basis.
    3. Only save keyboard map deltas.
    4. Ignore Joystick and Mouse mappings and assignments.
    These are all very specific to your individual needs.

    UserDataStore_PlayerPrefs code is neatly organized into regions of related content:
    1. UserDataStore Implmentation - Public implementation
    2. Load - Deals with loading data
    3. Save - Deals with saving data
    4. PlayerPrefs Methods - Deals with reading/writing that data to PlayerPrefs
    5. Misc - Helper functions
    6. Classes - Helper classes
    Each of these sections contains methods that relate to those purposes. If you go piece by piece, you should be able to understand it if you take some time to look through it.

    For example, you want to read and write from a text file. Change all the code in "PlayerPrefs Method" to use your own method for storing the data to a text file and retrieving the data from that text file.

    Player profiles do not exist as a concept in Rewired. To do this, you would make some player profile id part of the data key when saving/loading the data. Things like this are exactly the reason UserDataStore was made as an interface which you could implement yourself. Your needs are so specific and different than the most common use case that you require a totally custom implementation of UserDataStore.

    Every single place in the code that iterates the player list (for i = 0; i < ReInput.players.playerCount...) just needs to be changed to instead only process Player 0 instead. Remove the for loops. There are only like 3 or 4 of them in the file.

    All code that saves/loads Joystick or Mouse data just needs to be deleted and code that saves/loads Keyboard data left as is.

    The Rewired API already does almost everything you want it to. You just have to find the functions you need.
    1. The Player is in charge of storing Controller Maps.
    2. All Mapping functions are in Player.ControllerHelper.MappingHelper (player.controllers.maps):
    3. The function you want is Player.controllers.maps.LoadDefaultMaps
    4. This is listed in the How To's - Managing Controller Maps at Runtime
    Restoring default controls is also shown in the Control Mapper source code:

    Code (csharp):
    1. IList<Player> players = ReInput.players.Players;
    2. for(int i = 0; i < players.Count; i++) {
    3.     Player player = players[i];
    4.     if(_showControllers) player.controllers.maps.LoadDefaultMaps(ControllerType.Joystick);
    5.     if(_showKeyboard) player.controllers.maps.LoadDefaultMaps(ControllerType.Keyboard);
    6.     if(_showMouse) player.controllers.maps.LoadDefaultMaps(ControllerType.Mouse);
    7. }
    UserDataStore is not used for loading developer-defined data from the Rewired Input Manager. UserDataStore is only concerned with saved user-defined XML data.

    I'm not understanding what you are trying to achieve, but there are multiple things wrong with this:
    1. Controller Maps are a function of Players in Rewired, not the Controller. The entire mapping system is a Player-Action mapping system where the Player owns the Controller Maps. The maps are used to link Controller elements to Actions in the Player. ReInput.controllers.Keyboard has no knowledge of Controller Maps in any way.
    2. I don't understand what you mean by "Mapping Delta." A change in mapping in relation to what? The difference in the current Controller Map vs the default defined Controller Map in that Category/Layout in the Rewired Input Manager?
    3. Saving/Loading some kind of binding delta would be a fundamental change to how the entire Controller Map system works. When XML data is output for a Controller Map, it is a dump to XML of the current Controller Map state including the bindings. The entire state is saved to an XML string. When you load it, the entire Controller Map is replaced with the bindings loaded from XML. Trying to do something that saves/loads only deltas vs some undefined default would be a huge change and would affect every saving/loading function in Player, Controller Map, ControllerMapSaveData, and other related classes.
    Saving keyboard maps for a Player is as simple as:
    Code (csharp):
    1. ControllerMapSaveData[] saveData = player.controllers.maps.GetAllMapSaveData(ControllerType.Keyboard, false);
    2. foreach(var data in saveData) {
    3.     SaveMap(data);
    4. }
    5.  
    6. private void SaveMap(ControllerMapSaveData data) {
    7.    string xml = data.map.ToXMLString();
    8.    // use your player profile id as a key to save the xml string
    9.    // use the other properties on ControllerMapData to organize this data in your storage system
    10. }
    11.  
    This is all illustrated in the code to UserDataStore_PlayerPrefs.

    The attached file is UserDataStore_PlayerPrefs where I went through all the methods and stripped out everything you're not using for your specific use case: Controller assignment saving/loading, all Joystick data saving/loading, all Mouse saving loading, using Player 0 instead of iterating through the Players, and Input Behaviors.

    There is little difference between this file and the original UserDataStore_PlayerPrefs except for the removal of the parts you are not using.

    Most of the PlayerPrefs code was removed except some was left behind so you could modify it to use whatever type of text file data storage system you have in mind.

    Any further replies will be delayed due to holiday travel.
     

    Attached Files:

    Last edited: Dec 19, 2017
    Cleverlie likes this.
  46. ninuxw

    ninuxw

    Joined:
    Jul 8, 2014
    Posts:
    26
    Hi i @guavaman I got a quick question. I am about to purchase your asset but I need to know something. I am developing a roguelike and I am in need of support for ">" and "<" key bindings. Now these would need to work also if a player has to hit Shift + [whatever key needed for his keyboard to do a ">"]. Is this something possible?

    Thanks in advance!
     
  47. Cleverlie

    Cleverlie

    Joined:
    Dec 23, 2013
    Posts:
    219
    hi, thanks for the time you took in answering and making the .cs file, I think I will investigate how to use this:


    Code (CSharp):
    1. ControllerMapSaveData[] saveData = player.controllers.maps.GetAllMapSaveData(ControllerType.Keyboard, false);
    2. foreach(var data in saveData) {
    3.     SaveMap(data);
    4. }
    5. private void SaveMap(ControllerMapSaveData data) {
    6.    string xml = data.map.ToXMLString();
    7.    // use your player profile id as a key to save the xml string
    8.    // use the other properties on ControllerMapData to organize this data in your storage system
    9. }
    and what is the inverse process (load the controller maps at runtime from the files created).

    so yes, my idea was to get the most basic function that saves the controller map data and put that into a file called <profileName>_controlMaps.xml and then later do something like
    Code (CSharp):
    1.  
    2. ReInput.GetPlayer(0).maps.LoadAndReplace(GetXmlFromFile(string nameOfFile : currentPlayerProfile.Name + "_controlMaps.xml"));


    I know that line of code is over simplified but that is the basic functionality I want, probably I need to extract and use a subset of the functions of UserDataStore_PlayerPrefs but instead of saving to playerprefs return a string so I can save it in a text file wherever I want.

    I'll let you know if I have more advances on this, thanks again!
     
  48. bonkersdeluxe

    bonkersdeluxe

    Joined:
    Sep 13, 2013
    Posts:
    3
    Hi, i create a splitscreen game. For textfields i create an osd keyboard, when my game was played with joypads / gamepads. This works fine. If two keyboards connected i will prefer to use the keyboard for easier input as osdkeyboard. How can i send all buttons as text to the textfield in an extra category like inputfield.
    eg : schift + a = big A. So that i can create a chatbox. The splitscrean game will be able for multiplayer over the network.
    Both player should indepent write text with their keyboards, of course when two keyboards connected.
    In short, how can i save text from keyboard to save it in a string?
    Sorry for my bad english.
    Thank you!
     
  49. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    This was answered via email support.
     
  50. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    1. Rewired does not support multiple independent keyboards on any plataform. See the FAQ.
    2. The only way you can read character values is by checking the values directly from the Keyboard controller:
    Code (csharp):
    1. if(ReInput.controllers.Keyboard.GetKey(KeyCode.A)) {
    2.     // Do something
    3. }
     
    Last edited: Dec 29, 2017