Watch
Watch class serves as the primary entry point for all operations involving watch variables.
Global Management Methods
These methods manage global operations for all variables in the project.
UpdateAll
Updates all variables. Typically called from theLateUpdate() 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
Clears all values for all variables, similar to the Clear button in the LiveWatch window.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
Creates an existing variable or adds a new one of typeT with name path. Note that type T must be one of the basic types or a type generated from the Schema.
PushEmpty
Pushes an empty value to the variable identified by namepath, 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
Pushes a coloredformat to the variable with name path.
PushExtraText
Pushes additional textextraText to the variable with name path.
PushStackTrace
Captures and pushes the current stack trace to the variable with namepath.
Per Type Methods
These methods are designed for concrete types including basic types and generated ones.
GetOrAdd
Creates or retrieves a variable identified namepath. 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)
path that is a child of the specified parent variable. The valueGetter allows for automatic updates.
Setup
Prepares the specified variablewatchReference 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)
value into the given watchReference variable. The maxRecursionDepth controls how deep the push operation will proceed to prevent an infinite recursion loop.
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)
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)
GetOrAdd(). It is not generated by default for custom types but can be enabled in the Generator.
SetupWatch
An extension method that mirrors the functionality of the standardSetup(). It is not generated by default for custom types but can be enabled in the Generator.