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:

      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:

        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
        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
        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
        int snapshotOffset
        int snapshotSize
        IntPtr changeMask
        int maskOffset
        int changeMaskBits

        ConvertToUnsafeList(IntPtr, int)

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

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

        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
        int offset
        int numBits
        Returns
        Type Description
        uint

        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
        uint src
        int offset
        int numBits

        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
        Returns
        Type Description
        IntPtr
        Type Parameters
        Name Description
        T

        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
        int offset
        int numBits

        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
        Returns
        Type Description
        int
        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
        Returns
        Type Description
        int

        SnapshotSizeAligned(uint)

        Align the give size to 16 byte boundary

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

        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
        int offset
        Returns
        Type Description
        T
        Type Parameters
        Name Description
        T

        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
        int offset
        Returns
        Type Description
        T
        Type Parameters
        Name Description
        T
        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)