{"record":{"id":"1c0161e8bec0c694","repo":"Unity-Technologies/UnityCsReference","slug":"input-prefab-asset-is-not-an-asset-object-input-a","errorCode":null,"errorMessage":"Input Prefab asset is not an asset object. Input asset: {prefabAsset.name}","messagePattern":"Input Prefab asset is not an asset object\\. Input asset: (.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Prefabs/PrefabUtility.cs","lineNumber":2225,"sourceCode":"\n        // Instantiates the given prefab in a given scene\n        public static Object InstantiatePrefab(Object assetComponentOrGameObject, Scene destinationScene)\n        {\n            return InstantiatePrefab_internal(assetComponentOrGameObject, destinationScene, null);\n        }\n\n        public static Object InstantiatePrefab(Object assetComponentOrGameObject, Transform parent)\n        {\n            return InstantiatePrefab_internal(assetComponentOrGameObject, EditorSceneManager.GetTargetSceneForNewGameObjects(), parent);\n        }\n\n        internal static void ThrowIfInvalidAssetForReplacePrefabInstance(GameObject prefabAsset, InteractionMode action)\n        {\n            if (prefabAsset == null)\n                throw new ArgumentNullException(nameof(prefabAsset));\n\n            if (!EditorUtility.IsPersistent(prefabAsset))\n                throw new ArgumentException(\"Input Prefab asset is not an asset object. Input asset: \" + prefabAsset.name, nameof(prefabAsset));\n\n            var assetPath = AssetDatabase.GetAssetPath(prefabAsset);\n            if (assetPath.StartsWith(\"Library/\"))\n                throw new InvalidOperationException(string.Format(\"Cannot replace the Prefab instance since the Prefab Asset is invalid for instance replacement. Prefab Asset path: \" + assetPath));\n\n            // Recording undo does not handle missing scripts\n            var gameObjectsWithInvalidScript = FindGameObjectsWithInvalidComponent(prefabAsset);\n            if (action == InteractionMode.UserAction && gameObjectsWithInvalidScript.Count > 0)\n                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.\"));\n        }\n\n        internal static void ThrowIfInvalidArgumentsForReplacePrefabInstance(GameObject prefabInstanceRoot, GameObject prefabAssetRoot, bool checkValidAsset, InteractionMode mode)\n        {\n            if (prefabInstanceRoot == null)\n                throw new ArgumentNullException(nameof(prefabInstanceRoot));\n\n            if (prefabAssetRoot == null)\n                throw new ArgumentNullException(nameof(prefabAssetRoot));","sourceCodeStart":2207,"sourceCodeEnd":2243,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Prefabs/PrefabUtility.cs#L2207-L2243","documentation":"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.","triggerScenarios":"Passing a scene-level GameObject or an instantiated runtime object as the prefabAsset argument to a ReplacePrefabInstance operation.","commonSituations":"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.","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."],"exampleFix":"// before\nGameObject liveInstance = Instantiate(myPrefab);\nThrowIfInvalidAssetForReplacePrefabInstance(liveInstance, mode);\n// after\nGameObject asset = PrefabUtility.GetCorrespondingObjectFromSource(liveInstance);\n// or: AssetDatabase.LoadAssetAtPath<GameObject>(\"Assets/x.prefab\")\nThrowIfInvalidAssetForReplacePrefabInstance(asset, mode);","handlingStrategy":"validation","validationCode":"if (!EditorUtility.IsPersistent(prefabAsset))\n{ Debug.LogError(\"Object is not an asset; load it from AssetDatabase.\"); return; }\nPrefabUtility.ThrowIfInvalidAssetForReplacePrefabInstance(prefabAsset, mode);","typeGuard":"static bool IsPersistentAsset(Object obj) =>\n    obj != null && EditorUtility.IsPersistent(obj);","tryCatchPattern":null,"preventionTips":["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."],"tags":["unity","prefab","persistent-check","replace-instance"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}