Class InputEventTrace.ReplayController
Controls replaying of events recorded in an Input
Implements
Namespace: UnityEngine .InputSystem .LowLevel
Assembly: Unity.InputSystem.dll
Syntax
public class InputEventTrace.ReplayController : IDisposable
Remarks
Playback can be controlled either on a per-event or a per-frame basis. Note that playing back events
frame by frame requires frame markers to be present in the trace (see record
By default, events will be queued as is except for their timestamps which will be set to the current time that each event is queued at.
What this means is that events replay with the same device ID (see device
To map recorded events to a different device, you can either call With
var trace = new InputEventTrace(myDevice);
trace.Enable();
// ... run one or more frames ...
trace.Replay().OneFrame();
Properties
createdDevices
List of devices created by the replay controller.
Declaration
public IEnumerable<InputDevice> createdDevices { get; }
Property Value
Type | Description |
---|---|
IEnumerable<Input |
Devices created by the replay controller. |
Remarks
By default, a replay controller will queue events as is, i.e. with device
Using With
See Also
finished
Whether replay has finished.
Declaration
public bool finished { get; }
Property Value
Type | Description |
---|---|
bool | True if replay has finished or is not in progress. |
See Also
paused
Whether replay is paused.
Declaration
public bool paused { get; set; }
Property Value
Type | Description |
---|---|
bool | True if replay is currently paused. |
See Also
position
Current position in the event stream.
Declaration
public int position { get; }
Property Value
Type | Description |
---|---|
int | Index of current event in trace. |
See Also
trace
The event trace associated with the replay controller.
Declaration
public InputEventTrace trace { get; }
Property Value
Type | Description |
---|---|
Input |
Trace from which events are replayed. |
See Also
Methods
Dispose()
Removes devices created by the controller when using With
Declaration
public void Dispose()
See Also
OnEvent(Action<InputEventPtr>)
Invoke the given callback when an event is about to be queued.
Declaration
public InputEventTrace.ReplayController OnEvent(Action<InputEventPtr> action)
Parameters
Type | Name | Description |
---|---|---|
Action<Input |
action | A callback to invoke when an event is getting queued. |
Returns
Type | Description |
---|---|
Input |
The same ReplayController instance. |
See Also
OnFinished(Action)
Invoke the given callback when playback finishes.
Declaration
public InputEventTrace.ReplayController OnFinished(Action action)
Parameters
Type | Name | Description |
---|---|---|
Action | action | A callback to invoke when playback finishes. |
Returns
Type | Description |
---|---|
Input |
The same ReplayController instance. |
See Also
PlayAllEvents()
Go through all remaining event in the trace starting at the current read position and queue them using
Queue
Declaration
public InputEventTrace.ReplayController PlayAllEvents()
Returns
Type | Description |
---|---|
Input |
The same ReplayController instance. |
Remarks
Unlike methods such as Play
See Also
PlayAllEventsAccordingToTimestamps()
Replay events in a way that tries to preserve the original timing sequence.
Declaration
public InputEventTrace.ReplayController PlayAllEventsAccordingToTimestamps()
Returns
Type | Description |
---|---|
Input |
The same ReplayController instance. |
Remarks
This method will take the current time as the starting time to which make all events relative to. Based on this time, it will try to correlate the original event timing with the timing of input updates as they happen. When successful, this will compensate for differences in frame timings compared to when input was recorded and instead queue input in frames that are closer to the original timing.
Note that this method will perform one initial scan of the trace to determine a linear ordering of the events by time (the input system does not require any such ordering on the events in its queue and thus events in a trace, especially if there are multiple devices involved, may be out of order).
See Also
PlayAllFramesOneByOne()
Replay all frames one by one from the current playback position.
Declaration
public InputEventTrace.ReplayController PlayAllFramesOneByOne()
Returns
Type | Description |
---|---|
Input |
The same ReplayController instance. |
Remarks
Events will be fed to the input system from within on
Note that for this method to correctly space out events and distribute them to frames, frame markers
must be present in the trace (see record
See Also
PlayOneEvent()
Takes the next event from the trace and queues it.
Declaration
public InputEventTrace.ReplayController PlayOneEvent()
Returns
Type | Description |
---|---|
Input |
The same ReplayController instance. |
Remarks
This method takes the next event at the current read position and queues it using Queue
Frame marker events (see Frame
Exceptions
Type | Condition |
---|---|
Invalid |
There are no more events in the trace -or- the only
events left are frame marker events (see Frame |
See Also
Rewind()
Rewind playback all the way to the beginning of the event trace.
Declaration
public InputEventTrace.ReplayController Rewind()
Returns
Type | Description |
---|---|
Input |
The same ReplayController instance. |
See Also
WithAllDevicesMappedToNewInstances()
For all events, create new devices to replay the events on instead of replaying the events on existing devices.
Declaration
public InputEventTrace.ReplayController WithAllDevicesMappedToNewInstances()
Returns
Type | Description |
---|---|
Input |
The same ReplayController instance. |
Remarks
Note that devices created by the ReplayController
will stick around for as long as the replay
controller is not disposed of. This means that multiple successive replays using the same ReplayController
will replay the events on the same devices that were created on the first replay. It also means that in order
to do away with the created devices, it is necessary to call Dispose().
See Also
WithDeviceMappedFromTo(int, int)
Replace devicerecordedDeviceId
with device ID playbackDeviceId
.
Declaration
public InputEventTrace.ReplayController WithDeviceMappedFromTo(int recordedDeviceId, int playbackDeviceId)
Parameters
Type | Name | Description |
---|---|---|
int | recordedDeviceId | device |
int | playbackDeviceId | device |
Returns
Type | Description |
---|---|
Input |
The same ReplayController instance. |
See Also
WithDeviceMappedFromTo(InputDevice, InputDevice)
Replay events recorded from recordedDevice
on device playbackDevice
.
Declaration
public InputEventTrace.ReplayController WithDeviceMappedFromTo(InputDevice recordedDevice, InputDevice playbackDevice)
Parameters
Type | Name | Description |
---|---|---|
Input |
recordedDevice | Device events have been recorded from. |
Input |
playbackDevice | Device events should be played back on. |
Returns
Type | Description |
---|---|
Input |
The same ReplayController instance. |
Remarks
This method causes all events with a device ID (see deviceplaybackDevice
.
Exceptions
Type | Condition |
---|---|
Argument |
|