docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class InputStateHistory<TValue>

    Records value changes of a given control over time.

    Inheritance
    object
    InputStateHistory
    InputStateHistory<TValue>
    Implements
    IDisposable
    IEnumerable<InputStateHistory.Record>
    IInputStateChangeMonitor
    IReadOnlyList<InputStateHistory<TValue>.Record>
    IReadOnlyCollection<InputStateHistory<TValue>.Record>
    IEnumerable<InputStateHistory<TValue>.Record>
    IEnumerable
    Inherited Members
    InputStateHistory.Count
    InputStateHistory.version
    InputStateHistory.historyDepth
    InputStateHistory.extraMemoryPerRecord
    InputStateHistory.updateMask
    InputStateHistory.controls
    InputStateHistory.onRecordAdded
    InputStateHistory.onShouldRecordStateChange
    InputStateHistory.Clear()
    InputStateHistory.AddRecord(InputStateHistory.Record)
    InputStateHistory.StartRecording()
    InputStateHistory.StopRecording()
    InputStateHistory.RecordStateChange(InputControl, InputEventPtr)
    InputStateHistory.RecordStateChange(InputControl, void*, double)
    InputStateHistory.Dispose()
    InputStateHistory.Destroy()
    InputStateHistory.RecordIndexToUserIndex(int)
    InputStateHistory.UserIndexToRecordIndex(int)
    InputStateHistory.GetRecord(int)
    InputStateHistory.AllocateRecord(out int)
    InputStateHistory.ReadValue<TValue>(InputStateHistory.RecordHeader*)
    InputStateHistory.ReadValueAsObject(InputStateHistory.RecordHeader*)
    Namespace: UnityEngine.InputSystem.LowLevel
    Assembly: Unity.InputSystem.dll
    Syntax
    public class InputStateHistory<TValue> : InputStateHistory, IDisposable, IEnumerable<InputStateHistory.Record>, IInputStateChangeMonitor, IReadOnlyList<InputStateHistory<TValue>.Record>, IReadOnlyCollection<InputStateHistory<TValue>.Record>, IEnumerable<InputStateHistory<TValue>.Record>, IEnumerable where TValue : struct
    Type Parameters
    Name Description
    TValue

    The type of the record being stored

    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.

    Constructors

    InputStateHistory(int?)

    Creates a new InputStateHistory class to record all control state changes.

    Declaration
    public InputStateHistory(int? maxStateSizeInBytes = null)
    Parameters
    Type Name Description
    int? maxStateSizeInBytes

    Maximum size of control state in the record entries. Controls with larger state will not be recorded.

    Remarks

    Creates a new InputStateHistory to record a history of control state changes.

    New controls are automatically added into the state history if there state is smaller than the threshold.

    InputStateHistory(string)

    Creates a new InputStateHistory class to record state changes for a specified control.

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

    Control path to identify which controls to monitor.

    Remarks

    Creates a new InputStateHistory to record a history of state changes for the specified controls.

    Examples
    // Track all stick controls in the system.
    var history = new InputStateHistory<Vector2>("*/<Stick>");

    InputStateHistory(InputControl<TValue>)

    Creates a new InputStateHistory class to record state changes for a specified control.

    Declaration
    public InputStateHistory(InputControl<TValue> control)
    Parameters
    Type Name Description
    InputControl<TValue> control

    Control to monitor.

    Remarks

    Creates a new InputStateHistory to record a history of state changes for the specified control.

    Properties

    this[int]

    Returns an entry in the state history at the given index.

    Declaration
    public InputStateHistory<TValue>.Record this[int index] { get; set; }
    Parameters
    Type Name Description
    int index

    Index into the array.

    Property Value
    Type Description
    InputStateHistory<TValue>.Record
    Remarks

    Returns a InputStateHistory<TValue>.Record entry from the state history at the given index.

    Exceptions
    Type Condition
    IndexOutOfRangeException

    index is less than 0 or greater than Count.

    Methods

    AddRecord(Record)

    Add a record to the input state history.

    Declaration
    public InputStateHistory<TValue>.Record AddRecord(InputStateHistory<TValue>.Record record)
    Parameters
    Type Name Description
    InputStateHistory<TValue>.Record record

    Record to add.

    Returns
    Type Description
    InputStateHistory<TValue>.Record

    The newly added record from the history array (as a copy is made).

    Remarks

    Add a record to the input state history. Allocates an entry in the history array and returns this copy of the original data passed to the function.

    ~InputStateHistory()

    InputStateHistory destructor.

    Declaration
    protected ~InputStateHistory()

    GetEnumerator()

    Enumerate all state history records.

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

    An enumerator going over the state history records.

    Remarks

    Enumerate all state history records.

    See Also
    GetEnumerator()

    RecordStateChange(InputControl<TValue>, TValue, double)

    Record a state change for a specific control.

    Declaration
    public InputStateHistory<TValue>.Record RecordStateChange(InputControl<TValue> control, TValue value, double time = -1)
    Parameters
    Type Name Description
    InputControl<TValue> control

    The control to record the state change for.

    TValue value

    The value to record.

    double time

    Time stamp to apply (overriding the event timestamp)

    Returns
    Type Description
    InputStateHistory<TValue>.Record

    The newly added record.

    Remarks

    Record a state change for a specific control. Will call the onRecordAdded delegate after adding the record. Note this does not call the onShouldRecordStateChange delegate.

    Examples
    using (var allTouchTaps = new InputStateHistory<float>(Gamepad.current.leftTrigger))
    {
        history.RecordStateChange(Gamepad.current.leftTrigger, 0.234f);
    }

    Implements

    IDisposable
    IEnumerable<T>
    IInputStateChangeMonitor
    IReadOnlyList<T>
    IReadOnlyCollection<T>
    IEnumerable<T>
    IEnumerable

    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(int?)
      • InputStateHistory(string)
      • InputStateHistory(InputControl<TValue>)
    • Properties
      • this[int]
    • Methods
      • AddRecord(Record)
      • ~InputStateHistory()
      • GetEnumerator()
      • RecordStateChange(InputControl<TValue>, TValue, double)
    • Implements
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)