Unity-Technologies/UnityCsReference · error · InvalidOperationException

Cannot revert overriden properties in Animation Mode.

Error message

Cannot revert overriden properties in Animation Mode.

What it means

Thrown by WarnIfInAnimationMode when a Revert override operation is attempted during Animation Mode with InteractionMode.AutomatedAction. Reverting overrides while Animation Mode samples them would desync the preview, so the automated path raises InvalidOperationException('Cannot revert overriden properties in Animation Mode.').

Source

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

            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"),
                            message,
                            L10n.Tr("OK"));

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Stop Animation Mode first: AnimationMode.StopAnimationMode();
  2. Gate automated reverts with: if (!AnimationMode.InAnimationMode()) Revert...;
  3. Switch to InteractionMode.UserAction for interactive use where a dialog is acceptable.

Example fix

// before
PrefabUtility.RevertObjectOverride(obj, InteractionMode.AutomatedAction);

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

Strategy: validation

Validate before calling

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

Type guard

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

Try / catch

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

Prevention

When it happens

Trigger: Calling RevertObjectOverride / RevertAddedComponent-family methods with InteractionMode.AutomatedAction while AnimationMode.InAnimationMode() is true.

Common situations: Automation pipelines that revert overrides on a schedule overlapping an animation preview; tooling that wraps revert in batch jobs without checking editor state; timeline preview sessions.

Related errors


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