Skip to main content

On Change

This is a handler that watches for parameter changes and emits an event when the value of a parameter changes. There are two implicit variables that become available:

  • $newValue
  • $oldValue
template Abc {
required int value;
onChange:value => Debug.Log($newValue);
}

The comparison will use .Equals if IEquatable<T> is implemented, otherwise it will use == for primitives and classes, and will not work for structs without and IEquatable<T> implementation.

The event will fire after parameters were set but before the render block runs.

You can also use onChange as a template argument, it works slightly differently in that case but the concept is the same.

There are two differences:

  • it fires after the template finished its execution for the frame
  • it can observe public state fields and parameters.
template Something {

render {
SomeTemplate(onChange:someValue => Debug.Log($newValue + " " + $oldValue)
}

}