Input simulation methods
Compare the ways to send input to a device without its hardware, for example to test your input code, drive a virtual device, or replay input that you recorded.
The Input System has several ways to simulate input. Some work only in the Editor or in tests, and others also work in builds.
Simulation methods by goal
| Goal | Method | Works in builds | More information |
|---|---|---|---|
| Feed input in automated tests | The Press, Release, PressAndRelease, Set, and Trigger methods of InputTestFixture. |
Test builds only. Not available in normal player builds. | Write tests |
| Send input to a device as if it came from the hardware | InputSystem.QueueStateEvent or InputSystem.QueueDeltaStateEvent. The Input System processes the events in its next update. |
Yes. | Create events |
| Change the state of a device immediately, without the event queue | InputState.Change. |
Yes. | Synthesize a device state change |
| Create a virtual device to send input to | InputSystem.AddDevice. |
Yes. | Manually add and remove devices |
| Replay input that you recorded | InputEventTrace.Replay. |
Yes. | Record events |
| Simulate touch input with a mouse or pen | The Simulate Touch Input From Mouse or Pen option in the Input Debugger window, the TouchSimulation component, or the Device Simulator window. |
Input Debugger option and Device Simulator: No, Editor only. TouchSimulation: Yes. |
Simulate touches, Device Simulation |
| Let users drive a device with buttons and sticks on the screen | The On-Screen Button and On-Screen Stick components. | Yes. | Create on-screen controls |