ActionVariables
Container that manages all ActionVariable instances for a single Action. It maintains two dictionaries — one for field-backed variables (discovered via reflection) and one for dynamically created variables — and provides a unified API for reading, writing, querying, and iterating variables by name.
Implements ISerializationCallbackReceiver to refresh field variables after Unity deserialization.
Definition
Namespace: Paragon.Core.ActionSystem Assembly: Paragon.dll
[Serializable]
public class ActionVariables : ISerializationCallbackReceiverImplements: UnityEngine.ISerializationCallbackReceiver
Quick Lookup
Add a runtime variable
actionVariables.AddVariable(typeof(int), "name", 0)
Remove a runtime variable
actionVariables.RemoveVariable("name")
Set a variable's value
actionVariables.SetVariableValue("name", value)
Get a typed value
actionVariables.GetVariableValue<float>("name")
Check if a variable exists
actionVariables.HasVariable("name")
Sync field variables before use
actionVariables.ApplyFieldVariables()
Iterate all variables
foreach (var v in actionVariables.GetAllVariables())
Filter by type
actionVariables.GetAllVariablesOfType(typeof(Transform))
Properties
FieldVariableCount
Number of field-backed variables discovered via reflection.
DynamicVariableCount
Number of dynamically added variables.
Constructor
ActionVariables(Action)
Creates the container for the given action and immediately discovers all field variables via reflection.
action
Action
The action whose [Variable]-marked fields will be discovered
Methods
AddVariable
Creates and registers a new DynamicVariable-backed ActionVariable with the given type, name, and optional initial value.
type
Type
The value type
name
string
Unique variable name
value
object
Optional initial value
Duplicate name check: Logs an error and returns without adding if a variable with the same name already exists (field or dynamic).
RemoveVariable
Removes a dynamic variable by name. Cannot remove field variables.
name
string
Name of the variable to remove
Returns: true if the variable was found and removed; false otherwise.
Not found: Logs an error if no variable with the given name exists.
SetVariableValue
Sets the value of a variable by name. Searches field variables first, then dynamic variables.
name
string
Variable name
value
object
Value to assign
Not found: Logs an error if no variable with the given name exists in either dictionary.
GetVariableValue<TValue>
Gets a variable's value by name, cast to the specified type.
name
string
Variable name
Returns: The value cast to TValue.
Throws ArgumentException if no variable with the given name exists.
HasVariable
Checks whether a variable exists by name across both field and dynamic dictionaries.
name
string
Variable name to check
Returns: true if a variable with that name exists.
ApplyFieldVariables
Calls UpdateValue() on every field variable, syncing referenced values back to the actual action fields. Called automatically by Action.ExecuteAsync() before execution begins.
GetAllVariables
Returns all variables (field and dynamic) as a single enumerable.
Returns: Union of field variables and dynamic variables.
GetAllVariablesOfType
Filters all variables to those matching the specified type.
type
Type
The type to filter by (exact match)
Returns: Variables whose Type equals the given type.
Serialization Behavior
ActionVariables implements ISerializationCallbackReceiver:
OnBeforeSerialize — No-op.
OnAfterDeserialize — Calls
UpdateFieldVariables()to re-discover and reconcile field variables with the action's current fields. This handles cases where fields are added, removed, or change type between serialization cycles.
Field variable reconciliation preserves existing ActionVariable instances (and their references) when the field name and type still match. Only mismatched or new fields get fresh instances.
Common Pitfalls
Duplicate variable names across field and dynamic Field variables are discovered automatically from [Variable]-marked fields. If you call AddVariable() with a name that matches a field variable, the add will be rejected with an error log. Choose unique names for dynamic variables.
RemoveVariable only works for dynamic variables RemoveVariable() removes from the dynamicVariables dictionary only. Field variables cannot be removed — they are managed by reflection discovery.
GetVariableValue throws on missing name Unlike SetVariableValue (which logs an error), GetVariableValue<T>() throws an ArgumentException if the name is not found. Use HasVariable() to check first if uncertain.
Examples
Managing Variables at Runtime
Iterating Variables
See Also
ActionVariable — the individual variable wrapper
Action — the base class that owns an
ActionVariablesinstanceAction Variables Subsystem — subsystem overview
Last updated