image/svg+xml
docs.unity3d.com
  • Manual
  • Scripting API
  • Changelog
  • License
    Show / Hide Table of Contents
    • Unity​Engine.​Input​System
      • Accelerometer
      • Ambient​Temperature​Sensor
      • Attitude​Sensor
      • Common​Usages
      • Default​Input​Actions
      • Default​Input​Actions.​IPlayer​Actions
      • Default​Input​Actions.​IUIActions
      • Default​Input​Actions.​Player​Actions
      • Default​Input​Actions.​UIActions
      • Gamepad
      • Gravity​Sensor
      • Gyroscope
      • Humidity​Sensor
      • IInput​Action​Collection
      • IInput​Action​Collection2
      • IInput​Interaction
      • IInput​Interaction<TValue>
      • Input​Action
      • Input​Action.​Callback​Context
      • Input​Action​Asset
      • Input​Action​Change
      • Input​Action​Map
      • Input​Action​Phase
      • Input​Action​Property
      • Input​Action​Rebinding​Extensions
      • Input​Action​Rebinding​Extensions.​Rebinding​Operation
      • Input​Action​Reference
      • Input​Action​Setup​Extensions
      • Input​Action​Setup​Extensions.​Binding​Syntax
      • Input​Action​Setup​Extensions.​Composite​Syntax
      • Input​Action​Setup​Extensions.​Control​Scheme​Syntax
      • Input​Action​Type
      • Input​Binding
      • Input​Binding.​Display​String​Options
      • Input​Binding​Composite
      • Input​Binding​Composite<TValue>
      • Input​Binding​Composite​Context
      • Input​Binding​Composite​Context.​Part​Binding
      • Input​Control
      • Input​Control<TValue>
      • Input​Control​Extensions
      • Input​Control​Extensions.​Enumerate
      • Input​Control​Extensions.​Input​Event​Control​Collection
      • Input​Control​Extensions.​Input​Event​Control​Enumerator
      • Input​Control​Layout​Change
      • Input​Control​List<TControl>
      • Input​Control​Path
      • Input​Control​Path.​Human​Readable​String​Options
      • Input​Control​Path.​Parsed​Path​Component
      • Input​Control​Scheme
      • Input​Control​Scheme.​Device​Requirement
      • Input​Control​Scheme.​Match​Result
      • Input​Control​Scheme.​Match​Result.​Match
      • Input​Device
      • Input​Device​Change
      • Input​Extensions
      • Input​Interaction​Context
      • Input​Processor
      • Input​Processor<TValue>
      • Input​Recorder
      • Input​Recorder.​Change
      • Input​Recorder.​Change​Event
      • Input​Remoting
      • Input​Remoting.​Message
      • Input​Remoting.​Message​Type
      • Input​Settings
      • Input​Settings.​Background​Behavior
      • Input​Settings.​Editor​Input​Behavior​In​Play​Mode
      • Input​Settings.​iOSSettings
      • Input​Settings.​Update​Mode
      • Input​System
      • Input​Test​Fixture
      • Input​Test​Fixture.​Action​Constraint
      • Input​Value
      • Joystick
      • Key
      • Keyboard
      • Light​Sensor
      • Linear​Acceleration​Sensor
      • Magnetic​Field​Sensor
      • Mouse
      • Pen
      • Pen​Button
      • Player​Input
      • Player​Input.​Action​Event
      • Player​Input.​Controls​Changed​Event
      • Player​Input.​Device​Lost​Event
      • Player​Input.​Device​Regained​Event
      • Player​Input​Manager
      • Player​Input​Manager.​Player​Joined​Event
      • Player​Input​Manager.​Player​Left​Event
      • Player​Join​Behavior
      • Player​Notifications
      • Pointer
      • Pressure​Sensor
      • Proximity​Sensor
      • Sensor
      • Step​Counter
      • Touch​Phase
      • Touchscreen
      • Tracked​Device
    • Unity​Engine.​Input​System.​Android
      • Android​Accelerometer
      • Android​Ambient​Temperature
      • Android​Gamepad
      • Android​Gamepad​With​Dpad​Axes
      • Android​Gamepad​With​Dpad​Buttons
      • Android​Gravity​Sensor
      • Android​Gyroscope
      • Android​Joystick
      • Android​Light​Sensor
      • Android​Linear​Acceleration​Sensor
      • Android​Magnetic​Field​Sensor
      • Android​Pressure​Sensor
      • Android​Proximity
      • Android​Relative​Humidity
      • Android​Rotation​Vector
      • Android​Step​Counter
      • Dual​Shock4Gamepad​Android
      • Xbox​One​Gamepad​Android
    • Unity​Engine.​Input​System.​Composites
      • Axis​Composite
      • Axis​Composite.​Which​Side​Wins
      • Button​With​One​Modifier
      • Button​With​Two​Modifiers
      • One​Modifier​Composite
      • Two​Modifiers​Composite
      • Vector2Composite
      • Vector2Composite.​Mode
      • Vector3Composite
      • Vector3Composite.​Mode
    • Unity​Engine.​Input​System.​Controls
      • Any​Key​Control
      • Axis​Control
      • Axis​Control.​Clamp
      • Button​Control
      • Discrete​Button​Control
      • Double​Control
      • Dpad​Control
      • Dpad​Control.​Dpad​Axis​Control
      • Integer​Control
      • Key​Control
      • Quaternion​Control
      • Stick​Control
      • Touch​Control
      • Touch​Phase​Control
      • Touch​Press​Control
      • Vector2Control
      • Vector3Control
    • Unity​Engine.​Input​System.​Dual​Shock
      • Dual​Shock3Gamepad​HID
      • Dual​Shock4Gamepad​HID
      • Dual​Shock​Gamepad
      • IDual​Shock​Haptics
    • Unity​Engine.​Input​System.​Editor
      • Input​Control​Path​Editor
      • Input​Control​Picker
      • Input​Control​Picker.​Mode
      • Input​Control​Picker​State
      • Input​Parameter​Editor
      • Input​Parameter​Editor<TObject>
    • Unity​Engine.​Input​System.​Enhanced​Touch
      • Enhanced​Touch​Support
      • Finger
      • Touch
      • Touch​History
      • Touch​Simulation
    • Unity​Engine.​Input​System.​Haptics
      • IDual​Motor​Rumble
      • IHaptics
    • Unity​Engine.​Input​System.​HID
      • HID
      • HID.​Button
      • HID.​Generic​Desktop
      • HID.​HIDCollection​Descriptor
      • HID.​HIDCollection​Type
      • HID.​HIDDevice​Descriptor
      • HID.​HIDDevice​Descriptor​Builder
      • HID.​HIDElement​Descriptor
      • HID.​HIDElement​Flags
      • HID.​HIDReport​Type
      • HID.​Simulation
      • HID.​Usage​Page
      • HIDSupport
      • HIDSupport.​HIDPage​Usage
    • Unity​Engine.​Input​System.​Interactions
      • Hold​Interaction
      • Multi​Tap​Interaction
      • Press​Behavior
      • Press​Interaction
      • Slow​Tap​Interaction
      • Tap​Interaction
    • Unity​Engine.​Input​System.​iOS
      • Dual​Shock4Gampadi​OS
      • i​OSGame​Controller
      • Privacy​Data​Usage
      • Xbox​One​Gampadi​OS
    • Unity​Engine.​Input​System.​iOS.​Low​Level
      • i​OSStep​Counter
      • Motion​Authorization​Status
    • Unity​Engine.​Input​System.​Layouts
      • Input​Control​Attribute
      • Input​Control​Layout
      • Input​Control​Layout.​Builder
      • Input​Control​Layout.​Builder.​Control​Builder
      • Input​Control​Layout.​Control​Item
      • Input​Control​Layout.​Layout​Not​Found​Exception
      • Input​Control​Layout​Attribute
      • Input​Device​Description
      • Input​Device​Find​Control​Layout​Delegate
      • Input​Device​Matcher
    • Unity​Engine.​Input​System.​Low​Level
      • Delta​State​Event
      • Device​Configuration​Event
      • Device​Remove​Event
      • Device​Reset​Event
      • Disable​Device​Command
      • Enable​Device​Command
      • Enable​IMEComposition​Command
      • Gamepad​Button
      • Gamepad​State
      • IInput​Device​Command​Info
      • IInput​Event​Type​Info
      • IInput​State​Callback​Receiver
      • IInput​State​Change​Monitor
      • IInput​State​Type​Info
      • IInput​Update​Callback​Receiver
      • IMEComposition​Event
      • IMEComposition​String
      • Initiate​User​Account​Pairing​Command
      • Initiate​User​Account​Pairing​Command.​Result
      • Input​Device​Command
      • Input​Device​Command​Delegate
      • Input​Device​Execute​Command​Delegate
      • Input​Event
      • Input​Event​Buffer
      • Input​Event​Listener
      • Input​Event​Ptr
      • Input​Event​Trace
      • Input​Event​Trace.​Device​Info
      • Input​Event​Trace.​Replay​Controller
      • Input​Metrics
      • Input​State
      • Input​State​Block
      • Input​State​History
      • Input​State​History.​Record
      • Input​State​History.​Record​Header
      • Input​State​History<TValue>
      • Input​State​History<TValue>.​Record
      • Input​Update​Type
      • IText​Input​Receiver
      • Keyboard​State
      • Mouse​Button
      • Mouse​State
      • Pen​State
      • Query​Can​Run​In​Background
      • Query​Dimensions​Command
      • Query​Enabled​State​Command
      • Query​Keyboard​Layout​Command
      • Query​Key​Name​Command
      • Query​Paired​User​Account​Command
      • Query​Paired​User​Account​Command.​Result
      • Request​Reset​Command
      • Request​Sync​Command
      • Set​IMECursor​Position​Command
      • Set​Sampling​Frequency​Command
      • State​Event
      • Text​Event
      • Touch​State
    • Unity​Engine.​Input​System.​On​Screen
      • On​Screen​Button
      • On​Screen​Control
      • On​Screen​Stick
    • Unity​Engine.​Input​System.​Processors
      • Axis​Deadzone​Processor
      • Clamp​Processor
      • Editor​Window​Space​Processor
      • Invert​Processor
      • Invert​Vector2Processor
      • Invert​Vector3Processor
      • Normalize​Processor
      • Normalize​Vector2Processor
      • Normalize​Vector3Processor
      • Scale​Processor
      • Scale​Vector2Processor
      • Scale​Vector3Processor
      • Stick​Deadzone​Processor
    • Unity​Engine.​Input​System.​Samples
      • Input​Action​Visualizer
      • Input​Action​Visualizer.​Visualization
      • Input​Control​Visualizer
      • Input​Control​Visualizer.​Mode
      • Input​Visualizer
    • Unity​Engine.​Input​System.​Switch
      • Switch​Pro​Controller​HID
    • Unity​Engine.​Input​System.​UI
      • Extended​Pointer​Event​Data
      • Input​System​UIInput​Module
      • Multiplayer​Event​System
      • Tracked​Device​Raycaster
      • UIPointer​Behavior
      • UIPointer​Type
      • Virtual​Mouse​Input
      • Virtual​Mouse​Input.​Cursor​Mode
    • Unity​Engine.​Input​System.​Users
      • Input​User
      • Input​User.​Control​Scheme​Change​Syntax
      • Input​User​Account​Handle
      • Input​User​Change
      • Input​User​Pairing​Options
    • Unity​Engine.​Input​System.​Utilities
      • Display​String​Format​Attribute
      • Four​CC
      • Input​Action​Trace
      • Input​Action​Trace.​Action​Event​Ptr
      • Interned​String
      • Name​And​Parameters
      • Named​Value
      • Observable
      • Primitive​Value
      • Read​Only​Array<TValue>
      • Read​Only​Array<TValue>.​Enumerator
      • Read​Only​Array​Extensions
      • Vector2Magnitude​Comparer
      • Vector3Magnitude​Comparer
    • Unity​Engine.​Input​System.​Web​GL
      • Web​GLGamepad
      • Web​GLJoystick
    • Unity​Engine.​Input​System.​XInput
      • IXbox​One​Rumble
      • Xbox​Gamepad​Mac​OS
      • Xbox​One​Gampad​Mac​OSWireless
      • XInput​Controller
      • XInput​Controller.​Device​Flags
      • XInput​Controller.​Device​Sub​Type
    • Unity​Engine.​Input​System.​XR
      • Bone
      • Bone​Control
      • Eyes
      • Eyes​Control
      • Feature​Type
      • Pose​Control
      • Pose​State
      • Tracked​Pose​Driver
      • Tracked​Pose​Driver.​Tracking​Type
      • Tracked​Pose​Driver.​Update​Type
      • Usage​Hint
      • XRController
      • XRController​With​Rumble
      • XRDevice​Descriptor
      • XRFeature​Descriptor
      • XRHMD
      • XRUtilities
    • Unity​Engine.​Input​System.​XR.​Haptics
      • Buffered​Rumble
      • Get​Current​Haptic​State​Command
      • Get​Haptic​Capabilities​Command
      • Haptic​Capabilities
      • Haptic​State
      • Send​Buffered​Haptic​Command
      • Send​Haptic​Impulse​Command
    • Scripting API
    • Unity​Engine.​Input​System.​Low​Level
    • Input​State​History

    Class InputStateHistory

    Record a history of state changes applied to one or more controls.

    Inheritance
    Object
    InputStateHistory
    InputStateHistory<TValue>
    Namespace: UnityEngine.InputSystem.LowLevel
    Syntax
    public class InputStateHistory : IDisposable, IEnumerable<InputStateHistory.Record>, IInputStateChangeMonitor
    Remarks

    This class makes it easy to track input values over time. It will automatically retain input state up to a given maximum history depth (historyDepth). When the history is full, it will start overwriting the oldest entry each time a new history record is received.

    The class listens to changes on the given controls by adding change monitors (IInputStateChangeMonitor) to each control.

    // Track all stick controls in the system.
    var history = new InputStateHistory<Vector2>("*/<Stick>");
    foreach (var control in history.controls)
        Debug.Log("Capturing input on " + control);
    
    // Start capturing.
    history.StartRecording();
    
    // Perform a couple artificial value changes.
    Gamepad.current.leftStick.QueueValueChange(new Vector2(0.123f, 0.234f));
    Gamepad.current.leftStick.QueueValueChange(new Vector2(0.234f, 0.345f));
    Gamepad.current.leftStick.QueueValueChange(new Vector2(0.345f, 0.456f));
    InputSystem.Update();
    
    // Every value change will be visible in the history.
    foreach (var record in history)
        Debug.Log($"{record.control} changed value to {record.ReadValue()}");
    
    // Histories allocate unmanaged memory and must be disposed of in order to not leak.
    history.Dispose();

    Constructors

    InputStateHistory(IEnumerable<InputControl>)

    Declaration
    public InputStateHistory(IEnumerable<InputControl> controls)
    Parameters
    Type Name Description
    IEnumerable<InputControl> controls

    InputStateHistory(Int32)

    Declaration
    public InputStateHistory(int maxStateSizeInBytes)
    Parameters
    Type Name Description
    Int32 maxStateSizeInBytes

    InputStateHistory(String)

    Declaration
    public InputStateHistory(string path)
    Parameters
    Type Name Description
    String path

    InputStateHistory(InputControl)

    Declaration
    public InputStateHistory(InputControl control)
    Parameters
    Type Name Description
    InputControl control

    Properties

    controls

    Declaration
    public ReadOnlyArray<InputControl> controls { get; }
    Property Value
    Type Description
    ReadOnlyArray<InputControl>

    Count

    Total number of state records currently captured in the history.

    Declaration
    public int Count { get; }
    Property Value
    Type Description
    Int32

    Number of records in the collection.

    Remarks

    This will always be at most historyDepth.

    See Also
    historyDepth
    RecordStateChange(InputControl, InputEventPtr)

    extraMemoryPerRecord

    Declaration
    public int extraMemoryPerRecord { get; set; }
    Property Value
    Type Description
    Int32

    historyDepth

    Maximum number of records that can be recorded in the history.

    Declaration
    public int historyDepth { get; set; }
    Property Value
    Type Description
    Int32

    Upper limit on number of records.

    Remarks

    A fixed size memory block of unmanaged memory will be allocated to store history records. This property determines TODO

    Item[Int32]

    Declaration
    public InputStateHistory.Record this[int index] { get; set; }
    Parameters
    Type Name Description
    Int32 index
    Property Value
    Type Description
    InputStateHistory.Record

    onRecordAdded

    Declaration
    public Action<InputStateHistory.Record> onRecordAdded { get; set; }
    Property Value
    Type Description
    Action<InputStateHistory.Record>

    onShouldRecordStateChange

    Declaration
    public Func<InputControl, double, InputEventPtr, bool> onShouldRecordStateChange { get; set; }
    Property Value
    Type Description
    Func<InputControl, Double, InputEventPtr, Boolean>

    updateMask

    Declaration
    public InputUpdateType updateMask { get; set; }
    Property Value
    Type Description
    InputUpdateType

    version

    Current version stamp. Every time a record is stored in the history, this is incremented by one.

    Declaration
    public uint version { get; }
    Property Value
    Type Description
    UInt32

    Version stamp that indicates the number of mutations.

    See Also
    RecordStateChange(InputControl, InputEventPtr)

    Methods

    AddRecord(InputStateHistory.Record)

    Declaration
    public InputStateHistory.Record AddRecord(InputStateHistory.Record record)
    Parameters
    Type Name Description
    InputStateHistory.Record record
    Returns
    Type Description
    InputStateHistory.Record

    AllocateRecord(out Int32)

    Declaration
    protected InputStateHistory.RecordHeader*AllocateRecord(out int index)
    Parameters
    Type Name Description
    Int32 index
    Returns
    Type Description
    InputStateHistory.RecordHeader*

    Clear()

    Declaration
    public void Clear()

    Destroy()

    Declaration
    protected void Destroy()

    Dispose()

    Declaration
    public void Dispose()

    Finalize()

    Declaration
    protected void Finalize()

    GetEnumerator()

    Declaration
    public IEnumerator<InputStateHistory.Record> GetEnumerator()
    Returns
    Type Description
    IEnumerator<InputStateHistory.Record>

    GetRecord(Int32)

    Declaration
    protected InputStateHistory.RecordHeader*GetRecord(int index)
    Parameters
    Type Name Description
    Int32 index
    Returns
    Type Description
    InputStateHistory.RecordHeader*

    ReadValue<TValue>(InputStateHistory.RecordHeader*)

    Declaration
    protected TValue ReadValue<TValue>(InputStateHistory.RecordHeader*data)
        where TValue : struct
    Parameters
    Type Name Description
    InputStateHistory.RecordHeader* data
    Returns
    Type Description
    TValue
    Type Parameters
    Name Description
    TValue

    ReadValueAsObject(InputStateHistory.RecordHeader*)

    Declaration
    protected object ReadValueAsObject(InputStateHistory.RecordHeader*data)
    Parameters
    Type Name Description
    InputStateHistory.RecordHeader* data
    Returns
    Type Description
    Object

    RecordIndexToUserIndex(Int32)

    Declaration
    protected int RecordIndexToUserIndex(int index)
    Parameters
    Type Name Description
    Int32 index
    Returns
    Type Description
    Int32

    RecordStateChange(InputControl, Void*, Double)

    Declaration
    public InputStateHistory.Record RecordStateChange(InputControl control, void *statePtr, double time)
    Parameters
    Type Name Description
    InputControl control
    Void* statePtr
    Double time
    Returns
    Type Description
    InputStateHistory.Record

    RecordStateChange(InputControl, InputEventPtr)

    Declaration
    public InputStateHistory.Record RecordStateChange(InputControl control, InputEventPtr eventPtr)
    Parameters
    Type Name Description
    InputControl control
    InputEventPtr eventPtr
    Returns
    Type Description
    InputStateHistory.Record

    StartRecording()

    Declaration
    public void StartRecording()

    StopRecording()

    Declaration
    public void StopRecording()

    UserIndexToRecordIndex(Int32)

    Declaration
    protected int UserIndexToRecordIndex(int index)
    Parameters
    Type Name Description
    Int32 index
    Returns
    Type Description
    Int32

    Explicit Interface Implementations

    IInputStateChangeMonitor.NotifyControlStateChanged(InputControl, Double, InputEventPtr, Int64)

    Declaration
    void IInputStateChangeMonitor.NotifyControlStateChanged(InputControl control, double time, InputEventPtr eventPtr, long monitorIndex)
    Parameters
    Type Name Description
    InputControl control
    Double time
    InputEventPtr eventPtr
    Int64 monitorIndex
    Implements
    IInputStateChangeMonitor.NotifyControlStateChanged(InputControl, Double, InputEventPtr, Int64)

    IInputStateChangeMonitor.NotifyTimerExpired(InputControl, Double, Int64, Int32)

    Declaration
    void IInputStateChangeMonitor.NotifyTimerExpired(InputControl control, double time, long monitorIndex, int timerIndex)
    Parameters
    Type Name Description
    InputControl control
    Double time
    Int64 monitorIndex
    Int32 timerIndex
    Implements
    IInputStateChangeMonitor.NotifyTimerExpired(InputControl, Double, Int64, Int32)

    Did you find this page useful? Please give it a rating:

    Thanks for rating this page!

    Report a problem on this page

    What kind of problem would you like to report?

    • This page needs code samples
    • Code samples do not work
    • Information is missing
    • Information is incorrect
    • Information is unclear or confusing
    • There is a spelling/grammar error on this page
    • Something else

    Thanks for letting us know! This page has been marked for review based on your feedback.

    If you have time, you can provide more information to help us fix the problem faster.

    Provide more information

    You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:

    You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:

    You've told us there is information missing from this page. Please tell us more about what's missing:

    You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:

    You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:

    You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:

    You've told us this page has a problem. Please tell us more about what's wrong:

    Thank you for helping to make the Unity documentation better!

    Your feedback has been submitted as a ticket for our documentation team to review.

    We are not able to reply to every ticket submitted.

    In This Article
    • Constructors
      • InputStateHistory(IEnumerable<InputControl>)
      • InputStateHistory(Int32)
      • InputStateHistory(String)
      • InputStateHistory(InputControl)
    • Properties
      • controls
      • Count
      • extraMemoryPerRecord
      • historyDepth
      • Item[Int32]
      • onRecordAdded
      • onShouldRecordStateChange
      • updateMask
      • version
    • Methods
      • AddRecord(InputStateHistory.Record)
      • AllocateRecord(out Int32)
      • Clear()
      • Destroy()
      • Dispose()
      • Finalize()
      • GetEnumerator()
      • GetRecord(Int32)
      • ReadValue<TValue>(InputStateHistory.RecordHeader*)
      • ReadValueAsObject(InputStateHistory.RecordHeader*)
      • RecordIndexToUserIndex(Int32)
      • RecordStateChange(InputControl, Void*, Double)
      • RecordStateChange(InputControl, InputEventPtr)
      • StartRecording()
      • StopRecording()
      • UserIndexToRecordIndex(Int32)
    • Explicit Interface Implementations
      • IInputStateChangeMonitor.NotifyControlStateChanged(InputControl, Double, InputEventPtr, Int64)
      • IInputStateChangeMonitor.NotifyTimerExpired(InputControl, Double, Int64, Int32)
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023