Search Unity

Feedback Displaying what an action is bound to

Discussion in 'Input System' started by Adrian, Sep 21, 2019.

  1. Adrian

    Adrian

    Joined:
    Apr 5, 2008
    Posts:
    1,065
    I'm nearly finished converting our old game to the new input system. So far, that has been great and I'm happy that a lot of the headaches caused by the old input manager are now gone.

    One of the last parts I'm implementing is showing the user tutorial messages that include which keys or buttons to use. Unfortunately, this has turned out to be pretty cumbersome.

    For displaying, I don't want to use the same more generic name that I'm using for rebinding and that's produced by InputControlPath.ToHumanReadableString, i.e. «Button South» for the X button on PS4 controller. I want to display the actual button of the used gamepad, "X" in this case.

    Controls have nice display names for that but I couldn't find an easy way to go from a binding to the control it has been resolved to. Right now I'm using InputControlPath.Matches with the effectivePath on every control of the action but that seems a bit brittle. It would be nice for a binding to have the index of the control it was resolved to or a method on actions that converts a binding index to a control index.

    Picking out the right binding is also not very straight-forward. E.g. I want to get the binding for a specific part of a composite with a specific group. Right now, it seems I have to walk through the bindings, check if I'm in the composite I'm looking for and then check against the part name. If the composite binding would somehow map to the actual composite instance, it would be much easier to find the right control (I think composites are currently not accessible at all, since they only live on InputActionState?).

    Is there a better way to get the display name of the control a binding has been resolved to?

    Also, display names for special keyboard keys are unusable right now, since they contain the unicode control character of the key. The input system should convert the control character to a proper display name.
     
  2. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
    Hmm, I'm not sure I fully follow what you need this for yet. You can get the controls an action is bound to using `InputAction.controls`, and you can get nice names from that. But I guess what you want is controls for a specific binding instead, which indeed is not easily possible. But why do you need the specific binding? It seems that all bindings should be equivalent options, so for a tutorial you would want to show all bound controls? Or, you may want to filter them to show only the currently active device or control scheme, but then you can filter controls by that. So, why do you need to get the control for a specific binding?
     
  3. Adrian

    Adrian

    Joined:
    Apr 5, 2008
    Posts:
    1,065
    The way we have things set up is that we have a set of main bindings as well as alternate bindings. On the gamepad, the left stick and the four main buttons are the main bindings but the d-pad and shoulder buttons can be used as well.

    To make things simpler in the tutorial and for rebinding, we only want to show the main bindings and only allow the main bindings to be rebound. This also has the nice effect that if a user customizes controls and then starts the game, the tutorial will show the controls they've chosen.

    I could group the main bindings with a control scheme but how would I filter controls for a control scheme? AFAICT, the groups (control schemes) are stored on the binding, not on the control. So I can filter the bindings for a group but then I have to again figure out wich controls a binding was resolved to.
     
    Daerst and Mikael-H like this.
  4. MlleBun

    MlleBun

    Joined:
    Sep 19, 2017
    Posts:
    163
    You can print actionControl and get something like this :

    Code (CSharp):
    1.  Debug.Log(yourInputSystem.yourActionMap.yourActions.activeControl);
    upload_2019-11-16_11-23-32.png
     
  5. luvcraft

    luvcraft

    Joined:
    Aug 22, 2011
    Posts:
    74