Unity-Technologies/UnityCsReference · error · InvalidOperationException

Cannot apply overriden properties in Animation Mode.

Error message

Cannot apply overriden properties in Animation Mode.

What it means

Thrown by WarnIfInAnimationMode when an Apply override operation is attempted while AnimationMode.InAnimationMode() is true and action is InteractionMode.AutomatedAction. Animation Mode samples property overrides for preview, so committing an apply during it would conflict with the sampled state; the automated path throws rather than show a dialog.

Source

Thrown at Editor/Mono/Prefabs/PrefabUtility.cs:587

            }
            referencedObject = GetCorrespondingObjectFromSourceInAsset(referencedObject, prefabSourceObject);
            if (referencedObject != null)
            {
                property.objectReferenceValue = referencedObject;
            }
        }

        static bool WarnIfInAnimationMode(OverrideOperation overrideOperation, InteractionMode action)
        {
            if (!AnimationMode.InAnimationMode())
                return false;

            if (action == InteractionMode.AutomatedAction)
            {
                switch (overrideOperation)
                {
                    case OverrideOperation.Apply:
                        throw new InvalidOperationException("Cannot apply overriden properties in Animation Mode.");
                    case OverrideOperation.Revert:
                        throw new InvalidOperationException("Cannot revert overriden properties in Animation Mode.");
                }
            }
            else if (action == InteractionMode.UserAction)
            {
                var message = L10n.Tr("Overriden properties cannot be applied or reverted when in Animation Mode.\n\nDisable Animation Mode and try again.");
                switch (overrideOperation)
                {
                    case OverrideOperation.Apply:
                        EditorUtility.DisplayDialog(
                            L10n.Tr("Cannot apply property override to Prefab"),
                            message,
                            L10n.Tr("OK"));
                        break;
                    case OverrideOperation.Revert:
                        EditorUtility.DisplayDialog(
                            L10n.Tr("Cannot revert property override"),

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Call AnimationMode.StopAnimationMode() before performing the apply.
  2. Guard with: if (AnimationMode.InAnimationMode()) return; before automated apply calls.
  3. Use InteractionMode.UserAction to get a blocking dialog instead of an exception when a user is driving the action.

Example fix

// before
if (AnimationMode.InAnimationMode()) { /* still apply */ }
PrefabUtility.ApplyObjectOverride(obj, path, InteractionMode.AutomatedAction);

// after
if (AnimationMode.InAnimationMode()) AnimationMode.StopAnimationMode();
PrefabUtility.ApplyObjectOverride(obj, path, InteractionMode.AutomatedAction);
Defensive patterns

Strategy: validation

Validate before calling

if (AnimationMode.InAnimationMode())
    AnimationMode.StopAnimationMode();
PrefabUtility.ApplyObjectOverride(obj, assetPath, InteractionMode.AutomatedAction);

Type guard

static bool CanApplyOverridesNow() => !AnimationMode.InAnimationMode();

Try / catch

try { PrefabUtility.ApplyObjectOverride(obj, path, InteractionMode.AutomatedAction); }
catch (InvalidOperationException ex) when (ex.Message.Contains("Animation Mode"))
{ Debug.LogWarning("Skipped apply: Animation Mode active."); }

Prevention

When it happens

Trigger: Calling ApplyObjectOverride / ApplyAddedGameObjectOverride-family methods with InteractionMode.AutomatedAction while the editor is recording or previewing animation (AnimationMode.StartAnimationMode active).

Common situations: Editor tools that run apply operations from a coroutine/timer that overlaps an active Animation Mode session; automation that forgets to call AnimationMode.StopAnimationMode before applying overrides; timeline/animation window integrations.

Related errors


AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13). Data as JSON: /api/errors/0bfe49888b44348b. Report an issue: GitHub.