docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Struct GhostComponentSerializer

    Mostly for internal use. A collection helper functions used by code-gen and some runtime systems. See GhostSendSystem, GhostReceiveSystem, and others. To work with ghost snapshots, see SnapshotData and SnapshotDynamicDataBuffer. It also declares all the ghost component/buffers serializers delegate methods, that are used to register (at runtime) the code-generated serializers (to the GhostComponentSerializer.State collection).

    Inherited Members
    ValueType.Equals(object)
    ValueType.GetHashCode()
    object.Equals(object, object)
    object.GetType()
    object.ReferenceEquals(object, object)
    Namespace: Unity.NetCode.LowLevel.Unsafe
    Assembly: Unity.NetCode.dll
    Syntax
    public struct GhostComponentSerializer

    Fields

    DynamicBufferComponentMaskBits

    The number of change mask bits used the shadow buffer data. The change mask for the buffer is like this:

    • 00 : nothing change
    • 01 : len is the same, content has changed.
    • 10 : len is changed, we consider the content has changed too. (may change in the future).
    Declaration
    public const int DynamicBufferComponentMaskBits = 2
    Field Value
    Type Description
    int

    DynamicBufferComponentSnapshotSize

    Dynamic Buffer have a special entry in the snapshot data that is used to track the len and offset of the the buffer data inside the SnapshotDynamicDataBuffer buffer. This shadow component entry has the following format:

    • uint Length: the length of the buffer
    • uint Offset: the position in bytes from the beginning of the dynamic data buffer (for that specific history slot)
    Declaration
    public const int DynamicBufferComponentSnapshotSize = 8
    Field Value
    Type Description
    int

    Methods

    ChangeMaskArraySizeInBytes(int)

    Compute the number of bytes necessary to encode the required number of bits

    Declaration
    public static int ChangeMaskArraySizeInBytes(int numBits)
    Parameters
    Type Name Description
    int numBits

    Number of bits to convert.

    Returns
    Type Description
    int

    The min number of bytes to store this number of bits, rounded to the nearest 4 bytes (for data-alignment).

    ChangeMaskArraySizeInUInts(int)

    Compute the number of uint necessary to encode the required number of bits

    Declaration
    public static int ChangeMaskArraySizeInUInts(int numBits)
    Parameters
    Type Name Description
    int numBits

    Number of bits to convert.

    Returns
    Type Description
    int

    The uint mask to encode this number of bits.

    ClearSnapshotDataAndMask(IntPtr, int, int, IntPtr, int, int)

    Reset the changemask and the snapshot data to the default value (all 0)

    Declaration
    public static void ClearSnapshotDataAndMask(IntPtr snapshot, int snapshotOffset, int snapshotSize, IntPtr changeMask, int maskOffset, int changeMaskBits)
    Parameters
    Type Name Description
    IntPtr snapshot

    Snapshot data

    int snapshotOffset

    Snapshot offset

    int snapshotSize

    Snapshot size

    IntPtr changeMask

    Change mask

    int maskOffset

    Mask offset

    int changeMaskBits

    Change mask bits

    ConvertToUnsafeList(IntPtr, int)

    Helper method to construct an UnsafeList<T> from a given IntPtr and length.

    Declaration
    public static UnsafeList<float> ConvertToUnsafeList(IntPtr floatData, int len)
    Parameters
    Type Name Description
    IntPtr floatData

    Float data

    int len

    Number of bits to convert

    Returns
    Type Description
    UnsafeList<float>

    List of converted floats

    CopyFromChangeMask(IntPtr, int, int)

    Extract from the source buffer an unsigned integer, representing a portion of a bitmask starting from the given offset and number of bits (up to 32 bits max).

    Declaration
    public static uint CopyFromChangeMask(IntPtr bitData, int offset, int numBits)
    Parameters
    Type Name Description
    IntPtr bitData

    Bitmask array

    int offset

    Offset to extract integer

    int numBits

    Number of bits to extract

    Returns
    Type Description
    uint

    Extracted unsigned integer

    CopyToChangeMask(IntPtr, uint, int, int)

    For internal use only, copy the src bitmask to a destination buffer, to the given offset and for the required number of bits.

    Declaration
    public static void CopyToChangeMask(IntPtr bitData, uint src, int offset, int numBits)
    Parameters
    Type Name Description
    IntPtr bitData

    Destination buffer

    uint src

    Bitmask

    int offset

    Offset to copy to

    int numBits

    Number of bits to copy

    GetDeltaCompressedSizeInBits(uint, uint, in StreamCompressionModel)

    The compressed size in bits necessary to encode a given unsigned int value in delta in respect to the given baseline.

    Declaration
    public static int GetDeltaCompressedSizeInBits(uint value, uint baseline, in StreamCompressionModel model)
    Parameters
    Type Name Description
    uint value

    the value to encode

    uint baseline

    the baseline used to calculate the delta

    StreamCompressionModel model

    the compression model to use

    Returns
    Type Description
    int

    the number of bits necessary to encode the value

    IntPtrCast<T>(ref T)

    Return a pointer to the memory address for the given value instance.

    Declaration
    public static IntPtr IntPtrCast<T>(ref T value) where T : struct
    Parameters
    Type Name Description
    T value

    Data

    Returns
    Type Description
    IntPtr

    Reference to component type in data

    Type Parameters
    Name Description
    T

    Component type

    ResetChangeMask(IntPtr, int, int)

    For internal use only, reset the bitData bitmask bits from the given offset and for the required number of bits.

    Declaration
    public static void ResetChangeMask(IntPtr bitData, int offset, int numBits)
    Parameters
    Type Name Description
    IntPtr bitData

    Bitmask

    int offset

    Offset

    int numBits

    Number of bits

    ResetEntityStartBits(int, ref DataStreamWriter, IntPtr)

    For internal use only (mostly code gen), reset the recorded start and end position in the compressed bit stream for each individual entity.

    Declaration
    public static void ResetEntityStartBits(int count, ref DataStreamWriter writer, IntPtr entityStartBit)
    Parameters
    Type Name Description
    int count

    the lenght of the entityStartBits array to reset

    DataStreamWriter writer

    the output stream

    IntPtr entityStartBit

    the array of start/end offset pair to reset

    SizeInSnapshot(in State)

    Helper that returns the size in bytes (aligned to 16 bytes boundary) used to store the component data inside SnapshotData.

    Declaration
    public static int SizeInSnapshot(in GhostComponentSerializer.State serializer)
    Parameters
    Type Name Description
    GhostComponentSerializer.State serializer

    Serializer state

    Returns
    Type Description
    int

    Size in bytes (aligned to 16 bytes boundary)

    Remarks

    For buffers in particular, the SnapshotData contains only offset and length information (the buffer data resides inside the SnapshotDynamicDataBuffer), and the reported size is always equal to the DynamicBufferComponentSnapshotSize.

    SnapshotSizeAligned(int)

    Align the give size to 16 byte boundary.

    Declaration
    public static int SnapshotSizeAligned(int size)
    Parameters
    Type Name Description
    int size

    Size to align

    Returns
    Type Description
    int

    New size aligned to 16 byte

    SnapshotSizeAligned(uint)

    Align the give size to 16 byte boundary

    Declaration
    public static uint SnapshotSizeAligned(uint size)
    Parameters
    Type Name Description
    uint size

    Size to align

    Returns
    Type Description
    uint

    New size aligned to 16 byte

    TypeCastReadonly<T>(IntPtr, int)

    Helper method to get a reference to a struct data from its address in memory.

    Declaration
    public static ref readonly T TypeCastReadonly<T>(IntPtr value, int offset = 0) where T : struct
    Parameters
    Type Name Description
    IntPtr value

    Data

    int offset

    Offset

    Returns
    Type Description
    T

    Reference to component type in data

    Type Parameters
    Name Description
    T

    Component type

    TypeCast<T>(IntPtr, int)

    Helper method to get a reference to a struct data from its address in memory.

    Declaration
    public static ref T TypeCast<T>(IntPtr value, int offset = 0) where T : struct
    Parameters
    Type Name Description
    IntPtr value

    Data

    int offset

    Offset

    Returns
    Type Description
    T

    Reference to component type in data

    Type Parameters
    Name Description
    T

    Component 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)