ModifyingWhat a script that modifies or observes a member uses.

Modifier lines

Modifier

structgenerated

Marks a modifier line, which Concordance rewrites after Unity compiles it: x = (Modifier)value; turns the assigned value into the calling object's modifier on the member. Concordance generates it as an internal type in the Concordance namespace of each assembly that uses it, with a conversion for each type of value its quick syntax lines use. (Modifier) must apply to the whole right side of an assignment to a field or property, or the value argument of a getter and setter pair's setter. For more information, refer to Write modifiers.

Static fields
static readonly Modifier StopRemoves the calling object's modifier on the member: x = Modifier.Stop;. Same as x.StopModifying().
Operators
The conversions throw InvalidOperationException when they run, which happens only in code that Concordance didn't rewrite.
explicit operator Modifier(T value)The conversion (Modifier) applies to the assigned value. Generated for each type T the assembly's casts use, except interfaces, object and type parameters.
implicit operator T(Modifier modifier)Lets (Modifier)value stand where the member's type is expected, so the assignment compiles.

ModifierPhase

staticgenerated

The default place of a script's modifiers in each member's modifier order, set with one of its nested attributes on a method, a class or a struct. The method's attribute wins over its type's, a lambda, coroutine or async method takes the phase of the method that declares it, and a line without any is in Default. The attributes aren't inherited. The member's modifier order in the Concordance window can pin a script elsewhere. Concordance generates the type in each assembly that uses it. For more information, refer to Set a phase in code.

Nested attributes
class Earliest : AttributeApplies before every other phase.
class Early : AttributeApplies after Earliest and before Default.
class Default : AttributeThe phase of a line without an attribute. Use it to return a method to Default inside a class with another phase.
class Late : AttributeApplies after Default and before Latest.
class Latest : AttributeApplies after every other phase.

Extension methods

ModifierExtensions

static

Modifies a member, as the quick syntax (Modifier) does, with a choice of owner, key and local order: AudioListener.volume.Modify(0f). Concordance rewrites each call after Unity compiles it, so member names the member itself rather than passing its value. Call it on the member itself: a field, a property with a setter, or the getter of a getter and setter pair. Never call it on a local variable. Leaving owner out, or passing null, means the calling object, or the declaring type in a static method. A key tells apart several modifiers of one owner on one member, compared with Equals. For more information, refer to Use the regular syntax.

Static methods
Every method throws InvalidOperationException when the call was not rewritten at compile time, when called off the main thread, and in the Editor outside Play mode and tests, and NullReferenceException when the object holding the member is null. Modify and StopModifying also throw ArgumentNullException when owner is null in a struct method, which has no calling object.
void Modify<T>(this T member, T value, object owner = null, object key = null, int localOrder = 0)Modifies the member with a value, as x = (Modifier)value does: speed.Modify(speed * slowFactor). In the value, a read of the member itself is the value before this modifier; every other part is read once, when the call runs. localOrder orders this modifier among the other modifiers of the same script, lowest first; it has no effect on the order between scripts.
void Modify<T>(this T member, ModifierFunction<T> function, object owner = null, object key = null, int localOrder = 0)Modifies the member with a function of the value before this modifier, such as one picked in the Inspector window. Its fields are copied when the call runs: to apply new field values, call again. The copy is shallow: a field holding an object stays shared. Null, such as a field left on None, leaves the value unchanged. Also throws InvalidOperationException when the function cannot apply to its types, such as an operator they lack.
void StopModifying<T>(this T member, object owner = null, object key = null)Removes the owner's modifier for the key, if there is one. The member's value is then computed again from its base value and its other modifiers. owner and key are the ones passed to Modify.
void Recombine<T>(this T member)Computes the member's value again: its current value becomes the base value, and the modifiers apply on top. Call it after a write from code Concordance doesn't rewrite, such as a precompiled DLL, to apply the modifiers at once. Does nothing on a member without modifiers or observers.
T GetUnmodified<T>(this T member)Returns the member's value without its modifiers. A plain write computed from it changes the base value without adding the modifiers to it: x = x.GetUnmodified() * 2f.

ObserverExtensions

static

Calls a handler each time a member's value changes, from a modifier or a plain write alike: light.intensity.Observe(OnChanged). Concordance rewrites each call after Unity compiles it, so member names the member itself rather than passing its value. A handler that throws is logged, and the others still run. An owner registers a handler on a member once: observing again with the same handler and owner changes nothing. A handler that writes the member it observes, or sets a modifier on it, throws. For more information, refer to Observe changes.

Static methods
Every method throws InvalidOperationException when the call was not rewritten at compile time, when called off the main thread, and in the Editor outside Play mode and tests, and NullReferenceException when the object holding the member is null. Observe also throws ArgumentNullException when handler is null, or owner is null in a struct method.
void Observe<T>(this T member, Action<T> handler, object owner = null)Calls the handler with the new value each time the member's value changes. The handler is removed when the owner is destroyed, or collected for a plain C# object. Leaving owner out, or passing null, means the calling object, or the declaring type in a static method.
void Observe<T>(this T member, Action<T, T> handler, object owner = null)Calls the handler with the previous and the new value each time the member's value changes.
void StopObserving<T>(this T member, Action<T> handler, object owner = null)
void StopObserving<T>(this T member, Action<T, T> handler, object owner = null)
Removes a handler added with Observe, if it is there. The handler is compared with Equals: passing the same method again removes it. owner is the owner passed to Observe; leaving it out, or passing null, means the calling object, or the declaring type in a static method.

Functions

ModifierFunction<T>

abstract

A modifier's function from the value before it to the value after it. Derive from it to write your own function, as the built-in functions do; mark the subclass [Serializable] for a function field's dropdown to list it, and [DisplayName] to label it. T is the type of the modified member.

Methods
abstract T Apply(T previous)Returns the value after this modifier. previous is the value before it: the base value, with every earlier modifier applied. Runs each time the member's value is computed again. An exception thrown here is logged, and the modifier is skipped. Setting a modifier here, or writing a member with modifiers or observers, throws and skips it the same way.