Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

[Free] Custom Input Manager

Discussion in 'Assets and Asset Store' started by daemon3000, Jan 18, 2014.

  1. punsho

    punsho

    Joined:
    Nov 24, 2015
    Posts:
    4
    ok, it works, shouldn't there be a tutorial for this? Maybe in the README file?
     
  2. daemon3000

    daemon3000

    Joined:
    Aug 13, 2012
    Posts:
    134
    Normally you should get a dialog box with something like "In order to use the InputManager plugin you need to overwrite your project's input settings." when you open the project(or when you import the plugin in a new project). Don't know why you didn't get that. I'll look into it.
     
  3. punsho

    punsho

    Joined:
    Nov 24, 2015
    Posts:
    4
    Hello, I've encountered a problem InputManager.Load() and save(), in the editor I can perfectly save and load files but when the project has been built and launched these scripts stop working. How can I resolve this? The xml files are saved in the assets folder
     
    Last edited: Nov 27, 2018
  4. daemon3000

    daemon3000

    Joined:
    Aug 13, 2012
    Posts:
    134
    I made a build with the controls menu example from the plugin project and it worked. Can you make a test project where the issue can be replicated and send it to me?
     
  5. punsho

    punsho

    Joined:
    Nov 24, 2015
    Posts:
    4
    I have updated the input manager and reworked code from the example to fit into my project, everything works now, I was mislead by my own implementation of the code because it worked flawlessly in the editor. This is a really great project and a huge timesaver for me. I will be using it in the future projects as well. It's a shame that unity doesn't allow to change inputs in runtime, seems like this feature should be a available in all modern game engines
     
  6. Penj

    Penj

    Joined:
    Jul 21, 2015
    Posts:
    1
    Easy to implement!?? How!? I downloaded a giant project that doesn't build, contains no libraries, and have no idea how to include this in my project. Anybody else have implementation issues/questions, or is everyone a genius except me? ... I'm not a super genius.... or are I? _Homer Simpson.
     
  7. daemon3000

    daemon3000

    Joined:
    Aug 13, 2012
    Posts:
    134
  8. ApocFI

    ApocFI

    Joined:
    May 26, 2017
    Posts:
    33
    So, after setting this up, how do I display contextual key configurations as a text? Example:
    I have configured a customizable button ( or Action) called "Pick Item". I want to display the configured key at certain situations, for example like this (textoToDisplay being the configured key for "Pick Item" as a string):
    Code (CSharp):
    1.     private void OnTriggerEnter(Collider other)
    2.     {
    3.  
    4.         textField.text = "Press " +textToDisplay " to pick up this item";
    5.     }
     
  9. daemon3000

    daemon3000

    Joined:
    Aug 13, 2012
    Posts:
    134
    You need to get a reference to the InputAction and then show the appropriate binding depending on your specific setup.

    Code (CSharp):
    1. private void OnTriggerEnter(Collider other)
    2. {
    3.     InputAction inputAction = InputManager.GetAction("MyControlScheme", "MyAction");
    4.    
    5.     //    The binding index depends on how you have the controls set up, what input device the player is using, etc.
    6.     int bindingIndex = 0;
    7.    
    8.     //    This works if the binding type is "Button"
    9.     string keyName = inputAction.Bindings[bindingIndex].Positive.ToString();
    10.     //    This works if the binding type is "GamepadButton"
    11.     string gamepadButtonName = inputAction.Bindings[bindingIndex].GamepadButton.ToString();
    12.    
    13.     textField.text = "Press " + keyName + " to pick up this item";
    14.     //    or
    15.     textField.text = "Press " + gamepadButtonName + " to pick up this item";
    16. }
    You should use a Dictionary object or some kind of similar setup to associate the values from the binding to user friendly strings. It won't make much sense to the player if you show something like "Press Alpha1 to select shotgun." instead of "Press 1 to select shotgun." or "Press ActionBottom to jump." instead of "Press A to jump.".
     
    ApocFI likes this.
  10. Vermilingus

    Vermilingus

    Joined:
    Nov 20, 2017
    Posts:
    2
    Hey, the gamepad input works fine but I'm trying to make a drop in/drop out system and it seems I can't make it add or remove gamepads on the fly.

    It works if I set the gamepad as a default, however if I try to set the control scheme during runtime it doesn't detect it.
     
    Last edited: Apr 11, 2019
  11. daemon3000

    daemon3000

    Joined:
    Aug 13, 2012
    Posts:
    134
    Can you make a simple test project where I can replicate the issue?
     
  12. _Exerion

    _Exerion

    Joined:
    Dec 3, 2014
    Posts:
    7
    The project is great and useful, and there is a lot of effort put in, but (I'm sorry to say that) the documentation is scarce. You need to study the examples or the source code itself to get things going. But there are some cases not covered by examples and some things not entirely clear.

    Let's say we want to build a game with various kinds of controls. To simplify the matter, let's say it's Windows only game with support for keyboard+mouse, Xbox360 gamepad and PS4 gamepad. Keyboard+mouse is straightforward, no problems with that.
    To support gamepads, we need to add IGamepadStateAdapter component to InputManager gameobject. We have three variants of components implementing this interface: XInput, UWP and Generic.

    XInput is Windows-only which is fine for this example, but it supports only Xbox gamepads, if I got it right from the docs.
    UWP adapter is for Windows Store of Xbox Store which is not our case.
    So we are left with the only option - GenericGamepadStateAdapter. To make it work, we need to assign a gamepad profile. So there is the first question: how do we detect the type of gamepad connected to automaticaly assign a corresponding profile? If there something like this:
    Code (CSharp):
    1. if(GenericGamepadStateAdapter.GamepadType == GamepadType.Xbox360){
    2.     // do your stuff
    3. }
    it will be awesome, but the examples do not cover that part. Is there a code for detecting the type of gamepad, and if there are none, how do we do that? We want our player to be able to use whatever type of gamepad is connected straight from the moment of game start, without any settings, the same way it works in other games with a gamepad support.

    Another small thing which is not clear: what is the difference between Analog Axis and Gamepad Axis types of binding? Which one should we use? What gives?
    What is the difference between Analog Button, Gamepad Button and Gamepad Analog Button?
     
  13. daemon3000

    daemon3000

    Joined:
    Aug 13, 2012
    Posts:
    134
    The XInput adapter is not just for Xbox controller. It works with any XInput compatible controller(e.g. steam controller, logitech controllers). If the player doesn't have a compatible controller they can use an emulator like this one https://www.x360ce.com/ so you can practically support any controller with the XInput adapter.

    The only option you have to detect controllers is to use UnityEngine.Input.GetJoystickNames() and check the names. I have no way of knowing what these names are unless I buy the controllers and check the names so giving you a GamepadType enum or auto-selecting profiles is not an option. This is something you'll have to figure out. Make a list of controllers you want to support, find out what names they have, create the profiles and, at runtime, get the joystick names and assign the correct profile.

    Code (CSharp):
    1. void Start()
    2. {
    3.     string joystickName = InputManager.GetJoystickNames()[0];
    4.    
    5.     //    myProfileList is a List<GamepadProfile> that you configure in the inspector
    6.     GamepadProfile profile = myProfileList.Find(item => item.Name == joystickName) ?? myProfileList[0];
    7.    
    8.     GenericGamepadStateAdapter adapter = GamepadState.Adapter as GenericGamepadStateAdapter;
    9.     adapter.Profile = profile;
    10. }
    Button - Generic button(keyboard or joystick) that gets its value directly from Unity's input system.
    AnalogAxis - Generic joystick axis that gets its value directly from Unity's input system.
    AnalogButton - Similar to AnalogAxis but converts the axis to button input. If value >= 0.9(I think) the button is considered pressed. Allows you to use the triggers as buttons instead of axes for example.

    GamepadButton - A button from the standardized gamepad layout that gets its value from a gamepad adapter.
    GamepadAxis - An axis from the standardized gamepad layout that gets its value from a gamepad adapter.
    GamepadAnalogButton - Similar to GamepadAxis but converts the axis to button input. If value >= 0.9(I think) the button is considered pressed. Allows you to use the triggers as buttons instead of axes for example.

    If you're using a gamepad adapter use GamepadButton, GamepadAxis, GamepadAnalogButton else use Button, AnalogAxis, AnalogButton.
     
    _Exerion likes this.
  14. _Exerion

    _Exerion

    Joined:
    Dec 3, 2014
    Posts:
    7
    First, thank you for your reply and your effort.
    Yeah, I had a suspicion that XInput can support more than just Xbox controller. What put me off is this page which specifically says:
    So, rounding it up: we need to use XInput as and Adapter and GamepadButton or GamepadAxis as binding types, right?
    But how it works? If I understand correctly, different gamepads have different button and axis keycodes. In case of Generic Adapter we need to select a Gamepad Profile in order to map specific buttons to appropriate keycodes, but in case of XInput Adapter we don't need to do so - why? Is it standartized?
     
  15. daemon3000

    daemon3000

    Joined:
    Aug 13, 2012
    Posts:
    134
    The XInput adapter doesn't need gamepad profiles because it doesn't use Unity's input system. It gets the input directly through the DirectX API using this library https://github.com/speps/XInputDotNet . However only some controllers work with this API. For those that don't the player needs to use an emulator or you need to use the generic adapter and make profiles for those controllers.

    The Playstation 4 controller won't work with the XInput adapter because it's not compatible. Players will have to use a program to emulate an Xbox 360 controller like this one http://ds4windows.com/ or the one I linked in the previous message or you can use the generic adapter with a Playstation 4 controller profile.
     
    _Exerion likes this.
  16. _Exerion

    _Exerion

    Joined:
    Dec 3, 2014
    Posts:
    7
    Now I see, thank you!

    All this zoo of controllers isn't the easiest thing to manage.
     
  17. jam54

    jam54

    Joined:
    Feb 5, 2017
    Posts:
    2
    So first of all, a big thank you for putting so much time and effort in this inputmanager.
    And sorry if I am doing something stupid or if I am missing out on something.
    But when I create my own control scheme, and hit play, it just uses the default scheme in playmode.
    Or when I add new actions to the default scheme. And then start playing the scene, it just uses the default scheme without the actions I added.
    But when I stop playing the scene, the inputmanager shows my own scheme and actions again.
    It's just when I start playing it uses the default scheme instead of the one I defined and I don't know why.
    Here is also a video to make it more clear.

    @daemon3000
     
  18. daemon3000

    daemon3000

    Joined:
    Aug 13, 2012
    Posts:
    134
    It most likely happens because you have a load script in there and it overwrites your inputs with an older version when you play the scene. Did you use the save/load scripts from the example scene?

    The save file is in Application.persistentDataPath if you used the example scripts. You need to delete it.
     
  19. jam54

    jam54

    Joined:
    Feb 5, 2017
    Posts:
    2
    Alright that fixed the problem for me! Thank you very much!
     
  20. ApocFI

    ApocFI

    Joined:
    May 26, 2017
    Posts:
    33
    I'm having problems implementing local multiplayer with controller support for my top down game. I have created two input schemes and attached the generic gamepad adapter to input manager object, and chosen the default PS4 as the gamepad profile in the adapter script. The player movement script has a player ID field, and the player is moved with:
    Code (CSharp):
    1.         float h = InputManager.GetAxis("Horizontal", m_playerID);
    2.         float v = InputManager.GetAxis("Vertical", m_playerID);
    If I assign the controller inputs to default profile, it works, but if I set them to player two the input axes won't work - No input received in float h or v. But if I assign a button for player two profile it works, code:
    Code (CSharp):
    1. InputManager.GetButtonDown("Roll",m_playerID)
    Any ideas what causes this? I'm using a PS4 controller (naturally), and I've tested that all the inputs work in the generic gamepad sample scene.
     
  21. daemon3000

    daemon3000

    Joined:
    Aug 13, 2012
    Posts:
    134
    Export the control scheme(form the Input Editor go to the File menu and select Export) and send it to me together with a screenshot of the gamepad adapter component.
     
  22. ApocFI

    ApocFI

    Joined:
    May 26, 2017
    Posts:
    33
    Thanks for helping out. After further inspection I discovered that the gamepad axes scales were set to 0. Setting this to 1 fixed "the issue" =)
     
  23. luxoid

    luxoid

    Joined:
    Dec 16, 2015
    Posts:
    9
    Hello!

    First of all thank you for this awesome input manager. It worked like a charm for first try but I have an issue actually...
    I have recently updated Unity from 5.6.2f1 to 2019.1.9f1 and since then inputs fail to load with an error message:
    "FormatException: Input string was not in a correct format.
    System.Number.ParseSingle (System.String value, System.Globalization.NumberStyles options, System.Globalization.NumberFormatInfo numfmt) (at <7d97106330684add86d080ecf65bfe69>:0)
    System.Single.Parse (System.String s, System.Globalization.NumberStyles style, System.Globalization.NumberFormatInfo info) (at <7d97106330684add86d080ecf65bfe69>:0)
    System.Single.Parse (System.String s, System.Globalization.NumberStyles style, System.IFormatProvider provider) (at <7d97106330684add86d080ecf65bfe69>:0)
    etc"

    I think this is because the newer Unity is using .NET4.0. Can you please help in which file shall I add "
    CultureInfo.InvariantCulture" parameter for the parsing function? If it is the reason of the problem of course... (I have found an article about these parsing errors with .NET4)

    Many thanks in advance!
     
  24. daemon3000

    daemon3000

    Joined:
    Aug 13, 2012
    Posts:
    134
    Can you upload the input file that fails to load so I can run some tests?
     
    luxoid likes this.
  25. luxoid

    luxoid

    Joined:
    Dec 16, 2015
    Posts:
    9

    Attached Files:

  26. daemon3000

    daemon3000

    Joined:
    Aug 13, 2012
    Posts:
    134
    Are you sure it's the plugin throwing the error? It works for me when I import the file(it uses the same loader as runtime loading so it shouldn't matter). See if you can load this file: https://pastebin.com/KQtLGMbE

    Are you using the newest version of the plugin from Github? Download the project from Github and try it there see if you get the same error.

     
  27. daemon3000

    daemon3000

    Joined:
    Aug 13, 2012
    Posts:
    134
    The plugin parses floats in only two place, here and here. You should place breakpoints there and see if it throws an exception and if it does look at the content of the XML node, maybe there's something wrong with it that can explain the issue.
     
  28. luxoid

    luxoid

    Joined:
    Dec 16, 2015
    Posts:
    9
    "An axis named 'Yaw' does not exist in the active input configuration for player One"

    Inputs are vanishing in Input Editor when trying to load the XML file you have sent but they are visible when loading the generated input config xml just the same parsing error is displayed.

    Anyway I am not using the latest version I think of your Custom Input Manager so I'll try to download and update. I will return with the results in a bit.
    upload_2019-8-1_11-4-14.png
     
  29. luxoid

    luxoid

    Joined:
    Dec 16, 2015
    Posts:
    9
    Sorry for bothering you again with these but it looks like the latest version uses different namespaces and functions...
    For example StartJoystickAxisScan function is not working, InputConfiguration, AxisConfiguration namespaces could not be found, etc..
    I have replaced TeamUtility.IO to Luminosity.IO and PlayerID, InputManager namespaces are working again.
    Can you please tell me what shall I add instead of the listed elements?
    upload_2019-8-1_11-46-51.png
     
  30. daemon3000

    daemon3000

    Joined:
    Aug 13, 2012
    Posts:
    134
    Looks like you were using a very old version(almost 2 years old). I completely changed the way things work. Not sure if it will be practical for you to update. I still have a "legacy" branch on github with the old version. I can add the parse fix on that branch if you don't want to completely redo your input code. If you still want to update you can start with these changes:
    • "InputConfiguration" is now "ControlScheme"
    • "AxisConfiguration" is now "InputAction". "InputAction" contains a list of "InputBinding" which are equivalent to the old "AxisConfiguration"
    • "InputManager.GetAxisConfiguration" is now "InputManager.GetAction"
    • "InputManager.StartJoystickAxisScan" is now "InputManager.StartInputScan"
     
  31. luxoid

    luxoid

    Joined:
    Dec 16, 2015
    Posts:
    9
    Yes I haven't updated since years but I am updating the whole project now which I began 5 years ago so I am facing with some troubles already haha :)
    Luckily it is almost ready and working nicely except a few parts including the Input Manager.
    Thanks a lot for helping, even by making the legacy version compatible. I will try to use the updated Input Manager for now. I will return to you with the results. The old version did the trick as well but better to be up to date if possible.
     
  32. luxoid

    luxoid

    Joined:
    Dec 16, 2015
    Posts:
    9
    Well I think I see what you meant by maybe won't be practical to update.. After replacing the namespaces and functions the arguments differ a lot which may lead into dreamless nights and many of related scripts are throwing bunch of errors... If it is not a problem to you then please help me with parsing fix then I will update the Input Manager later when I have more time to fix things.
    Thanks a lot!

    In return for your kindness and help can I add you to the Credits of Real Drone Simulator?
     
    Last edited: Aug 1, 2019
  33. daemon3000

    daemon3000

    Joined:
    Aug 13, 2012
    Posts:
    134
    I updated the legacy branch. You'll most likely need to delete the saved input file first since it was probably written with the wrong culture info. And sure you can add me to the credits if you want to.
     
    luxoid likes this.
  34. luxoid

    luxoid

    Joined:
    Dec 16, 2015
    Posts:
    9
    Wow that was super fast! Thanks a lot for your help.
    I'll check it soon.
    I will add you to credits. Would you like to use daemon3000 or full name? If full name then please contact me on facebook as I have added my FB details to Unity forum profile. Thanks!

    I will return once I could test the legacy branch.
     
  35. luxoid

    luxoid

    Joined:
    Dec 16, 2015
    Posts:
    9
    Sorry for the late reply!
    The updated legacy branch is working like a charm without the need of modifying anything on the project. Just imported the new package, updated old files and it saves / loads the inputs properly without any errors or warnings.
    Thanks a lot for you help and efforts!
    I can finally continue upgrading the pending 4 scenes and to release an update soon.
     
  36. Gillissie

    Gillissie

    Joined:
    May 16, 2011
    Posts:
    95
    Thanks for giving away this free library. I just installed the library in my project that's in 2018.4.6f1, and ran the example_1 scene. I'm getting spammed with errors:
    ArgumentException: Input Axis mouse_axis_0 is not setup.
    ArgumentException: Input Axis mouse_axis_1 is not setup.

    The full stack is:

    Luminosity.IO.InputBinding.GetAxis () (at Assets/InputManager/Source/Runtime/InputBinding.cs:362)
    Luminosity.IO.InputAction.GetAxis () (at Assets/InputManager/Source/Runtime/InputAction.cs:111)
    Luminosity.IO.InputManager.GetAxis (System.String name, Luminosity.IO.PlayerID playerID) (at Assets/InputManager/Source/Runtime/InputManager_Unity.cs:82)
    Luminosity.IO.Examples.MouseLook.Update () (at Assets/InputManager/Examples/Common/Packages/FirstPersonController/Sources/Scripts/MouseLook.cs:46)

    I'm not sure what this means or how to fix it.
    Thanks.
     
  37. Gillissie

    Gillissie

    Joined:
    May 16, 2011
    Posts:
    95
    Update: I realized that this was because I hadn't yet set up the control scheme that it was expecting.
     
  38. Gil8ert

    Gil8ert

    Joined:
    May 17, 2017
    Posts:
    3
    Hey chaps, I recently installed this into a project and it’s all good but I’ve hit a snag.
    On a canvas ui button, the onclick() method no longer works. How do I fix this?
     
  39. daemon3000

    daemon3000

    Joined:
    Aug 13, 2012
    Posts:
    134
  40. Gil8ert

    Gil8ert

    Joined:
    May 17, 2017
    Posts:
    3
    Thanks for the response daemon3000!

    If I try to do that, I get an error message saying 'Unable to find any built-in input modules in the scene'.

    What I did do was remove the button() component from my buttons, and replace it with your InputEventManager() component. This does work to an extent, except it detects the event over the entire scene, and not just for the one button. So any click on the screen will try to fire off a button event.

    Any ideas? I promise I'm not trying to be stupid!
     
  41. daemon3000

    daemon3000

    Joined:
    Aug 13, 2012
    Posts:
    134
    Can you make a small test project where the issue can be replicated? I have can't really figure out what the issue is just from your description.
     
  42. Gil8ert

    Gil8ert

    Joined:
    May 17, 2017
    Posts:
    3
    No worries, I finally got to the bottom of it. I didn't have a Standalone Input Module in my scene anywhere. I added one back in, replaced with custom.

    Then I had to put my button components back on the UI buttons and VOILA!

    It was a mistake replacing the components with InputEventManager()

    Thanks for your time anyway!
     
  43. Gillissie

    Gillissie

    Joined:
    May 16, 2011
    Posts:
    95
    The built-in input manager allows primary and secondary mapping for each functionality. Is it possible to map secondary using this custom input manager? I can't see any obvious properties to set for secondary.

    [Edit] I think I figured out that I need to add additional bindings to the actions in the Input Editor. So I added a second binding to the actions I want, but I'm getting errors that the index was out of range when trying to access m_inputAction.Bindings[1]; Not sure how to make the game recognize the new bindings I added.

    I must be doing something wrong, but I cannot get the input manager to recognize the new bindings. I tried "File->Overwrite Project Settings", but when I quit and relaunch the project, the settings are still the old way. Please advise....

    [Edit] I realized that I have to save the scene in order for my new bindings to be saved after I quit/restart Unity, even though there's no indication at all that those settings are saved in the scene somehow. Still, even though they are still there upon relaunch, when I run my game, it still shows the old settings with only one binding. I'm really confused.

    [Edit] Ugh. It appears that when I call Luminosity.IO.InputManager.Load(); to load existing settings, that it also loads the old configuration with only one binding per action. How can I use the config with the additional bindings, and still load the existing settings?
     
    Last edited: Feb 26, 2020
  44. daemon3000

    daemon3000

    Joined:
    Aug 13, 2012
    Posts:
    134
    There is no support for merging input configurations at the moment. I will look into it this weekend.
     
  45. Gillissie

    Gillissie

    Joined:
    May 16, 2011
    Posts:
    95
    I got around it for now by commenting out the line that loads the configuration, then saved the new configuration, then un-commented out that line.
     
  46. Zhialus

    Zhialus

    Joined:
    Jan 3, 2019
    Posts:
    15
    How does Custom Input Manager compare to unity's new input system? I'm not ultra familiar with either beyond how to get them functioning, are there any deeper rooted advantages of using one over the other, i.e. features one does or doesn't have?
     
  47. daemon3000

    daemon3000

    Joined:
    Aug 13, 2012
    Posts:
    134
    I have no idea. I haven't used Unity's new input system yet.
     
unityunity