docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class GhostVariantsUtility

    Collection of utility that are used by the editor and runtime to compute and check ghost component variants hashes.

    Inheritance
    object
    GhostVariantsUtility
    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 GhostVariantsUtility

    Fields

    ClientOnlyHash

    Stable hash of the built-in ClientOnlyVariant. Use this from a baker to force a component to be client-only.

    Declaration
    public static readonly ulong ClientOnlyHash
    Field Value
    Type Description
    ulong

    DontSerializeHash

    Stable hash of the built-in DontSerializeVariant. Use this from a baker to mark a component as non-serialized.

    Declaration
    public static readonly ulong DontSerializeHash
    Field Value
    Type Description
    ulong

    ServerOnlyHash

    Stable hash of the built-in ServerOnlyVariant. Use this from a baker to force a component to be server-only.

    Declaration
    public static readonly ulong ServerOnlyHash
    Field Value
    Type Description
    ulong

    Methods

    CalculateVariantHashForComponent(ComponentType)

    Calculates the "variant hash" for the component type itself, so that we can fetch the meta-data.

    Declaration
    public static ulong CalculateVariantHashForComponent(ComponentType componentType)
    Parameters
    Type Name Description
    ComponentType componentType

    The ComponentType to be used for both the component, and the variant.

    Returns
    Type Description
    ulong

    The calculated hash.

    Remarks

    It's a little odd, but the default serializer for a Component is the ComponentType itself. I.e. It is its own variant.

    ResolveVariantHashFromType(Type, ComponentType)

    Resolves a variant Type to its ulong hash for a given component, honoring the well-known special variants (DontSerializeVariant, ClientOnlyVariant, ServerOnlyVariant) and falling through to UncheckedVariantHashNBC(Type, ComponentType). Returns 0 when variantType is null.

    Declaration
    [ExcludeFromBurstCompatTesting("Use managed types")]
    public static ulong ResolveVariantHashFromType(Type variantType, ComponentType componentType)
    Parameters
    Type Name Description
    Type variantType

    The managed variant type to resolve. Pass null to receive 0; pass one of the well-known special variants to receive the precomputed hash; pass any other type to fall through to UncheckedVariantHashNBC(Type, ComponentType).

    ComponentType componentType

    The component type the variant applies to. Used as the second hash input for the fall-through path; ignored for the well-known special variants.

    Returns
    Type Description
    ulong

    The resolved variant hash, or 0 if variantType is null.

    Remarks

    Single-source-of-truth for converting a managed variant type into its on-disk hash; used by both DefaultVariantSystemBase.Rule and the baker-side AppendOverride<TVariant> extension.

    UncheckedVariantHash(ulong, ComponentType)

    Calculates the "variant hash" for the variant + component pair.

    Declaration
    public static ulong UncheckedVariantHash(ulong variantTypeHash, ComponentType componentType)
    Parameters
    Type Name Description
    ulong variantTypeHash

    The hash of the Variant Type's System.Type.FullName.

    ComponentType componentType

    The ComponentType that this variant applies to.

    Returns
    Type Description
    ulong

    The calculated hash.

    UncheckedVariantHash(in FixedString512Bytes, in FixedString512Bytes)

    Calculates the "variant hash" for the variant + component pair.

    Declaration
    public static ulong UncheckedVariantHash(in FixedString512Bytes variantTypeFullName, in FixedString512Bytes componentTypeFullName)
    Parameters
    Type Name Description
    FixedString512Bytes variantTypeFullName

    The Variant Type's System.Type.FullName.

    FixedString512Bytes componentTypeFullName

    The Component Type's System.Type.FullName that this variant applies to.

    Returns
    Type Description
    ulong

    The calculated hash.

    UncheckedVariantHash(in FixedString512Bytes, ComponentType)

    Calculates a stable hash for a variant via Unity.Entities.TypeManager.GetTypeNameFixed(Unity.Entities.TypeIndex).

    Declaration
    public static ulong UncheckedVariantHash(in FixedString512Bytes variantTypeFullName, ComponentType componentType)
    Parameters
    Type Name Description
    FixedString512Bytes variantTypeFullName

    The Variant Type's FullName.

    ComponentType componentType

    The ComponentType that this variant applies to.

    Returns
    Type Description
    ulong

    The calculated hash.

    UncheckedVariantHashNBC(string, string)

    Calculates the "variant hash" for the variant + component pair. Non-Burst Compatible version.

    Declaration
    [ExcludeFromBurstCompatTesting("Use managed types")]
    public static ulong UncheckedVariantHashNBC(string variantTypeFullName, string componentTypeFullName)
    Parameters
    Type Name Description
    string variantTypeFullName

    The Variant Type's System.Type.FullName.

    string componentTypeFullName

    The Component Type's System.Type.FullName that this variant applies to.

    Returns
    Type Description
    ulong

    The calculated hash.

    Remarks

    This method is not Burst Compatible.

    UncheckedVariantHashNBC(Type, ComponentType)

    Calculates a stable hash for a variant by combining the variant Type.Fullname and Unity.Entities.ComponentType name hash Unity.Entities.TypeManager.GetFullNameHash(Unity.Entities.TypeIndex).

    Declaration
    [ExcludeFromBurstCompatTesting("Use managed types")]
    public static ulong UncheckedVariantHashNBC(Type variantStructDeclaration, ComponentType componentType)
    Parameters
    Type Name Description
    Type variantStructDeclaration

    The Variant struct declaration type.

    ComponentType componentType

    The ComponentType that this variant applies to.

    Returns
    Type Description
    ulong

    The calculated hash.

    In This Article
    Back to top
    Copyright © 2026 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)