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

Implements: UnityEngine.ISerializationCallbackReceiver

Quick Lookup

Goal
How

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.

Parameter
Type
Description

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.

Parameter
Type
Description

type

Type

The value type

name

string

Unique variable name

value

object

Optional initial value

circle-exclamation

RemoveVariable

Removes a dynamic variable by name. Cannot remove field variables.

Parameter
Type
Description

name

string

Name of the variable to remove

Returns: true if the variable was found and removed; false otherwise.

circle-exclamation

SetVariableValue

Sets the value of a variable by name. Searches field variables first, then dynamic variables.

Parameter
Type
Description

name

string

Variable name

value

object

Value to assign

circle-exclamation

GetVariableValue<TValue>

Gets a variable's value by name, cast to the specified type.

Parameter
Type
Description

name

string

Variable name

Returns: The value cast to TValue.

circle-exclamation

HasVariable

Checks whether a variable exists by name across both field and dynamic dictionaries.

Parameter
Type
Description

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.

Parameter
Type
Description

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.

circle-info

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

circle-exclamation
circle-exclamation
circle-exclamation

Examples

Managing Variables at Runtime

Iterating Variables

See Also

Last updated