Unity-Technologies/UnityCsReference · error · ArgumentException
Input Prefab asset is not an asset object. Input asset: {pre
Error message
Input Prefab asset is not an asset object. Input asset: {prefabAsset.name} What it means
Thrown by ThrowIfInvalidAssetForReplacePrefabInstance when EditorUtility.IsPersistent(prefabAsset) returns false — the object is a scene or runtime instance, not an asset stored in the AssetDatabase. Replace operations require a real Prefab asset as the replacement source.
Source
Thrown at Editor/Mono/Prefabs/PrefabUtility.cs:2225
// Instantiates the given prefab in a given scene
public static Object InstantiatePrefab(Object assetComponentOrGameObject, Scene destinationScene)
{
return InstantiatePrefab_internal(assetComponentOrGameObject, destinationScene, null);
}
public static Object InstantiatePrefab(Object assetComponentOrGameObject, Transform parent)
{
return InstantiatePrefab_internal(assetComponentOrGameObject, EditorSceneManager.GetTargetSceneForNewGameObjects(), parent);
}
internal static void ThrowIfInvalidAssetForReplacePrefabInstance(GameObject prefabAsset, InteractionMode action)
{
if (prefabAsset == null)
throw new ArgumentNullException(nameof(prefabAsset));
if (!EditorUtility.IsPersistent(prefabAsset))
throw new ArgumentException("Input Prefab asset is not an asset object. Input asset: " + prefabAsset.name, nameof(prefabAsset));
var assetPath = AssetDatabase.GetAssetPath(prefabAsset);
if (assetPath.StartsWith("Library/"))
throw new InvalidOperationException(string.Format("Cannot replace the Prefab instance since the Prefab Asset is invalid for instance replacement. Prefab Asset path: " + assetPath));
// Recording undo does not handle missing scripts
var gameObjectsWithInvalidScript = FindGameObjectsWithInvalidComponent(prefabAsset);
if (action == InteractionMode.UserAction && gameObjectsWithInvalidScript.Count > 0)
throw new InvalidOperationException(string.Format($"Cannot replace the Prefab instance with the Prefab Asset '{AssetDatabase.GetAssetPath(prefabAsset)}' because it has a missing script. GameObject '{gameObjectsWithInvalidScript[0].name}' in the Prefab Asset has a missing script."));
}
internal static void ThrowIfInvalidArgumentsForReplacePrefabInstance(GameObject prefabInstanceRoot, GameObject prefabAssetRoot, bool checkValidAsset, InteractionMode mode)
{
if (prefabInstanceRoot == null)
throw new ArgumentNullException(nameof(prefabInstanceRoot));
if (prefabAssetRoot == null)
throw new ArgumentNullException(nameof(prefabAssetRoot));View on GitHub (pinned to 225b0fbdb5)
Solutions
- Pass the original Prefab asset reference (from AssetDatabase.LoadAssetAtPath), not a runtime instance.
- Check EditorUtility.IsPersistent(obj) before calling the replace API.
- If you only have an instance, resolve its source asset via PrefabUtility.GetCorrespondingObjectFromSource.
Example fix
// before
GameObject liveInstance = Instantiate(myPrefab);
ThrowIfInvalidAssetForReplacePrefabInstance(liveInstance, mode);
// after
GameObject asset = PrefabUtility.GetCorrespondingObjectFromSource(liveInstance);
// or: AssetDatabase.LoadAssetAtPath<GameObject>("Assets/x.prefab")
ThrowIfInvalidAssetForReplacePrefabInstance(asset, mode); Defensive patterns
Strategy: validation
Validate before calling
if (!EditorUtility.IsPersistent(prefabAsset))
{ Debug.LogError("Object is not an asset; load it from AssetDatabase."); return; }
PrefabUtility.ThrowIfInvalidAssetForReplacePrefabInstance(prefabAsset, mode); Type guard
static bool IsPersistentAsset(Object obj) =>
obj != null && EditorUtility.IsPersistent(obj); Prevention
- Pass the original asset reference, not a runtime instance.
- Check IsPersistent before calling replace APIs.
- Resolve source assets via GetCorrespondingObjectFromSource when only an instance is available.
When it happens
Trigger: Passing a scene-level GameObject or an instantiated runtime object as the prefabAsset argument to a ReplacePrefabInstance operation.
Common situations: Developer passes an instantiated Prefab (from Instantiate or InstantiatePrefab) instead of the asset reference. Confusing a live scene object with the template asset. Forgetting that IsPersistent is only true for objects in the AssetDatabase.
Related errors
- Value cannot be null. (Parameter 'prefabAsset')
- Cannot replace the Prefab instance since the Prefab Asset is
- Cannot replace the Prefab instance with the Prefab Asset '{A
- prefabAssetRoot
- PrefabFamilyPopup is already open
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/1c0161e8bec0c694.
Report an issue: GitHub.