docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class CommandDataUtility

    Contains utility methods to add and retrieve commands from ICommandData dynamic buffers.

    Inheritance
    object
    CommandDataUtility
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    Namespace: Unity.NetCode
    Assembly: Unity.NetCode.dll
    Syntax
    public static class CommandDataUtility

    Fields

    k_CommandDataMaxSize

    The maximum number of commands that can be sent in one single command packet.

    Declaration
    public const int k_CommandDataMaxSize = 64
    Field Value
    Type Description
    int

    Methods

    AddCommandData<T>(DynamicBuffer<T>, T)

    Add an instance of a ICommandData into the command circular buffer. The command buffer capacity if fixed and the Tick is used to find in which slot the command should be put to keep the command buffer sorted. If a command with the same tick already exists in the buffer, it will be overritten

    Declaration
    public static bool AddCommandData<T>(this DynamicBuffer<T> commandBuffer, T commandData) where T : unmanaged, ICommandData
    Parameters
    Type Name Description
    DynamicBuffer<T> commandBuffer

    The buffer being written to.

    T commandData

    The individual input struct to add.

    Returns
    Type Description
    bool

    True if we replaced an existing input at this exact tick value.

    Type Parameters
    Name Description
    T

    the command type

    GetDataAtTick<T>(DynamicBuffer<T>, NetworkTick, out T)

    Get latest command data for given target tick. For example, if command buffer contains ticks 3,4,5,6 and targetTick is 5 it will return tick 5 (latest without going over). If the command buffer is 1,2,3 and targetTick is 5 it will return tick 3.

    Declaration
    public static bool GetDataAtTick<T>(this DynamicBuffer<T> commandArray, NetworkTick targetTick, out T commandData) where T : unmanaged, ICommandData
    Parameters
    Type Name Description
    DynamicBuffer<T> commandArray

    Command input buffer.

    NetworkTick targetTick

    Target tick to fetch from.

    T commandData

    The last-received input.

    Returns
    Type Description
    bool

    Returns true if any data was found, false when no tick data is equal or older to the target tick in the buffer.

    Type Parameters
    Name Description
    T

    Command input buffer type.

    GetInputAtIndex<T>(DynamicBuffer<T>, int)

    Get a readonly reference to the input at the given index. Need to be used in safe context, where you know the buffer is not going to be modified. That would invalidate the reference in that case and we can't guaratee the data you are reading is going to be valid anymore.

    Declaration
    public static ref readonly T GetInputAtIndex<T>(this DynamicBuffer<T> buffer, int index) where T : unmanaged, ICommandData
    Parameters
    Type Name Description
    DynamicBuffer<T> buffer

    Buffer to index

    int index

    index to get input

    Returns
    Type Description
    T

    A readonly reference to the element

    Type Parameters
    Name Description
    T

    the command type

    In This Article
    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)