docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Display bindings

    It can be useful for the user to know what an Action is currently bound to (taking any potentially active rebindings into account) while rebinding UIs, and for on-screen hints while the app is running. You can use InputBinding.effectivePath to get the currently active path for a binding (which returns overridePath if set, or otherwise returns path).

    The easiest way to retrieve a display string for an action is to call InputActionRebindingExtensions.GetBindingDisplayString which is an extension method for InputAction.

        // Get a binding string for the action as a whole. This takes into account which
        // bindings are currently active and the actual controls bound to the action.
        m_RebindButton.GetComponentInChildren<Text>().text = action.GetBindingDisplayString();
    
        // Get a binding string for a specific binding on an action by index.
        m_RebindButton.GetComponentInChildren<Text>().text = action.GetBindingDisplayString(1);
    
        // Look up binding indices with GetBindingIndex.
        var bindingIndex = action.GetBindingIndex(InputBinding.MaskByGroup("Gamepad"));
        m_RebindButton.GetComponentInChildren<Text>().text =
            action.GetBindingDisplayString(bindingIndex);
    

    You can also use this method to replace the text string with images.

        // Call GetBindingDisplayString() such that it also returns information about the
        // name of the device layout and path of the control on the device. This information
        // is useful for reliably associating imagery with individual controls.
        // NOTE: The first argument is the index of the binding within InputAction.bindings.
        var bindingString = action.GetBindingDisplayString(0, out deviceLayout, out controlPath);
    
        // If it's a gamepad, look up an icon for the control.
        Sprite icon = null;
        if (!string.IsNullOrEmpty(deviceLayout)
            && !string.IsNullOrEmpty(controlPath)
            && InputSystem.IsFirstLayoutBasedOnSecond(deviceLayout, "Gamepad"))
        {
            switch (controlPath)
            {
                case "buttonSouth": icon = aButtonIcon; break;
                case "dpad/up": icon = dpadUpIcon; break;
                //...
            }
        }
    
        // If you have an icon, display it instead of the text.
        var text = m_RebindButton.GetComponentInChildren<Text>();
        var image = m_RebindButton.GetComponentInChildren<Image>();
        if (icon != null)
        {
            // Display icon.
            text.gameObject.SetActive(false);
            image.gameObject.SetActive(true);
            image.sprite = icon;
        }
        else
        {
            // Display text.
            text.gameObject.SetActive(true);
            image.gameObject.SetActive(false);
            text.text = bindingString;
        }
    

    Additionally, each binding has a ToDisplayString method, which you can use to turn individual bindings into display strings. There is also a generic formatting method for Control paths, InputControlPath.ToHumanReadableString, which you can use with arbitrary Control path strings.

    Note that the Controls a binding resolves to can change at any time, and the display strings for controls might change dynamically. For example, if the user switches the currently active keyboard layout, the display string for each individual key on the Keyboard might change.

    In This Article
    Back to top
    Copyright © 2026 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)