Overview

image

Unity package library for sharing variable data across components and scenes, allowing other components to react to changes in values.

Heavily inspired by the infamous Unite 2017: Game Architecture with Scriptable Objects presentation by Ryan Hipple (GitHub).

Unfortunately Unity does not understand generics in the Editor and Inspectors, so only concrete types can be used. Fortunately, this can be made easy by deriving from a single generic type allowing the same common behaviors.

NOTE: This package is still in development and may have breaking changes in future versions until a stable v1.0.0 release is made.

Changelog

All notable changes to this library will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

[0.6.2] - 2022-12-28

Added

  • ScriptableObjectVariable variant
  • ScriptableObjectWatcher component
  • Icons for variables in the Editor
  • Icons for watcher components in the Editor

[0.6.1] - 2022-12-08

Fixed

  • Missing meta files

[0.6.0] - 2022-12-06

Added

  • IObservable interface
  • ObservableObject class
  • ObservableWatcher component
  • Observables sample scene

[0.5.0] - 2022-12-03

Added

  • ColorVariable variant
  • ColorVariableWatcher component
  • ColorReference variant
  • Vector2IntVariable variant
  • Vector2IntVariableWatcher component
  • Vector2IntReference variant
  • Vector2Variable variant
  • Vector2VariableWatcher component
  • Vector2Reference variant
  • Vector3Variable variant
  • Vector3VariableWatcher component
  • Vector3Reference variant
  • Vector4Variable variant
  • Vector4VariableWatcher component
  • Vector4Reference variant
  • SetPosition(Vector3Variable) method to TransformVariable class
  • Custom editors for new types

Changed

  • Exposed Variable getter property on RuntimeVariableWatcher component

[0.4.2] - 2022-12-03

Added

  • isReadOnly and IsReadOnly property to RuntimeVariable base class
  • MakeReadOnly() method to RuntimeVariable base class

[0.4.1] - 2022-12-02

Added

  • Docs via mdbook in Documentation~ directory
  • GitHub CI/CD workflows for documentation

[0.4.0] - 2022-11-30

Added

  • RuntimeVariableEditor<T> abstract base class
  • BoolVariableEditor custom editor
  • DoubleVariableEditor custom editor
  • FloatVariableEditor custom editor
  • IntVariableEditor custom editor
  • StringVariableEditor custom editor
  • TransformVariableEditor custom editor
  • RuntimeReferenceDrawer custom property drawer
  • RuntimeVariableWatcherEditor<T, TVar> abstract base class
  • BoolVariableWatcherEditor custom editor
  • DoubleVariableWatcherEditor custom editor
  • FloatVariableWatcherEditor custom editor
  • IntVariableWatcherEditor custom editor
  • StringVariableWatcherEditor custom editor
  • TransformVariableWatcherEditor custom editor
  • raiseOnAwake property to RuntimeVariableWatcher base class

[0.3.0] - 2022-11-30

Added

  • RuntimeReference<T> abstract base class
  • BoolReference variant
  • DoubleReference variant
  • FloatReference variant
  • IntReference variant
  • StringReference variant
  • TransformReference variant
  • CopyFrom(BoolVariable) method to BoolVariable
  • CopyFrom(IntVariable) method to DoubleVariable
  • CopyFrom(FloatVariable) method to DoubleVariable
  • CopyFrom(DoubleVariable) method to DoubleVariable
  • CopyFrom(IntVariable) method to FloatVariable
  • CopyFrom(FloatVariable) method to FloatVariable
  • CopyFrom(IntVariable) method to IntVariable
  • CopyFrom(StringVariable) method to StringVariable
  • CopyFrom(TransformVariable) method to TransformVariable
  • CopyTo(BoolVariable) method to BoolVariable
  • CopyTo(DoubleVariable) method to DoubleVariable
  • CopyTo(DoubleVariable) method to FloatVariable
  • CopyTo(FloatVariable) method to FloatVariable
  • CopyTo(IntVariable) method to IntVariable
  • CopyTo(FloatVariable) method to IntVariable
  • CopyTo(DoubleVariable) method to IntVariable
  • CopyTo(StringVariable) method to StringVariable
  • CopyTo(TransformVariable) method to TransformVariable
  • SetValue(int) method to DoubleVariable
  • SetValue(float) method to DoubleVariable
  • SetStringValue(int) method to FloatVariable
  • Stringify(bool) method to StringVariable
  • Stringify(int) method to StringVariable
  • Stringify(float) method to StringVariable
  • Stringify(double) method to StringVariable
  • References sample scene

