docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class GhostComponentVariationAttribute

    Generate a serialization variant for a component using the GhostFieldAttribute annotations present in variant declaration. The component variant can be assigned at authoring time using the GhostAuthoringComponent editor.

    Note: This is incompatible with any type implementing DontSupportPrefabOverridesAttribute.

    Inheritance
    object
    Attribute
    GhostComponentVariationAttribute
    Inherited Members
    Attribute.Equals(object)
    Attribute.GetCustomAttribute(Assembly, Type)
    Attribute.GetCustomAttribute(Assembly, Type, bool)
    Attribute.GetCustomAttribute(MemberInfo, Type)
    Attribute.GetCustomAttribute(MemberInfo, Type, bool)
    Attribute.GetCustomAttribute(Module, Type)
    Attribute.GetCustomAttribute(Module, Type, bool)
    Attribute.GetCustomAttribute(ParameterInfo, Type)
    Attribute.GetCustomAttribute(ParameterInfo, Type, bool)
    Attribute.GetCustomAttributes(Assembly)
    Attribute.GetCustomAttributes(Assembly, bool)
    Attribute.GetCustomAttributes(Assembly, Type)
    Attribute.GetCustomAttributes(Assembly, Type, bool)
    Attribute.GetCustomAttributes(MemberInfo)
    Attribute.GetCustomAttributes(MemberInfo, bool)
    Attribute.GetCustomAttributes(MemberInfo, Type)
    Attribute.GetCustomAttributes(MemberInfo, Type, bool)
    Attribute.GetCustomAttributes(Module)
    Attribute.GetCustomAttributes(Module, bool)
    Attribute.GetCustomAttributes(Module, Type)
    Attribute.GetCustomAttributes(Module, Type, bool)
    Attribute.GetCustomAttributes(ParameterInfo)
    Attribute.GetCustomAttributes(ParameterInfo, bool)
    Attribute.GetCustomAttributes(ParameterInfo, Type)
    Attribute.GetCustomAttributes(ParameterInfo, Type, bool)
    Attribute.GetHashCode()
    Attribute.IsDefaultAttribute()
    Attribute.IsDefined(Assembly, Type)
    Attribute.IsDefined(Assembly, Type, bool)
    Attribute.IsDefined(MemberInfo, Type)
    Attribute.IsDefined(MemberInfo, Type, bool)
    Attribute.IsDefined(Module, Type)
    Attribute.IsDefined(Module, Type, bool)
    Attribute.IsDefined(ParameterInfo, Type)
    Attribute.IsDefined(ParameterInfo, Type, bool)
    Attribute.Match(object)
    Attribute.TypeId
    object.Equals(object, object)
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    Namespace: Unity.NetCode
    Assembly: Unity.NetCode.dll
    Syntax
    [AttributeUsage(AttributeTargets.Struct)]
    public class GhostComponentVariationAttribute : Attribute
    Remarks

    When declaring a variant, all fields that should be serialized must be declared. Any missing field or new field not present in the original struct will not be serialized.

    Constructors

    GhostComponentVariationAttribute(Type, string, bool)

    Initialize and declare the variant for a given component type. We can't constrain on a specific interface, thus, the validation is done at compile time in the constructor (for now).

    Declaration
    public GhostComponentVariationAttribute(Type componentType, string displayName = null, bool isTestVariant = false)
    Parameters
    Type Name Description
    Type componentType

    ComponentType

    string displayName

    DisplayName

    bool isTestVariant

    IsTestVariant

    Fields

    ComponentType

    Type that this variant is overriding. Assigned at construction time.

    Declaration
    public readonly Type ComponentType
    Field Value
    Type Description
    Type

    Properties

    DisplayName

    User friendly, readable name for the variant. Used mainly for UI and logging purposes. If not assigned at construction time, the annotated class name will be used instead. "Default", "ClientOnly" and "DontSerialize" are not valid names and will be treated as null.

    Declaration
    public string DisplayName { get; }
    Property Value
    Type Description
    string
    Examples

    "Translation - 2D"

    IsTestVariant

    True if editor-only. Hides it in the user-facing dropdown. If true; we'll set this variant as the default in the editor, assuming we're unable to find a "proper" default.

    Declaration
    public bool IsTestVariant { get; }
    Property Value
    Type Description
    bool

    VariantHash

    The unique hash for the component variation. The hash is computed at compile time (assigned to the generated serialization class) and then assigned at runtime to the attribute when all the variant are registered by the GhostComponentSerializerCollectionSystemGroup. The hash itself is then used at both edit and runtime to identify the variation used for each component.

    Declaration
    public ulong VariantHash { get; }
    Property Value
    Type Description
    ulong
    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)