Skip to content

Watch

Watch class serves as the primary entry point for all operations involving watches.


Global Management Methods

These methods manage global operations for all variables in the project.

UpdateAll

public static void UpdateAll()
Updates all variables. Typically called from the LateUpdate() method but can be invoked elsewhere if needed.
How does UpdateAll work? For each variable, Push() is called recursively using the Func<T> valueGetter from GetOrAdd(). If a variable is created manually without a getter, it should be updated manually via Push().

Update order matters

Manual updates must be done BEFORE calling UpdateAll() to avoid inconsistent visual representation.

Ensure Live Is Active

This method won't function if the Live Toggle is off in the LiveWatch window.

ClearAll

public static void ClearAll()
Clears all values for all variables, similar to the Clear button in the LiveWatch window.

DestroyAll

public static void DestroyAll()

Destroys all variables and their data. Usually called in Awake() to remove variables from previous playmode sessions. If you want to preserve variables from the previous session, you can skip this call.


Type-Indifferent Methods

These methods interact with variables regardless of type.

GetOrAdd

public static WatchReference<T> GetOrAdd<T>(string path)
Creates an existing variable or adds a new one of type T with name path. Note that type T must be one of the basic types or a type generated from the Schema.

PushEmpty

public static WatchReference<Any> PushEmpty(string path)
Pushes an empty value to the variable identified by name path, regardless of its type.

What is Any type?

Any is not a real type, it's a special type for cases when variable type does not matter.

PushFormat

public static WatchReference<Any> PushFormat(string path, WatchValueFormat format)
Pushes a colored format to the variable with name path.

PushExtraText

public static WatchReference<Any> PushExtraText(string path, string extraText)
Pushes additional text extraText to the variable with name path.


Per Type Methods

These methods are designed for concrete types including basic type and generated ones.

GetOrAdd

public static WatchReference<T> GetOrAdd(string path, Func<T> valueGetter)
Creates or retrieves a variable identified name path. The valueGetter is a function that is used for automatic updates to the variable during each UpdateAll call.

public static WatchReference<T> GetOrAdd<V>(WatchReference<V> parent, string path, Func<T> valueGetter)
Creates or retrieves a variable with name path that is a child of the specified parent variable. The valueGetter allows for automatic updates.

Setup

public static WatchReference<T> Setup(WatchReference<T> watchReference)
Prepares the specified variable watchReference for its first update. This method is automatically called for all variables created via the aforementioned methods and during the first call to Push().

Push

public static WatchReference<T> Push(WatchReference<T> watchReference, T value, int maxRecursionDepth = 10)
Pushes the provided value into the given watchReference variable. The maxRecursionDepth controls how deep the push operation will proceed to prevent an infinite recursion loop.

public static WatchReference<T> Push(string path, T value, int maxRecursionDepth = 10)
Pushes the specified 'value' to the variable identified by name path. The maxRecursionDepth regulates the depth of the push operation.

PushValue

internal static WatchReference<T> PushValue(this WatchReference<T> watchReference, T value, int maxRecursionDepth = 10)
An extension method that functions similarly to the standard Push() method. It is not generated by default for custom types but can be enabled in the Generator.

Note if you want to use extensions

Extension methods must be called from the same namespace and assembly.

GetOrAddChild

internal static WatchReference<T> GetOrAddChild<V>(this WatchReference<V> parent, string path, Func<T> valueGetter)
An extension method that operates identically to the usual GetOrAdd(). It is not generated by default for custom types but can be enabled in the Generator.

SetupWatch

internal static WatchReference<T> SetupWatch(this WatchReference<T> watchReference)
An extension method that mirrors the functionality of the standard Setup(). It is not generated by default for custom types but can be enabled in the Generator.