Fixed

  • Watchers sample scene UI elements

[0.2.1] - 2022-11-30

Changed

  • Renamed package to runtime-variables
  • Renamed Variable<T> to RuntimeVariable<T> for consistency
  • Renamed VariableWatcher<T> to RuntimeVariableWatcher<T> for consistency

[0.2.0] - 2022-11-30

Added

  • VariableWatcher<T> abstract base class
  • BoolVariableWatcher component
  • DoubleVariableWatcher component
  • FloatVariableWatcher component
  • IntVariableWatcher component
  • StringVariableWatcher component
  • TransformVariableWatcher component
  • Watchers sample scene

[0.1.0] - 2022-11-29

Added

  • Variable<T> abstract base class
  • BoolVariable variant
  • DoubleVariable variant
  • FloatVariable variant
  • IntVariable variant
  • StringVariable variant
  • TransformVariable variant
  • Variables sample scene

Installation

OpenUPM

OpenUPM is an open source Unity package registry that allows you to easily install thousands of packages.

You can install this library with the following CLI command:

$ openupm add com.underlogic.runtime-variables

Git URL

Starting with Unity 2019.3 you can add packages via git url. You can add this package by the following url: https://github.com/UnderLogic/runtime-variables

Using this method will allow you to update the package through the Unity Package Manager.

Local Package

Alternatively, you can clone the git repository and add the package locally.

Getting Started

Context

To best understand the purpose of this library and the problems it solves, it is highly recommended to watch the Unite 2017: Game Architecture with Scriptable Objects by Ryan Hipple.

Use Cases

Shared Data

The common case of needing to share data between various components, potentially across multiple scenes. Easy to drag and drop references in the Editor and view/modify them in the Inspector during play mode.

See runtime-collections library in the related-libraries section for working with collections.

Complex Types

The common case of needing to represent a complex data type with various types of fields. Using the ObservableObject allows property value changes to be seen by other components.

Singleton

The common case of needing a single, global instance of data that can be accessed everywhere. This avoids the common pitfalls of traditional Unity singleton objects.

Event-Based Architecture

The case of only wanting to update or perform actions when necessary (reactively) instead of wastefully computing each frame. This is very common in UI-heavy applications.

See event-channels library in the related-libraries section for working with an event bus.

Quick Prototyping

The case of being able to swap between constant and variable values on the fly, allowing rapid prototyping and tweaking. By using references you can avoid refactoring components or having to restart your application to test each change.

Samples

The Samples~ folder contains sample scenes showcasing various aspects of the library in action. It is recommended to import and play around with them in Unity to get a feel for how to use the library.

Custom Types

While this library provides many of the common Unity types you will use, you may want to extend this library with your own custom types specific to your application. Fortunately, this is rather easy and typically only involves creating a derived class from one of the base classes. You may also add any additional helper properties and methods as you need.

Variables

  1. Create a new class that derives from RuntimeVariable<T>, where T should be the type you wish to wrap.
  2. Ensure the new type is marked with the CreateAssetMenu attribute, so you can create instances in the Editor.
  3. Create any instances of the new variable in your Assets folder.
  4. Configure the isReadOnly and initialValue as needed.
  5. Now you can use them throughout your application.

NOTE: While most people create ScriptableObject instances in the Editor, you can create them at runtime as well!

