The LegacyInput bridge
The LegacyInput API that migrated code calls, how it reads your axes, and the few settings it has.
Documentation pages
Input Porter is coming soon to the Unity Asset Store. This guide describes the release being prepared.
Migrated code calls StackBlender.InputPorter.LegacyInput, which has the same members
as UnityEngine.Input and behaves like it frame by frame, but reads the Input System.
You can also call it directly in new code, and it works the same whether Active Input
Handling is Both or Input System only.
using StackBlender.InputPorter;
void Update()
{
var move = LegacyInput.GetAxis("Horizontal");
if (LegacyInput.GetButtonDown("Jump")) Jump();
}
Members
| Area | Members |
|---|---|
| Keys | GetKey, GetKeyDown, GetKeyUp by KeyCode or by name ("left shift", "joystick button 0") |
| Axes and buttons | GetAxis, GetAxisRaw, GetButton, GetButtonDown, GetButtonUp, ResetInputAxes |
| Mouse | GetMouseButton, GetMouseButtonDown, GetMouseButtonUp, mousePosition, mousePositionDelta, mouseScrollDelta, mousePresent |
| Keyboard state | anyKey, anyKeyDown, inputString |
| Joysticks | Joystick buttons and axes by number, GetJoystickNames |
| Touch | touchCount, GetTouch, touches, touchSupported, multiTouchEnabled, simulateMouseWithTouches, touchPressureSupported, stylusTouchSupported |
| Accelerometer | acceleration, accelerationEventCount, GetAccelerationEvent, accelerationEvents |
Unknown axis or key names throw the same exceptions, with the same messages, as legacy input.
Where your axes come from
The migration writes your Input Manager axes to
Assets/InputPorter/Resources/InputPorterLegacyAxes.asset. The bridge loads it by
itself, in the editor and in game builds. To set axes from code instead, for example
in tests, call LegacyInput.Configure(axes) before the first read.
Every keyboard and every mouse is merged, as legacy input did, so a laptop keyboard and a USB keyboard both drive the same keys. Play sessions start clean even when Enter Play Mode Options skip the domain reload.
Settings
| Setting | Default | What it does |
|---|---|---|
LegacyInput.resetRepeatDelay |
0.5 |
After ResetInputAxes, a key still held comes back once it has been held this long, which is when the operating system starts repeating it. Mouse and joystick buttons come back only when pressed again |
LegacyInput.osCursorPosition |
true |
Windows builds: mousePosition follows the operating system’s cursor, as legacy input did. Set it to false to use the Input System’s position |