Unity-Technologies/UnityCsReference · error · ArgumentException

Provided GameObject is not a Prefab instance

Error message

Provided GameObject is not a Prefab instance

What it means

PrefabOverridesUtility.ThrowExceptionIfNullOrNotPartOfPrefabInstance is the precondition guard called by GetObjectOverrides and related methods. It throws ArgumentException("Provided GameObject is not a Prefab instance") when the passed GameObject is not part of a prefab instance (i.e., PrefabUtility.IsPartOfPrefabInstance returns false). This covers both plain scene objects and prefab assets, since overrides only exist on prefab instances.

Solutions

  1. Call PrefabUtility.IsPartOfPrefabInstance(go) before passing the GameObject to GetObjectOverrides
  2. If the object might be a prefab asset, use PrefabUtility.IsPartOfPrefabAsset to distinguish and route accordingly
  3. Validate Selection.activeGameObject or the user-provided object before processing

Example fix

// before
var overrides = PrefabOverridesUtility.GetObjectOverrides(selectedGo);

// after
if (selectedGo != null && PrefabUtility.IsPartOfPrefabInstance(selectedGo))
    var overrides = PrefabOverridesUtility.GetObjectOverrides(selectedGo);
else
    Debug.LogWarning("Selection is not a prefab instance.");
Defensive patterns

Strategy: validation

Validate before calling

if (!PrefabUtility.IsPartOfPrefabInstance(prefabInstance))
{
    Debug.LogWarning("GameObject is not a prefab instance — overrides are not applicable.");
    return;
}
// Safe to call GetObjectOverrides(prefabInstance)

Type guard

static bool IsPrefabInstance(GameObject go) => go != null && PrefabUtility.IsPartOfPrefabInstance(go);

Try / catch

try { var overrides = PrefabOverridesUtility.GetObjectOverrides(go); }
catch (ArgumentException ex) when (ex.Message == "Provided GameObject is not a Prefab instance")
{ Debug.LogWarning($"{go.name} is not a prefab instance."); }

Prevention

When it happens

Trigger: Calling PrefabOverridesUtility.GetObjectOverrides on a plain scene GameObject, a prefab asset in the Project window, or any object that PrefabUtility.IsPartOfPrefabInstance returns false for.

Common situations: Editor tools that operate on the current selection without verifying it is a prefab instance. Code that handles both prefab assets and instances in the same path. Unpacking a prefab instance and then trying to query its overrides.

Related errors


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

Appendix: source

Thrown at Editor/Mono/Prefabs/PrefabOverrides/PrefabOverridesUtility.cs:25

using UnityEngine;
using Unity.Scripting.LifecycleManagement;

namespace UnityEditor.SceneManagement
{
    internal class PrefabOverridesUtility
    {
        [NoAutoStaticsCleanup] // Reusable scratch buffer, always Clear()ed before and after use; holds no live references across reload.
        static List<Component> s_ComponentList = new List<Component>();
        [NoAutoStaticsCleanup] // Reusable scratch buffer, always Clear()ed before and after use; holds no live references across reload.
        static List<Component> s_AssetComponentList = new List<Component>();

        static void ThrowExceptionIfNullOrNotPartOfPrefabInstance(GameObject prefabInstance)
        {
            if (prefabInstance == null)
                throw new ArgumentNullException(nameof(prefabInstance));

            if (!PrefabUtility.IsPartOfPrefabInstance(prefabInstance))
                throw new ArgumentException("Provided GameObject is not a Prefab instance");
        }

        public static List<ObjectOverride> GetObjectOverrides(GameObject prefabInstance, bool includeDefaultOverrides = false)
        {
            ThrowExceptionIfNullOrNotPartOfPrefabInstance(prefabInstance);

            var prefabInstanceRoot = PrefabUtility.GetOutermostPrefabInstanceRoot(prefabInstance);

            // From root of instance traverse all child go and detect any GameObjects or components
            // that are not part of that source prefab objects component list (these must be added)
            TransformVisitor transformVisitor = new TransformVisitor();
            var modifiedObjects = new List<ObjectOverride>();

            Func<Transform, object, bool> checkMethod;
            if (includeDefaultOverrides)
                checkMethod = CheckForModifiedObjectsIncludingDefaultOverrides;
            else
                checkMethod = CheckForModifiedObjectsExcludingDefaultOverrides;

View on GitHub (pinned to 225b0fbdb5)