Filtering input actions by control type

I have two implementations for showing the correct ui elements based on the currently used controller. The first works as intended, but the second method is incorrect. I’m wondering if there is a more efficient way of doing what i’d like, would appreciate some input!

Working method
Below, Type is a reference to the inputactionreference that’s attached to the label, example ( the join action ). I have two control types, keyboard and gamepad. I loop through the control schemes to find the gamepad and keyboards, and then use that i variable for to show the correct binding and path.

public InputActionReference[] inputActionReference;
 for (int i = 0; i < type.asset.controlSchemes.Count; i++)
            {
                if(type.asset.controlSchemes[i].bindingGroup.Contains("Gamepad"))
                    label.lblGamepadTxt.text = "<sprite name=" + InputControlPath.ToHumanReadableString(type.action.bindings[i].path, InputControlPath.HumanReadableStringOptions.OmitDevice) + ">";
                else if(type.asset.controlSchemes[i].bindingGroup.Contains("Keyboard"))
                    label.lblKeyboardTxt.text = InputControlPath.ToHumanReadableString(type.action.bindings[i].path, InputControlPath.HumanReadableStringOptions.OmitDevice).ToUpper();
            }

Non-Working method ( shows gamepad instead of keyboard )
Below, I get the current control scheme index and pass that into the bindings array, but i find it gives me the wrong scheme. Thoughts?

public InputActionReference inputActionReference;
 if (myPlayer.GetComponentInParent<PlayerInput>().currentControlScheme.Contains("Gamepad"))
        {
            joinObj.GetComponentInChildren<TextMeshPro>().text =
                "<sprite name=" + InputControlPath.ToHumanReadableString(inputActionReference.action.bindings[getCurrentControlSchemeIndex()].path,
                InputControlPath.HumanReadableStringOptions.OmitDevice) + ">";
        }
        else if (myPlayer.GetComponentInParent<PlayerInput>().currentControlScheme.Contains("Keyboard"))
        {
            joinObj.GetComponentInChildren<TextMeshPro>().text =
                InputControlPath.ToHumanReadableString(inputActionReference.action.bindings[getCurrentControlSchemeIndex()].path,
                InputControlPath.HumanReadableStringOptions.OmitDevice);
        }

    int getCurrentControlSchemeIndex()
    {
        int index = inputActionReference.asset.FindControlSchemeIndex(myPlayer.GetComponentInParent<PlayerInput>().currentControlScheme);
        return index;
    }

If you’re looking at an already joined player complete with a control scheme and device(s), the most straightforward way is probably to simply grab the display name from the actual control.

inputActionReference.action.controls[0].displayName

If the control scheme switches, you’re still displaying the right thing. Also, it’ll allow automatically distinguishing between Xbox and PS4 controllers.

Will need some fallback and also can’t deal with composites and the like where there’s more than one control feeding into the action. Post 1.0, all this should become much easier.

Thanks Rene!

Ended up using that code elsewhere during play, but used the code above to produce this piece. Really helps with this new system, thanks for all the hard work.

08jvg

Looks great!