Observables

  1. Create a new class that derives from ObservableObject.
  2. Add private backing fields and public accessor properties.
  3. Use the TrySetProperty() method in the property set block.
  4. Optionally raise events via RaisePropertyChanged() method for any computed properties.
  5. Ensure the new type is marked with the CreateAssetMenu attribute, so you can create instances in the Editor.
  6. Create any instances of the new variable in your Assets folder.
  7. Now you can use them throughout your application.

References

  1. Create a new class that derives from RuntimeReference<T, TVar> where T should be the underlying type and TVar is the variable type.
  2. Ensure the new type is marked with the Serializable attribute, so it appears in the Inspector.
  3. Now you can use the reference in your components.

Editor

For the custom Inspector GUI to work you will need to create a new custom property drawer class. You can reuse the RuntimeReferencePropertyDrawer class.

  1. Create a new class that derives from RuntimeReferenceProperyDrawer.
  2. Ensure the new class is marked with the CustomPropertyDrawer attribute for your custom reference type.

NOTE: You can mark this custom property drawer as the CustomPropertyDrawer for multiple reference types. No need to create multiple variants unless you explicitly need them to behave differently.

Watchers

  1. Create a new class that derives from RuntimeVariableWatcher<T, TVar>, where T should be the underlying type and TVar is the variable type.
  2. You can now use the watcher component in your scenes.

Editor

For the custom Inspector GUI to work you will need to create a new custom editor class. You can reuse the RuntimeVariableWatcherEditor<T, TVar> class.

  1. Create a new class that derives from RuntimeVariableWatcherEditor<T, TVar>, where T should be the underlying type and TVar is the variable type.
  2. Ensure the new type is marked with the CustomEditor attribute for your custom watcher type.

NOTE: Unlike the property drawer, a CustomEditor can only reference a single type. You will need to make a custom editor for each custom watcher you make.

Related Libraries

Variables

Overview

Runtime variables are implemented as ScriptableObject instances that can be used to share their data across components and scenes. They also provide UnityAction events when their value changes or is about to be changed.

Many of the variables provide helper mutator methods that make it easier to manipulate their values from other components, including UnityEvent bindings. This can be especially useful when using the Watcher components.

RuntimeVariable<T>

Abstract base class that all other runtime variables derive from.

Description

Represents an observable value T that can be shared and modified throughout the application.

Serialized Fields (Inspector)

  • isReadOnly : bool - Whether the variable can be mutated.
  • initialValue : T - Initial value of the variable, will be re-applied on restart.
  • value : T - The current value of the variable.

Public Properties

  • IsReadOnly : bool (get) - Whether the variable can be mutated.
  • InitialValue : T (get) - Initial value of the variable, will be re-applied on restart.
  • Value : T (get, set) - The current value of the variable.

Public Events

  • ValueChanging : UnityAction<T> - Raised when the value is about to change, providing the new value to be set.
  • ValueChanged : UnityAction<T> - Raised when the value has changed, providing the newly set value.

NOTE: These events are only raised when the new value is not equal to the existing value.

Public Methods

  • GetValue() : T - Returns the current value of the variable.
  • SetValue(T) - Sets the value of the variable.
  • SetInitial() - Sets the value of the variable to the initial value.
  • SetDefault() - Sets the value of the variable to the default(T) value.
  • MakeReadOnly() - Marks the variable as readonly, useful for freezing after initialization.
  • RaiseValueChanging(T) - Manually raises a ValueChanging event with the value provided.
  • RaiseValueChanged() - Manually raises a ValueChanged event with the current value.

NOTE: Trying to modify a readonly variable will result in an InvalidOperationException being thrown.

Public Operators

  • operator RuntimeVariable<T> : T (implicit) - Allows the variable to be unwrapped to the native type T without needing to explicitly cast it.

BoolVariable

Derives from RuntimeVariable<T>.

Description

Represents an observable bool value that can be shared and modified throughout the application.

Public Methods

  • Toggle() - Inverts the boolean value.
  • CopyFrom(BoolVariable) - Copies the value of another BoolVariable into this variable.
  • CopyTo(BoolVariable) - Copies the value from this variable into another BoolVariable.

