Create a device
Once the system has chosen a layout for a device, it instantiates an InputDevice and populates it with InputControls as the layout dictates. This process is internal and happens automatically.
Note
You can't create valid InputDevices and InputControls by manually instantiating them with new. To guide the creation process, you must use layouts.
After the Input System assembles the InputDevice, it calls FinishSetup on each control of the device and on the device itself. Use this to complete the setup of the controls.
After an InputDevice is fully assembled, the Input System adds it to the system. As part of this process, the Input System performs the following actions, in order:
- Calls
InputDevice.OnAdded. - Calls
MakeCurrenton the device. If all the device's controls are noisy and another device of its type is already current, the Input System skips this step. For more information, refer to Noisy controls. - Signals
InputDeviceChange.AddedonInputSystem.onDeviceChange.
After the Input System adds the device, the InputDevice.added property changes to true.
Add devices manually
To add devices manually, you can call one of the InputSystem.AddDevice methods such as InputSystem.AddDevice(layout).
// Add a gamepad. This bypasses the matching process and creates
// a device directly
// with the Gamepad layout.
InputSystem.AddDevice<Gamepad>();
// Add a device such that the matching process is employed:
InputSystem.AddDevice(new InputDeviceDescription
{
interfaceName = "XInput",
product = "Xbox Controller",
});
When you add a device, the Input System automatically issues a sync request on the device. This instructs the device to send an event representing its current state. Whether this request succeeds depends on whether the given device supports the sync command.