How Concordance works
Concordance works in two steps. When Unity compiles your code, Concordance rewrites the writes to fields and properties. At runtime, it computes the value of each modified member and writes it through the member's setter.
At compile time
After Unity compiles an assembly that references Concordance, Concordance rewrites the compiled code, using the Mono Cecil package:
- Each modifier line and regular call becomes a call into the Concordance runtime, through direct calls, never reflection.
- Each plain write to a field or property gets a check before it: while the member has no modifier, observer or watch, the write runs as written.
A source generator creates the Modifier and ModifierPhase types in each assembly, and a
code analyzer reports mistakes in your code editor as you type. Precompiled DLLs and package assemblies are never
rewritten.
At runtime
A member's value is computed again only when one of its modifiers is written or stopped, or its base value changes, never on its own every frame. The value is written through the member's setter, so a property's setter runs each time. Once per frame, Concordance removes the modifiers of destroyed objects. When you exit Play mode, and after each Test Runner test, it removes every modifier and writes each base value back.
In the Editor and in builds
In the Editor, every write gets the check, so you can watch any member in the Concordance window. In a player build, you pay only for what you use: only the writes to members that some modifier or observe line uses get the check, and every other write runs exactly as without Concordance.
Reading a member never costs anything extra, and writing a modifier again, stopping it and plain writes allocate
nothing. The Concordance window, the history and the line records are Editor only. Concordance works with IL2CPP
and managed code stripping with no link.xml.
Threads, domain reload and tests
- Write modifiers and modified members from the main thread. A write from another thread to an object without modifiers or observers runs as written, and one to an object with them throws.
- Concordance supports entering Play mode with domain reload disabled.
- Modifier lines work in Edit mode tests too. Concordance's own tests compile only when the project defines
CONCORDANCE_TESTS.