Search Unity

Resolved How do I get the key/button associated to Cancel[any] or similar in Gamepads?

Discussion in 'Input System' started by pixelf0x300, Jan 10, 2022.

  1. pixelf0x300

    pixelf0x300

    Joined:
    Nov 10, 2019
    Posts:
    6
    Hi. yesterday I made a question about this topic in answers.unity, I didnt realised that theres few people posting there in comparison in here, and often the devs post here... So i decided to move the updated question here.

    Im trying to achieve a system that takes an InputActionReference and using the current controller gives the corresponding binding.
    Example: Attack >> For keyboard+Mouse: "Left Button" // For gamepad [any brand] : "Button South"

    I managed to do that fine in the scenario where there is always a specific binding for the controller, i cant use the Cancel [Any] or Submit[Any]. Even though it gives the wanted result with keyvoard, it doesnt do the same with gamepads.

    the current code I have is this:
    Code (CSharp):
    1. var control = currentActionMap.action.controls[0];
    2.  
    3.         string buttonName = InputControlPath.ToHumanReadableString(control.path, InputControlPath.HumanReadableStringOptions.OmitDevice);
    This code gives the almost the same binding in string as
    GetBindingDisplayString()
    but with less errors. Instead of "Left Shoulder" it would give "leftShoulder"

    The problem is that when using the [Any] bindings, and a controller is used, it doesnt detect that there is any control to that action.

    It can be easily fixed adding a specific mapping for the controller and stop using the [Any] bindings, but i wanted to achieve this automatic behaviour.

    I tried a lot with different methods to get whatever string that contains "Button East" (in Xbox controller) and "Button South" (in Nintendo controller) when given the Input action with an [Any] binding, but no success.
     
  2. pixelf0x300

    pixelf0x300

    Joined:
    Nov 10, 2019
    Posts:
    6
    I think im getting to the bottom of the problem, and im feeling pretty stupid.

    So it seems that the project im working, some time ago to make the UI controller compatible I added a binding to the Submit action. I dont remember well what I did at that moment but the navigation in the menu was fine. Maybe I Didnt do enough tests because i hadn't any controller binding on the cancel action.

    Its documented but in the real world doesnt seem to do what it says (at least without a bit of setup)
    The [any] Bindings are Usages, and by default some in keyboard are already implemented (ESC for cancel and Enter for Submit), but for controller you have to add them through code (maybe every time a controller is connected?).

    I haven't found any menu where you can set up this usages widely for each type of controllers, but it would be great.
    In the project settings/Input system there's an option where you can list the supported controllers.
    There could be the options to add usages widely per-controller type.

    In conclusion: the painless way to use the input system is avoiding the usages or using them as a safeguard in edge cases at the bottom of the bindings.
     
    Freddicus likes this.