Unity-Technologies/UnityCsReference · error · ArgumentException
Calling apply or revert methods on an object which is not pa
Error message
Calling apply or revert methods on an object which is not part of a Prefab instance is not supported.
What it means
Thrown by ThrowExceptionIfNotValidPrefabInstanceObject when the object is a non-null GameObject/Component but is NOT part of a prefab instance (PrefabUtility.IsPartOfPrefabInstance returns false). Apply/revert operate on overrides within prefab instances, so a plain scene object or an unpacked object is invalid.
Source
Thrown at Editor/Mono/Prefabs/PrefabUtility.cs:249
}
}
}
foreach (var path in assetsToReload)
{
AssetDatabase.WriteImportSettingsIfDirty(path);
AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);
}
}
static void ThrowExceptionIfNotValidPrefabInstanceObject(Object prefabInstanceObject, bool isApply)
{
if (!(prefabInstanceObject is GameObject || prefabInstanceObject is Component))
throw new ArgumentException("Calling apply or revert methods on an object which is not a GameObject or Component is not supported.", nameof(prefabInstanceObject));
if (prefabInstanceObject == null)
throw new NullReferenceException("Cannot apply or revert object. Object is null.");
if (!PrefabUtility.IsPartOfPrefabInstance(prefabInstanceObject))
throw new ArgumentException("Calling apply or revert methods on an object which is not part of a Prefab instance is not supported.", nameof(prefabInstanceObject));
// We support revert operations on Prefab Assets, but not apply operations.
if (isApply)
ThrowExceptionIfInstanceIsPersistent(prefabInstanceObject);
}
static void ThrowExceptionIfAllPrefabInstanceObjectsAreInvalid(Object[] prefabInstanceObjects, bool isApply)
{
foreach (var obj in prefabInstanceObjects)
{
if (obj != null && (obj is GameObject || obj is Component) && IsPartOfPrefabInstance(obj) && !(isApply && EditorUtility.IsPersistent(obj)))
return;
}
// Throw exception if all objects are invalid
throw new ArgumentException("Cannot apply or revert on any of the objects. Attempt with individual objects for details.", nameof(prefabInstanceObjects));
}
View on GitHub (pinned to 225b0fbdb5)
Solutions
- Ensure the object is part of a prefab instance: check IsPartOfPrefabInstance first.
- If unpacked, reconnect via InstantiatePrefab or reapply to a valid instance.
- For revert-on-asset flows use the asset path variant; for apply, operate on an instance in a scene.
Example fix
// before
PrefabUtility.ApplyPrefabOverride(unpackedGo, path);
// after
if (!PrefabUtility.IsPartOfPrefabInstance(obj))
{ Debug.LogWarning("Object is not part of a prefab instance."); return; }
PrefabUtility.ApplyPrefabOverride(obj, path); Defensive patterns
Strategy: validation
Validate before calling
if (!PrefabUtility.IsPartOfPrefabInstance(obj))
{ Debug.LogWarning("Object is not part of a prefab instance."); return; } Type guard
static bool IsPrefabInstanceObject(UnityEngine.Object o) => o is GameObject || o is Component && PrefabUtility.IsPartOfPrefabInstance(o);
Prevention
- Always check IsPartOfPrefabInstance before apply/revert.
- Do not unpack prefab instances you still need to apply overrides to.
- Use the asset-path revert overload for asset-side reverts, not instance apply.
When it happens
Trigger: Passing a regular scene GameObject with no prefab connection, an unpacked prefab, or an object whose instance link was stripped. Passing a prefab asset (which is not an 'instance').
Common situations: Operating on objects after PrefabUtility.UnpackPrefabInstance severed the link. Selecting plain scene objects in a custom apply tool. Forgetting that revert on a prefab asset is allowed but apply is not.
Related errors
- Calling apply or revert methods on an object which is not a
- Cannot apply or revert object. Object is null.
- Cannot apply or revert on any of the objects. Attempt with i
- The Prefab you want to instantiate is null.
- ApplyPrefabAddedGameObjects requires that GameObjects share
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/cfd36d9bb8b4b15a.
Report an issue: GitHub.