ColorVariable

Derives from RuntimeVariable<T>.

Description

Represents an observable Color value that can be shared and modified throughout the application.

Public Methods

  • CopyFrom(ColorVariable) - Copies the value of another ColorVariable into this variable.
  • CopyTo(ColorVariable) - Copies the value from this variable into another ColorVariable.

DoubleVariable

Derives from RuntimeVariable<T>.

Description

Represents an observable double value that can be shared and modified throughout the application.

Public Methods

  • Add(int) - Adds a signed int value to the variable.
  • Add(float) - Adds a float value to the variable.
  • Add(double) - Adds a double value to the variable.
  • Subtract(int) - Subtracts a signed int value from the variable.
  • Subtract(float) - Subtracts a float value from the variable.
  • Subtract(double) - Subtracts a double value from the variable.
  • MultiplyBy(int) - Multiplies the variable by a signed int value.
  • MultiplyBy(float) - Multiplies the variable by a float value.
  • MultiplyBy(double) - Multiplies the variable by a double value.
  • DivideBy(int) - Divides the variable by a signed int value.
  • DivideBy(float) - Divides the variable by a float value.
  • DivideBy(double) - Divides the variable by a double value.
  • CopyFrom(IntVariable) - Copies the value of another IntVariable into this variable.
  • CopyFrom(FloatVariable) - Copies the value of another FloatVariable into this variable.
  • CopyFrom(DoubleVariable) - Copies the value of another DoubleVariable into this variable.
  • CopyTo(DoubleVariable) - Copies the value from this variable into another DoubleVariable.
  • SetValue(int) - Sets the value of this variable to a signed int value.
  • SetValue(float) - Sets the value of this variable to a float value.

FloatVariable

Derives from RuntimeVariable<T>.

Description

Represents an observable float value that can be shared and modified throughout the application.

Public Methods

  • Add(int) - Adds a signed int value to the variable.
  • Add(float) - Adds a float value to the variable.
  • Subtract(int) - Subtracts a signed int value from the variable.
  • Subtract(float) - Subtracts a float value from the variable.
  • MultiplyBy(int) - Multiplies the variable by a signed int value.
  • MultiplyBy(float) - Multiplies the variable by a float value.
  • DivideBy(int) - Divides the variable by a signed int value.
  • DivideBy(float) - Divides the variable by a float value.
  • CopyFrom(IntVariable) - Copies the value of another IntVariable into this variable.
  • CopyFrom(FloatVariable) - Copies the value of another FloatVariable into this variable.
  • CopyTo(FloatVariable) - Copies the value from this variable into another FloatVariable.
  • CopyTo(DoubleVariable) - Copies the value from this variable into another DoubleVariable.
  • SetValue(int) - Sets the value of this variable to a signed int value.

IntVariable

Derives from RuntimeVariable<T>.

Description

Represents an observable signed int value that can be shared and modified throughout the application.

Public Methods

  • Add(int) - Adds a signed int value to the variable.
  • Subtract(int) - Subtracts a signed int value from the variable.
  • MultiplyBy(int) - Multiplies the variable by a signed int value.
  • DivideBy(int) - Divides the variable by a signed int value.
  • CopyFrom(IntVariable) - Copies the value of another IntVariable into this variable.
  • CopyTo(IntVariable) - Copies the value from this variable into another IntVariable.
  • CopyTo(FloatVariable) - Copies the value from this variable into another FloatVariable.
  • CopyTo(DoubleVariable) - Copies the value from this variable into another DoubleVariable.

ScriptableObjectVariable

Derives from RuntimeVariable<T>.

Description

Represents an observable ScriptableObject value that can be shared and modified throughout the application.

This component does not have any additional members.

StringVariable

Derives from RuntimeVariable<T>.

Description

Represents an observable string value that can be shared and modified throughout the application.

Public Properties

  • IsNullOrEmpty : bool (get) - Whether the string is null or "".
  • IsNullOrWhiteSpace : bool (get) - Whether the string is null or whitespace (including empty);

