VariableAttribute
Custom attribute that marks a field on an Action subclass for automatic discovery by the variable system. Fields decorated with [Variable] are reflected at construction time, wrapped as FieldVariable instances, and exposed through ActionVariables for Inspector editing and runtime binding.
Definition
Namespace: Paragon.Core.ActionSystem Assembly: Paragon.dll
[AttributeUsage(AttributeTargets.Field)]
public class VariableAttribute : OdinSerializeAttributeInherits: Sirenix.Serialization.OdinSerializeAttribute → VariableAttribute
Remarks
VariableAttribute serves a dual purpose:
Variable system marker — The ActionVariables system uses reflection to find all fields with this attribute and creates FieldVariable wrappers for them. This enables Inspector-driven configuration and runtime get/set via
Action.SetVariable<T>()/Action.GetVariable<T>().Odin serialization — By inheriting from
OdinSerializeAttribute, the attribute also opts the field into Odin Serializer's serialization pipeline. This means[Variable]fields support serialization of types that Unity's default serializer cannot handle (interfaces, abstract types, polymorphic collections, dictionaries, etc.).
Single attribute, two effects. You do NOT need to add both [Variable] and [OdinSerialize] — the [Variable] attribute already inherits from OdinSerializeAttribute and provides both behaviors.
Quick Lookup
Expose a field as a variable
Add [Variable] attribute to the field
Supported field access
Both public and private fields
Supported types
Any serializable type (primitives, Unity objects, custom classes/structs, collections)
Read variable at runtime
action.GetVariable<T>("fieldName")
Write variable at runtime
action.SetVariable("fieldName", value)
Usage
Attribute Target
[Variable] can only be applied to fields (AttributeTargets.Field). It cannot be applied to properties, methods, or classes.
Supported Field Types
The variable system supports any type that Odin Serializer can handle:
Primitives
bool, int, float, string
Unity types
Vector3, GameObject, Transform, Color
Custom classes
Any [Serializable] class
Custom structs
Any [Serializable] struct
Collections
List<T>, Dictionary<K,V>, arrays
Self-referencing
Action (the action system's own base type)
Interfaces / abstract
Supported via Odin polymorphic serialization
Field Visibility
Both public and private fields are discovered. The reflection lookup uses BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic.
Common Pitfalls
Do not combine with [OdinSerialize] [Variable] already inherits from OdinSerializeAttribute. Adding both attributes to the same field will cause duplicate serialization entries and may lead to unexpected behavior.
Variable name matches field name The variable name used in SetVariable / GetVariable is the exact field name (case-sensitive). Renaming a field without updating variable references will cause ArgumentException at runtime.
Properties are not supported [Variable] uses AttributeTargets.Field — it will compile on auto-properties but the reflection discovery system only scans for fields with FieldInfo, so properties will be silently ignored.
Examples
Basic Variable Declaration
Multiple Type Examples
Runtime Variable Access
See Also
Variable — the abstract base class for variable storage
FieldVariable — the variable backend created for each
[Variable]-attributed fieldActionVariables — the container that discovers
[Variable]fields via reflectionAction — base class where
[Variable]fields are declaredVariable Subsystem — subfolder overview
Last updated