docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class InputStateHistory

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

    Inheritance
    object
    InputStateHistory
    InputStateHistory<TValue>
    Implements
    IDisposable
    IEnumerable<InputStateHistory.Record>
    IEnumerable
    IInputStateChangeMonitor
    Namespace: UnityEngine.InputSystem.LowLevel
    Assembly: Unity.InputSystem.dll
    Syntax
    public class InputStateHistory : IDisposable, IEnumerable<InputStateHistory.Record>, IEnumerable, 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(int)

    Declaration
    public InputStateHistory(int maxStateSizeInBytes)
    Parameters
    Type Name Description
    int 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

    Count

    Total number of state records currently captured in the history.

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

    Number of records in the collection.

    Remarks

    This will always be at most historyDepth.

    See Also
    historyDepth
    RecordStateChange(InputControl, InputEventPtr)

    this[int]

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

    controls

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

    extraMemoryPerRecord

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

    historyDepth

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

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

    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

    Exceptions
    Type Condition
    ArgumentException

    value is negative.

    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, bool>

    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
    uint

    Version stamp that indicates the number of mutations.

    See Also
    RecordStateChange(InputControl, InputEventPtr)

    Methods

    AddRecord(Record)

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

    AllocateRecord(out int)

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

    Clear()

    Declaration
    public void Clear()

    Destroy()

    Declaration
    protected void Destroy()

    Dispose()

    Declaration
    public void Dispose()

    ~InputStateHistory()

    Declaration
    protected ~InputStateHistory()

    GetEnumerator()

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

    GetRecord(int)

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

    ReadValueAsObject(RecordHeader*)

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

    ReadValue<TValue>(RecordHeader*)

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

    RecordIndexToUserIndex(int)

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

    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(int)

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

    Implements

    IDisposable
    IEnumerable<T>
    IEnumerable
    IInputStateChangeMonitor

    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(int)
      • InputStateHistory(string)
      • InputStateHistory(InputControl)
    • Properties
      • Count
      • this[int]
      • controls
      • extraMemoryPerRecord
      • historyDepth
      • onRecordAdded
      • onShouldRecordStateChange
      • updateMask
      • version
    • Methods
      • AddRecord(Record)
      • AllocateRecord(out int)
      • Clear()
      • Destroy()
      • Dispose()
      • ~InputStateHistory()
      • GetEnumerator()
      • GetRecord(int)
      • ReadValueAsObject(RecordHeader*)
      • ReadValue<TValue>(RecordHeader*)
      • RecordIndexToUserIndex(int)
      • RecordStateChange(InputControl, void*, double)
      • RecordStateChange(InputControl, InputEventPtr)
      • StartRecording()
      • StopRecording()
      • UserIndexToRecordIndex(int)
    • Implements
    Back to top
    Copyright © 2024 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)