Quick Usage Guide
Coordinate the scripts that write the same value.
Two scripts, one value
Concordance coordinates the scripts that write the same field or property: it tracks who changes a value and when, combines their changes, and turns any member into a change event. It works on the members your code already writes, Unity's included, because it processes your code when Unity compiles it.
The following two scripts both write Time.timeScale. Each one is correct on its own:
public class PauseMenu : MonoBehaviour
{
public void Pause() => Time.timeScale = 0f;
public void Resume() => Time.timeScale = 1f;
}
public class SlowMotion : MonoBehaviour
{
float cached;
public void Begin()
{
cached = Time.timeScale;
Time.timeScale = cached * 0.5f;
}
public void End() => Time.timeScale = cached;
}
Together, they break each other. If slow motion ends while the game is paused, End writes back the
time scale it cached and unpauses the game under the pause menu. If the pause menu resumes during slow motion, the
game runs at full speed again, and slow motion is lost.
Find who writes a value
To find every script that writes a member, go to Tools > Concordance >
Open Window, search for the member, and select it. Its Writes section lists each
write in your project with its file and line: for Time.timeScale, the lines of PauseMenu
and SlowMotion.
To catch the scripts that break each other, select Watch > Watch for This Session, then enter Play mode. When two objects overwrite each other's value, the window flags their conflicting writes, with the line of each:
For more information, refer to Inspect members.
Write a modifier
To fix the conflict, each script writes a modifier instead: a change layered on top of the value,
which the script removes when its effect ends. Writing (Modifier) before the assigned value sets the modifier,
and Modifier.Stop removes it:
using Concordance;
public class PauseMenu : MonoBehaviour
{
[ModifierPhase.Latest]
public void Pause() => Time.timeScale = (Modifier)0f; // sets it to 0, after the others
public void Resume() => Time.timeScale = Modifier.Stop; // removes this script's modifier
}
using Concordance;
public class SlowMotion : MonoBehaviour
{
public void Begin() => Time.timeScale *= (Modifier)0.5f; // halves the time scale
public void End() => Time.timeScale = Modifier.Stop;
}
SlowMotion no longer caches the time scale to write it back: Concordance keeps the
base value, the value without modifiers, and applies the active modifiers to it in order. [ModifierPhase.Latest] puts the
pause after slow motion, so the pause wins while both are active.
In Play mode, the member's Values section in the Concordance window shows the base value, then each modifier in the order it applies, with its owner and line:
Each script removes only its own modifier. When the game resumes during slow motion, the time scale becomes 0.5, and when slow motion ends during a pause, the game stays paused. A modifier also ends with the object that wrote it, so a script destroyed in the middle of its effect never leaves its change behind.
Code that doesn't use Concordance keeps working. A plain write, such as Time.timeScale = 1f;, sets
the base value, and the modifiers apply on top of it. For more information, refer to
Base values.
After (Modifier), the member you write reads as its value before this modifier applies, so
speed * 0.5f halves whatever the earlier modifiers left. Every other expression is
evaluated once, when the line runs:
| Line | Modifier |
|---|---|
speed = (Modifier)0f | Sets speed to 0. |
speed *= (Modifier)0.5f | Halves speed. |
speed = (Modifier)Mathf.Min(speed, 3f) | Caps speed at 3. |
sprite.color = (Modifier)Color.Lerp(sprite.color, Color.red, 0.5f) | Tints the sprite halfway to red. |
meshRenderer.sharedMaterial = (Modifier)highlight | Swaps in the highlight material. |
canMove = (Modifier)false | Disables movement while it lasts. |
speed = Modifier.Stop | Removes the modifier this object set on speed. |
Running the line again replaces the modifier instead of adding one, so a modifier line in Update
never piles up modifiers.
For more information, refer to Write modifiers.
To choose a modifier's owner, the object it ends with, or to hold several modifiers from one object, call x.Modify(...)
instead. For more information, refer to Use the regular syntax.
Order the modifiers
Each script's modifiers belong to a phase, and a member's modifiers apply phase by phase, in this
order: Earliest, Early, Default, Late, then Latest. To choose a script's phase, add a phase attribute to the method or the class that writes its modifiers:
[ModifierPhase.Late]
public class SpeedLimiter : MonoBehaviour
{
[SerializeField] float maxSpeed = 3f;
public float speed;
void Update() => speed = (Modifier)Mathf.Min(speed, maxSpeed); // applies after the Default phase
}
Without an attribute, a script's modifiers are in Default.
When two scripts modify the same member in the same phase, the Concordance window flags it Order not set, and they apply in the order of their names until you drag one of them into place in the member's Modifier Order.
For more information, refer to Order modifiers.
Observe a value
To run code each time a member's value changes, call Observe on it. It works on any field or
property, your own or Unity's:
void OnEnable() => AudioListener.volume.Observe(OnVolumeChanged);
void OnDisable() => AudioListener.volume.StopObserving(OnVolumeChanged);
void OnVolumeChanged(float volume) => Debug.Log($"Volume: {volume}");
The handler runs after each change of the value, from a modifier or a plain write alike, and stops when the object that called Observe is destroyed. For more information, refer to Observe changes.
Next steps
- Tutorial: Coordinate a player's speed: build a player whose speed boosts, stun and speed log work together, step by step.
- Try the demo: play overlapping gravity zones, written once with plain writes and once with modifiers.
- User Manual: every feature of Concordance and its windows.
- Public API: every public type and member.
For questions and bug reports, use the contact form or email justetools@gmail.com.