# 2. Sync Layers, Write Defaults, and Interruption
Part of [[Animation Advanced]]. Prev: [[1.Layer Stacks and Avatar Masks Deep Dive]]. Next: [[3.Root Motion Advanced]]. Also see [[7.Animation Pitfalls]].
**Docs:** [Animation Layers](https://docs.unity3d.com/6000.5/Documentation/Manual/AnimationLayers.html) · [Animator API defaults/Rebind](https://docs.unity.com/en-us/engine/6000.5/script-reference/unityengine/animator) · [WriteDefaultValues](https://docs.unity3d.com/6000.5/Documentation/ScriptReference/Animator.WriteDefaultValues.html)
## 2.1 Sync layers
**Sync** makes a layer an *instance* of another layer's state-machine structure with **different clips** per state (classic "wounded locomotion" swap). Docs notes:
- Synced layer has **no independent state-machine definition**.
- Editing states/transitions in the synced view **edits the source**.
- Only the **selected clips** differ.
- Sidebar shows **S** for synced layers.
**Timing** checkbox: when off, synced clips stretch to the source layer's lengths (source is master). When on, lengths are a **weight-based compromise**.
```csharp
using UnityEngine;
/// <summary>
/// Cross-fade wounded presentation by weighting a synced "Fatigued" layer.
/// State machine structure stays shared with Base (Sync).
/// NOT compiled in Unity.
/// </summary>
public sealed class WoundedLayerSync : MonoBehaviour
{
[SerializeField] Animator animator;
[SerializeField] int woundedSyncedLayer = 1; // Sync → Base Layer in Controller
public void SetWoundedBlend(float t)
{
animator.SetLayerWeight(woundedSyncedLayer, Mathf.Clamp01(t));
}
}
```
Use Sync when **state graphs are identical**. If wounded needs different transitions, use `AnimatorOverrideController` (part 4) or a separate controller instead.
## 2.2 Write Defaults deep dive
When **Write Defaults** is on for a state, properties **not animated** by that state's clip(s) are written to the Animator's stored defaults.
Defaults are collected:
1. On first Animator initialization (scene load / instantiate).
2. Whenever a **Rebind** completes.
**Danger (from Animator API docs):** If Rebind happens *during* evaluation, new defaults may be whatever pose is currently in the scene — arbitrary and sticky. Symptoms: T-pose flashes, stuck offsets, "my idle drifted after swapping skins."
Mitigations:
- Prefer **not** relying on Write Defaults for critical bones; author complete curves.
- Or enable **`animator.writeDefaultValuesOnDisable`** so disable restores original defaults before a later Rebind.
- Or call **`animator.WriteDefaultValues()`** intentionally when you know the pose is clean.
- Avoid Rebind mid-combat; batch avatar/controller swaps at known safe points.
```csharp
using UnityEngine;
/// <summary>
/// Safer controller/avatar swap boundary.
/// NOT compiled in Unity.
/// </summary>
public sealed class SafeAnimatorRebind : MonoBehaviour
{
[SerializeField] Animator animator;
void Awake()
{
// Optional: keep defaults stable across disable/enable cycles.
animator.writeDefaultValuesOnDisable = true;
}
public void SwapController(RuntimeAnimatorController next)
{
// Ideally weight layers to known pose / go to a neutral state first.
animator.runtimeAnimatorController = next; // triggers Rebind path
// Changing to a prebuilt AnimatorOverrideController is cheaper than
// rebuilding overrides dynamically (see Animator API notes).
}
public void ForceWriteDefaultsNow()
{
animator.WriteDefaultValues();
}
}
```
## 2.3 Interruption sources (advanced use)
Transitions expose **Interruption Source** / ordered interruption (fundamentals in [[2.States Transitions and Parameters]]). Advanced patterns:
| Goal | Approach |
|---|---|
| Attack must finish | Interruption = None on commit window; open interruption only in recovery |
| Light attacks cancel into each other | Current State / Next State interruption on recovery transitions |
| Hit-react always wins | Higher-priority Any State → Hit with interruption allowed into it from attacks *(use sparingly)* |
| Code-driven cancel | `CrossFade` / `Play` from brain when cancel window bool is true (part 4) |
Prefer **explicit cancel windows** (bool `CanCancel`) set by Animation Events (part 6) over global Any-State spam.
```csharp
using UnityEngine;
public sealed class CancelWindow : MonoBehaviour
{
[SerializeField] Animator animator;
static readonly int CanCancelHash = Animator.StringToHash("CanCancel");
static readonly int AttackHash = Animator.StringToHash("Attack");
// Called by Animation Events on the attack clip
public void OpenCancel() => animator.SetBool(CanCancelHash, true);
public void CloseCancel() => animator.SetBool(CanCancelHash, false);
public void TryAttack()
{
// Brain may also check CanCancel for buffered inputs
animator.SetTrigger(AttackHash);
}
}
```
## 2.4 Interaction with layers
Write Defaults + multi-layer stacks: an upper-body state with Write Defaults **on** can stomp masked properties to defaults even when you expected base locomotion curves to hold. For Override layers, many teams turn **Write Defaults off** on sparse aim clips and rely on the mask + complete curves.
## Unverified
- Exact Inspector wording for Interruption Source enums across 6000.5 patch versions.
- Whether your Avatar Mask + Write Defaults combination matches a specific third-party character pack.