Introduction to on-screen controls
You can use on-screen controls to simulate Input Devices with UI widgets that the user interacts with on the screen. The most prominent example is the use of stick and button widgets on touchscreens to emulate a joystick or gamepad.
There are two built-in on-screen control types:
You can implement custom controls by extending the base OnScreenControl class (see documentation on writing custom on screen controls to learn more).
Note
On-screen controls don't have a predefined visual representation. It's up to you to set up the visual aspect of a control (for example, by adding a sprite or UI component to the GameObject). On-screen controls take care of the interaction logic and of setting up and generating input from interactions.
Each on-screen control uses a control path to reference the control that it should report input as. For example, the following on-screen button reports input as the right shoulder button of a gamepad:
![The OnScreenButton component displays the Control Path value as rightShoulder [Gamepad].](images/OnScreenButton.png)
The collection of on-screen controls present in a Scene forms one or more input devices. The Input System creates one input Device for each distinct type of device the controls reference. For example, if one on-screen button references <Gamepad>/buttonSouth and another on-screen button references <Keyboard>/a, the Input System creates both a Gamepad and a Keyboard. This happens automatically when the components are enabled. When disabled, the Input System automatically removes the devices again.
To query the control (and, implicitly, the device) that an on-screen control feeds into, you can use the OnScreenControl.control property.
Add on-screen controls to your project
On-screen controls are components that you add to UI GameObjects, such as a Button or an Image, on a Canvas. They respond to pointer events from the Unity UI system, so your scene also needs an EventSystem with an Input System UI Input Module.
You don't need to query an on-screen control or connect it to your actions. It reports input as the control in its Control Path, so any action bound to that control responds to it. For example, an on-screen stick with the control path <Gamepad>/leftStick drives the same actions as the left stick of a real gamepad, such as the Move action in the default project-wide actions.
Note
This design allows you to use on-screen controls to create input for arbitrary input devices, in addition to joysticks and gamepads.