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.
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)
Solutions
- Call PrefabUtility.IsPartOfPrefabInstance(go) before passing the GameObject to GetObjectOverrides
- If the object might be a prefab asset, use PrefabUtility.IsPartOfPrefabAsset to distinguish and route accordingly
- 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
- Always call PrefabUtility.IsPartOfPrefabInstance before querying overrides
- Distinguish prefab assets from prefab instances using IsPartOfPrefabAsset vs IsPartOfPrefabInstance
- Validate user selections before processing prefab operations
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
- Given input object is not a prefab asset
- Object to create variant from has to be a Prefab root
- PersistentLocalStorageSize must be between 256 and 4096, but
- guid
- prefabInstance
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/414599afd271bf2f.
Report an issue: GitHub.