Public Methods

  • CopyFrom(StringVariable) - Copies the value of another StringVariable into this variable.
  • CopyTo(StringVariable) - Copies the value from this variable into another StringVariable.
  • Stringify(bool) - Sets the value of this variable to the string representation of a bool value.
  • Stringify(int) - Sets the value of this variable to the string representation of a signed int value.
  • Stringify(float) - Sets the value of this variable to the string representation of a float value.
  • Stringify(double) - Sets the value of this variable to the string representation of a double value.

NOTE: The Stringify() methods will format the string using CultureInfo.CurrentCulture.

TransformVariable

Derives from RuntimeVariable<T>.

Description

Represents an observable Transform value that can be shared and modified throughout the application.

Public Methods

  • SetPosition(Vector3) - Sets the position of the Transform to a new Vector3 value.
  • SetPosition(Vector3Variable) - Sets the position of the Transform to the value of a Vector3Variable.
  • SetActive(bool) - Sets the active state of GameObject of the Transform.
  • CopyFrom(TransformVariable) - Copies the value of another TransformVariable into this variable.
  • CopyTo(TransformVariable) - Copies the value from this variable into another TransformVariable.

Vector2IntVariable

Derives from RuntimeVariable<T>.

Description

Represents an observable Vector2Int value that can be shared and modified throughout the application.

Public Methods

  • CopyFrom(Vector2IntVariable) - Copies the value of another Vector2IntVariable into this variable.
  • CopyTo(Vector2IntVariable) - Copies the value from this variable into another Vector2IntVariable.
  • CopyTo(Vector2Variable) - Copies the value from this variable into another Vector2Variable.
  • CopyTo(Vector3Variable) - Copies the value from this variable into another Vector3Variable.
  • CopyTo(Vector4Variable) - Copies the value from this variable into another Vector4Variable.

Vector2Variable

Derives from RuntimeVariable<T>.

Description

Represents an observable Vector2 value that can be shared and modified throughout the application.

Public Methods

  • CopyFrom(Vector2IntVariable) - Copies the value of another Vector2IntVariable into this variable.
  • CopyFrom(Vector2Variable) - Copies the value of another Vector2Variable into this variable.
  • CopyTo(Vector2Variable) - Copies the value from this variable into another Vector2Variable.
  • CopyTo(Vector3Variable) - Copies the value from this variable into another Vector3Variable.
  • CopyTo(Vector4Variable) - Copies the value from this variable into another Vector4Variable.

Vector3Variable

Derives from RuntimeVariable<T>.

Description

Represents an observable Vector3 value that can be shared and modified throughout the application.

Public Methods

  • CopyFrom(Vector2IntVariable) - Copies the value of another Vector2IntVariable into this variable.
  • CopyFrom(Vector2Variable) - Copies the value of another Vector2Variable into this variable.
  • CopyFrom(Vector3Variable) - Copies the value of another Vector3Variable into this variable.
  • CopyTo(Vector3Variable) - Copies the value from this variable into another Vector3Variable.
  • CopyTo(Vector4Variable) - Copies the value from this variable into another Vector4Variable.

Vector4Variable

Derives from RuntimeVariable<T>.

Description

Represents an observable Vector4 value that can be shared and modified throughout the application.

Public Methods

  • CopyFrom(Vector2IntVariable) - Copies the value of another Vector2IntVariable into this variable.
  • CopyFrom(Vector2Variable) - Copies the value of another Vector2Variable into this variable.
  • CopyFrom(Vector3Variable) - Copies the value of another Vector3Variable into this variable.
  • CopyFrom(Vector4Variable) - Copies the value of another Vector4Variable into this variable.
  • CopyTo(Vector4Variable) - Copies the value from this variable into another Vector4Variable.

Observables

Overview

Observable variables are implemented as ScriptableObject instances that represent complex data types. Similar to RuntimeVariable<T>, they can be used to share their data across components and scenes.

