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 : OdinSerializeAttribute

Inherits: Sirenix.Serialization.OdinSerializeAttribute → VariableAttribute

Remarks

VariableAttribute serves a dual purpose:

  1. 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>().

  2. 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.).

circle-info

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

Goal
How

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:

Category
Examples

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

circle-exclamation
circle-exclamation
circle-exclamation

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 field

  • ActionVariables — the container that discovers [Variable] fields via reflection

  • Action — base class where [Variable] fields are declared

  • Variable Subsystem — subfolder overview

Last updated