Class InputRecorder
A wrapper component around InputEventTrace that provides an easy interface for recording input from a GameObject.
Namespace: UnityEngine.InputSystem
Syntax
public class InputRecorder : MonoBehaviour
Remarks
This component comes with a custom inspector that provides an easy recording and playback interface and also gives feedback about what has been recorded in the trace. The interface also allows saving and loading event traces.
Capturing can either be constrained by a devicePath or capture all input occuring in the system.
Replay by default will happen frame by frame (see PlayAllFramesOneByOne()). If frame markers are disabled (see recordFrames), all events are queued right away in the first frame and replay completes immediately.
Other than frame-by-frame, replay can be made to happen in a way that tries to simulate the original input timing. To do so, enable simulateOriginalTimingOnReplay. This will make use of PlayAllEventsAccordingToTimestamps()
Properties
allocatedSizeInBytes
Total size of capture memory currently allocated.
Declaration
public long allocatedSizeInBytes { get; }
Property Value
Type | Description |
---|---|
Int64 | Size of memory allocated for capture. |
capture
The underlying event trace that contains the captured input events.
Declaration
public InputEventTrace capture { get; }
Property Value
Type | Description |
---|---|
InputEventTrace | Underlying event trace. |
Remarks
This will be null if no capture is currently associated with the recorder.
captureIsRunning
Whether a capture is currently in progress.
Declaration
public bool captureIsRunning { get; }
Property Value
Type | Description |
---|---|
Boolean | True if a capture is in progress. |
changeEvent
Declaration
public InputRecorder.ChangeEvent changeEvent { get; }
Property Value
Type | Description |
---|---|
InputRecorder.ChangeEvent |
devicePath
Path that constrains the devices to record from.
Declaration
public string devicePath { get; set; }
Property Value
Type | Description |
---|---|
String | Input control path to match devices or null/empty. |
Remarks
By default, this is not set. Meaning that input will be recorded from all devices. By setting this property to a path, only events for devices that match the given path (as dictated by Matches(String, InputControl)) will be recorded from.
By setting this property to the exact path of a device at runtime, recording can be restricted to just that device.
See Also
eventCount
Total number of events captured.
Declaration
public long eventCount { get; }
Property Value
Type | Description |
---|---|
Int64 | Number of captured events. |
playButtonPath
Declaration
public string playButtonPath { get; set; }
Property Value
Type | Description |
---|---|
String |
recordButtonPath
Declaration
public string recordButtonPath { get; set; }
Property Value
Type | Description |
---|---|
String |
recordFrames
Whether to record frame marker events when capturing input. Enabled by default.
Declaration
public bool recordFrames { get; set; }
Property Value
Type | Description |
---|---|
Boolean | True if frame marker events will be recorded. |
See Also
recordStateEventsOnly
Whether to record only StateEvents and DeltaStateEvents. Disabled by default.
Declaration
public bool recordStateEventsOnly { get; set; }
Property Value
Type | Description |
---|---|
Boolean | True if anything but state events should be ignored. |
replay
The replay controller for when a replay is running.
Declaration
public InputEventTrace.ReplayController replay { get; }
Property Value
Type | Description |
---|---|
InputEventTrace.ReplayController | Replay controller for the event trace while replay is running. |
See Also
replayIsRunning
Whether a replay is currently being run by the component.
Declaration
public bool replayIsRunning { get; }
Property Value
Type | Description |
---|---|
Boolean | True if replay is running. |
See Also
replayOnNewDevices
Whether a replay should create new devices or replay recorded events as is. Disabled by default.
Declaration
public bool replayOnNewDevices { get; set; }
Property Value
Type | Description |
---|---|
Boolean | True if replay should temporary create new devices. |
See Also
replayPosition
Declaration
public int replayPosition { get; }
Property Value
Type | Description |
---|---|
Int32 |
simulateOriginalTimingOnReplay
Whether to attempt to re-create the original event timing when replaying events. Disabled by default.
Declaration
public bool simulateOriginalTimingOnReplay { get; set; }
Property Value
Type | Description |
---|---|
Boolean | If true, events are queued based on their timestamp rather than based on their recorded frames (if any). |
See Also
startRecordingWhenEnabled
If true, input recording is started immediately when the component is enabled. Disabled by default. Call StartCapture() to manually start capturing.
Declaration
public bool startRecordingWhenEnabled { get; set; }
Property Value
Type | Description |
---|---|
Boolean | True if component will start recording automatically in OnEnable(). |
See Also
totalEventSizeInBytes
Total size of captured events.
Declaration
public long totalEventSizeInBytes { get; }
Property Value
Type | Description |
---|---|
Int64 | Size of captured events in bytes. |
Methods
ClearCapture()
Declaration
public void ClearCapture()
LoadCaptureFromFile(String)
Declaration
public void LoadCaptureFromFile(string fileName)
Parameters
Type | Name | Description |
---|---|---|
String | fileName |
OnDestroy()
Declaration
protected void OnDestroy()
OnDisable()
Declaration
protected void OnDisable()
OnEnable()
Declaration
protected void OnEnable()
PauseReplay()
Declaration
public void PauseReplay()
SaveCaptureToFile(String)
Declaration
public void SaveCaptureToFile(string fileName)
Parameters
Type | Name | Description |
---|---|---|
String | fileName |
StartCapture()
Declaration
public void StartCapture()
StartReplay()
Declaration
public void StartReplay()
StopCapture()
Declaration
public void StopCapture()
StopReplay()
Declaration
public void StopReplay()