They implement the IObservable interface which provides UnityAction events when a property changes.

Usage

Developers are expected to create their own subclasses of ObservableObject and provide custom properties. The TrySetProperty<T>() method handles most of the boilerplate code necessary for automatic notifications of property changes.

Example

public class PlayerData : ObservableObject
{
    [SerializeField] private string playerName = "Player";
    [SerializeField] private int currentHealth = 50;
    [SerializeField] private int maxHealth = 100;
    
    public string PlayerName
    {
        get => playerName;
        set => TrySetProperty(ref playerName, value);
        // propertyName will be "PlayerName" automatically via CallerMemberName
        // PropertyChanging and PropertyChanged events will be raised
    }
    
    public float HealthPercentage => CurrentHealth * 100f / MaxHealth;
    
    public string CurrentHealth
    {
        get => currentHealth;
        set {
            // If the current health was changed, notify the computed property changed
            if (TrySetProperty(ref currentHealth, value))
                RaisePropertyChanged("HealthPercentage");
        }
    }
    
    public string MaxHealth
    {
        get => maxHealth;
        set {
            // If the max health was changed, notify the computed property changed
            if (TrySetProperty(ref maxHealth, value))
                RaisePropertyChanged("HealthPercentage");
        }
    }
}

IObservable

Similar to INotifyPropertyChanging and INotifyPropertyChanged interfaces.

Description

Represents an object that can be observed for property changes.

Public Events

  • PropertyChanging : UnityAction<string> - Raised when a property on the object is about to change, providing the property name.
  • PropertyChanged : UnityAction<string> - Raised when a property on the object has changed, providing the property name.

Public Methods

  • RaisePropertyChanging(string) - Manually raises the PropertyChanging event with the property name provided.
  • RaisePropertyChanged(string) - Manually raises the PropertyChanged event with the property name provided.

ObservableObject

Abstract base class that all other observable objects derive from.

Implements the IObservable interface.

Description

Represents an object that can be observed for property changes. It can be shared and modified throughout the application.

Public Events

  • PropertyChanging : UnityAction<string> - Raised when a property on the object is about to change, providing the property name.
  • PropertyChanged : UnityAction<string> - Raised when a property on the object has changed, providing the property name.

Public Methods

  • RaisePropertyChanging(string) - Manually raises the PropertyChanging event with the property name provided.
  • RaisePropertyChanged(string) - Manually raises the PropertyChanged event with the property name provided.

Protected Methods

  • TrySetProperty<T>(ref T, T, [string]): bool - Attempts to set the field value with the new T value. Optionally, a property name can be provided.

NOTE: The PropertyChanging and PropertyChanged events are only raised when the new value is not equal to the existing value.

NOTE: The propertyName argument is optional and defaults to the value of [CallerMemberName].

ObservableWatcher

Base class that all other observable watchers derive from.

Description

Component that watches an ObservableObject for property changes and raises events.

Serialized Fields (Inspector)

  • observable : ObservableObject - The object to watch for property changes.
  • raiseOnAwake : bool - Whether the onPropertyChanged event should be raised when Awake() is called.
  • raiseOnEnable : bool - Whether the onPropertyChanged event should be raised when OnEnable() is called.
  • raiseOnStart : bool - Whether the onPropertyChanged event should be raised when Start() is called.

NOTE: The propertyName will be null when the onPropertyChanged event is raised from raiseOnAwake, raiseOnEnable, or raiseOnStart.

Public Events (Inspector)

  • onPropertyChanging : UnityEvent<ObservableObject, string> - The actions to perform when a property on the object is changing.
  • onPropertyChanged : UnityEvent<ObservableObject, string> - The actions to perform when a property on the object has changed.

Public Properties

  • Observable : ObservableObject (get) - The object being watched for property changes.

Public Methods

  • RaisePropertyChanging(string) - Manually raises the onPropertyChanging event with the property name provided.
  • RaisePropertyChanged(string) - Manually raises the onPropertyChanged event with the property name provided.

