UI Toolbox logoUI Toolbox

InputSettingsPanel and InputBindingOptions

An InputSettingsPanel is a controls settings screen. It shows one row for each button action of an InputActionAsset. Each row has a KeyBindingField for the keyboard or mouse binding and one for the gamepad binding. It has the members of the SettingsPanel base (see Custom settings panels), Actions and FieldOf(action, column). It needs the Input System package.

The Controls tab of the Settings screen of the GameMenu example: an InputSettingsPanel without its buttons, with five actions

<tb:InputSettingsPanel name="controls" prefs-key="mygame.input" />
// The actions of the game. The panel reads their bindings, with the saved paths over them
var panel = root.Q<InputSettingsPanel>("controls");
panel.Actions = myActions;

How to use the panel:

  1. In the Project window, right-click a folder and click Create > Input Actions. Name the asset, for example GameActions.
  2. Double-click the asset. Click + next to Action Maps and name the map, for example Player.
  3. Click + next to Actions and name the action, for example Jump. In the properties on the right, set Action Type to Button.
  4. Click the binding under the action. Set Path to a key, for example Keyboard > By Location of Key > Space.
  5. Click + on the action row, click Add Binding, and set Path to a gamepad button, for example Gamepad > Button South.
  6. Do steps 3 to 5 for each action. Click Save Asset.
  7. Add a field public InputActionAsset Actions; to the MonoBehaviour of your screen. Drag the asset on the field in the Inspector.
  8. Set panel.Actions = Actions in Start.

The player clicks a key field and presses a key or a button. Delete or Backspace clears the field, and Escape cancels. Apply sets a binding override on each changed binding and saves the paths. Revert goes back to the applied paths. Defaults shows the paths of the asset.

InputBindingOptions works without the panel:

// At the start of the game: set the saved bindings
InputBindingOptions.LoadSaved(actions, "mygame.input").Apply(actions);
actions.Enable();
Member Description
InputBindingOptions.Capture(actions) The paths in effect now, with their overrides.
InputBindingOptions.Defaults(actions) The paths of the asset, without overrides.
InputBindingOptions.LoadSaved(actions, key) The paths in effect, with the saved paths over them.
PathOf(binding), SetPath(binding, path) Reads or sets the path of one InputBinding. An empty path turns the binding off.
Apply(actions) Sets the paths as binding overrides. A path that equals the path of the asset removes the override.
InputBindingOptions.ButtonBindings(actions) The bindings that the options have, as pairs of an action and a binding index.

Tips: