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.
Inherited Members
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 | |
string | displayName | |
bool | 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 |