NOTE: Manually raising these events will only trigger the UnityEvent actions on this component.

References

Overview

References are values that can either point to a constant value or a variable, toggleable at runtime. They are useful when used for quick prototyping and testing of components and features.

Instead of a component needing a constant or hard reference to a RuntimeVariable, a RuntimeReference can be used instead. This allows developers to start with a constant value initially and swap to a variable value without needing to redesign components.

Their main benefit is that they can be switched at runtime which can greatly speed up play-testing and tweaking.

RuntimeReference<T, TVar>

Abstract base class that all other runtime references derive from.

Marked with the Serializable attribute.

Description

Represents a value that can point to either a constant value T or RuntimeVariable<T> value.

Can be toggled at runtime to switch between these values.

Serialized Fields (Inspector)

  • useConstant : bool - Whether the reference should point to the constant value or the variable value.
  • constantValue : T - The constant value to be used, when useConstant is true.
  • variable: TVar - The variable value to be used, when useConstant is false.

Public Properties

  • UseConstant : bool - (get, set) - Whether the reference should point to the constant value or the variable value.
  • ConstantValue : T - (get) - The constant value to be used, when UseConstant is true.
  • Variable : TVar (get) - The variable value to be used, when UseConstant is false.

Public Methods

  • GetValue() : T - Returns the current value, either of the constant value or variable value.
  • SetValue(T) - Sets the value of the variable to a new value. Has no effect when UseConstant is true.
  • SetUseConstant(bool) - Sets whether the reference should point to the constant value or the variable value.

BoolReference

Derives from RuntimeReference<T, TVar>.

Marked with the Serializable attribute.

Description

Represents a value that can point to either a constant bool value or BoolVariable value.

Can be toggled at runtime to switch between these values.

This class does not have any additional members.

ColorReference

Derives from RuntimeReference<T, TVar>.

Marked with the Serializable attribute.

Description

Represents a value that can point to either a constant Color value or ColorVariable value.

Can be toggled at runtime to switch between these values.

This class does not have any additional members.

DoubleReference

Derives from RuntimeReference<T, TVar>.

Marked with the Serializable attribute.

Description

Represents a value that can point to either a constant double value or DoubleVariable value.

Can be toggled at runtime to switch between these values.

This class does not have any additional members.

FloatReference

Derives from RuntimeReference<T, TVar>.

Marked with the Serializable attribute.

Description

Represents a value that can point to either a constant float value or FloatVariable value.

Can be toggled at runtime to switch between these values.

This class does not have any additional members.

IntReference

Derives from RuntimeReference<T, TVar>.

Marked with the Serializable attribute.

Description

Represents a value that can point to either a constant signed int value or IntVariable value.

Can be toggled at runtime to switch between these values.

This class does not have any additional members.

StringReference

Derives from RuntimeReference<T, TVar>.

Marked with the Serializable attribute.

Description

Represents a value that can point to either a constant string value or StringVariable value.

Can be toggled at runtime to switch between these values.

This class does not have any additional members.

TransformReference

Derives from RuntimeReference<T, TVar>.

Marked with the Serializable attribute.

Description

Represents a value that can point to either a constant Transform value or TransformVariable value.

Can be toggled at runtime to switch between these values.

This class does not have any additional members.

Vector2IntReference

Derives from RuntimeReference<T, TVar>.

Marked with the Serializable attribute.

Description

Represents a value that can point to either a constant Vector2Int value or Vector2IntVariable value.

Can be toggled at runtime to switch between these values.

This class does not have any additional members.

Vector2Reference

Derives from RuntimeReference<T, TVar>.

Marked with the Serializable attribute.

Description

Represents a value that can point to either a constant Vector2 value or Vector2Variable value.

Can be toggled at runtime to switch between these values.

This class does not have any additional members.

Vector3Reference

Derives from RuntimeReference<T, TVar>.

Marked with the Serializable attribute.

Description

Represents a value that can point to either a constant Vector3 value or Vector3Variable value.

Can be toggled at runtime to switch between these values.

This class does not have any additional members.

Vector4Reference

Derives from RuntimeReference<T, TVar>.

Marked with the Serializable attribute.

Description

Represents a value that can point to either a constant Vector4 value or Vector4Variable value.

Can be toggled at runtime to switch between these values.

This class does not have any additional members.

Watchers

Overview

Runtime variable watchers are implemented as MonoBehaviour components that can be used to bind UnityEvent actions to value change events via the Unity Inspector. This allows the watchers to notify other components without needing to write extra boilerplate code for subscribing and unsubscribing to those events.

It also allows multiple actions to be triggered from a single value change event.

RuntimeVariableWatcher<T, TVar>

Abstract base class that all other runtime variable watchers derive from.

Description

Component that watches a RuntimeVariable<T> for value changes and raises events.

Serialized Fields (Inspector)

  • variable : TVar - The variable to watch for value changes.
  • raiseOnAwake : bool - Whether the onValueChanged event should be raised when Awake() is called.
  • raiseOnEnable : bool - Whether the onValueChanged event should be raised when OnEnable() is called.
  • raiseOnStart : bool - Whether the onValueChanged event should be raised when Start() is called.

Public Events (Inspector)

  • onValueChanging : UnityEvent<T> - The actions to perform when the variable value is changing.
  • onValueChanged : UnityEvent<T> - The actions to perform when the variable value has changed.

Public Properties

  • Variable : TVar (get) - The variable being watched for value changes.

Public Methods

  • RaiseValueChanging(T) - Manually raises the onValueChanging event with the value provided.
  • RaiseValueChanged() - Manually raises the onValueChanged event with the current value of the variable.

NOTE: Manually raising these events will only trigger the UnityEvent actions on this component.

BoolVariableWatcher

Derives from RuntimeVariableWatcher<T, TVar>.

Description

Component that watches a BoolVariable for value changes and raises events.

This component does not have any additional members.

ColorVariableWatcher

Derives from RuntimeVariableWatcher<T, TVar>.

Description

Component that watches a ColorVariable for value changes and raises events.

This component does not have any additional members.

DoubleVariableWatcher

Derives from RuntimeVariableWatcher<T, TVar>.

Description

Component that watches a DoubleVariable for value changes and raises events.

This component does not have any additional members.

FloatVariableWatcher

Derives from RuntimeVariableWatcher<T, TVar>.

Description

Component that watches a FloatVariable for value changes and raises events.

This component does not have any additional members.

IntVariableWatcher

Derives from RuntimeVariableWatcher<T, TVar>.

Description

Component that watches a IntVariable for value changes and raises events.

This component does not have any additional members.

ScriptableObjectVariableWatcher

Derives from RuntimeVariableWatcher<T, TVar>.

Description

Component that watches a ScriptableObjectVariable for value changes and raises events.

This component does not have any additional members.

StringVariableWatcher

Derives from RuntimeVariableWatcher<T, TVar>.

Description

Component that watches a StringVariable for value changes and raises events.

This component does not have any additional members.

TransformVariableWatcher

Derives from RuntimeVariableWatcher<T, TVar>.

Description

Component that watches a TransformVariable for value changes and raises events.

This component does not have any additional members.

Vector2IntVariableWatcher

Derives from RuntimeVariableWatcher<T, TVar>.

Description

Component that watches a Vector2IntVariable for value changes and raises events.

This component does not have any additional members.

Vector2VariableWatcher

Derives from RuntimeVariableWatcher<T, TVar>.

Description

Component that watches a Vector2Variable for value changes and raises events.

This component does not have any additional members.

Vector3VariableWatcher

Derives from RuntimeVariableWatcher<T, TVar>.

Description

Component that watches a Vector3Variable for value changes and raises events.

This component does not have any additional members.

Vector4VariableWatcher

Derives from RuntimeVariableWatcher<T, TVar>.

Description

Component that watches a Vector4Variable for value changes and raises events.

This component does not have any additional members.