{"record":{"id":"ff792c38b08c49f7","repo":"Unity-Technologies/UnityCsReference","slug":"prefab-asset-path-is-null-or-empty","errorCode":null,"errorMessage":"Prefab Asset path is null or empty","messagePattern":"Prefab Asset path is null or empty","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Prefabs/PrefabUtility.cs","lineNumber":2903,"sourceCode":"            if (!PrefabUtility.IsPartOfAnyPrefab(componentOrGameObject))\n                return PrefabAssetType.NotAPrefab;\n\n            if (PrefabUtility.IsPrefabAssetMissing(componentOrGameObject))\n                return PrefabAssetType.MissingAsset;\n\n            if (PrefabUtility.IsPartOfVariantPrefab(componentOrGameObject))\n                return PrefabAssetType.Variant;\n\n            if (PrefabUtility.IsPartOfModelPrefab(componentOrGameObject))\n                return PrefabAssetType.Model;\n\n            return PrefabAssetType.Regular;\n        }\n\n        public static GameObject LoadPrefabContents(string assetPath)\n        {\n            if (string.IsNullOrEmpty(assetPath))\n                throw new ArgumentNullException(\"assetPath\", \"Prefab Asset path is null or empty\");\n\n            if (!File.Exists(assetPath))\n                throw new ArgumentException(string.Format(\"Path: {0}, does not exist\", assetPath));\n\n            if (Path.GetExtension(assetPath) != \".prefab\")\n                throw new ArgumentException(string.Format(\"Path: {0}, is not a prefab file\", assetPath));\n\n            var previewScene = EditorSceneManager.NewPreviewScene();\n            var rootGameObject = LoadPrefabContentsIntoPreviewScene_Internal(assetPath, previewScene);\n            previewScene.SetPathAndGuid(assetPath, AssetDatabase.AssetPathToGUID(assetPath));\n\n            if (rootGameObject == null)\n            {\n                EditorSceneManager.ClosePreviewScene(previewScene);\n                throw new ArgumentException(string.Format(\"Could not load Prefab contents at path {0}.\", assetPath));\n            }\n\n            return rootGameObject;","sourceCodeStart":2885,"sourceCodeEnd":2921,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Prefabs/PrefabUtility.cs#L2885-L2921","documentation":"PrefabUtility.LoadPrefabContents throws an ArgumentNullException when the assetPath is null or empty. This method loads a prefab asset's full contents into a temporary preview scene for editing, and requires a valid file path to the .prefab file.","triggerScenarios":"Calling PrefabUtility.LoadPrefabContents(null) or PrefabUtility.LoadPrefabContents(string.Empty). The method checks string.IsNullOrEmpty(assetPath) before attempting to load.","commonSituations":"Passing an AssetDatabase GUID instead of a path, using a path constructed from a missing/null variable, or calling with a path that failed to resolve from AssetDatabase.GUIDToAssetPath (which returns empty string for invalid GUIDs).","solutions":["Validate assetPath with !string.IsNullOrEmpty(assetPath) before calling.","Ensure you pass a project-relative path (e.g., 'Assets/Prefabs/MyPrefab.prefab'), not a GUID or absolute path.","If starting from a GUID, use AssetDatabase.GUIDToAssetPath(guid) and check the result is non-empty before passing."],"exampleFix":"// before\nvar contents = PrefabUtility.LoadPrefabContents(AssetDatabase.GUIDToAssetPath(guid));\n// after\nvar path = AssetDatabase.GUIDToAssetPath(guid);\nif (!string.IsNullOrEmpty(path))\n    var contents = PrefabUtility.LoadPrefabContents(path);","handlingStrategy":"validation","validationCode":"if (!string.IsNullOrEmpty(assetPath))\n    var contents = PrefabUtility.LoadPrefabContents(assetPath);","typeGuard":"static bool IsValidPrefabPath(string path) => !string.IsNullOrEmpty(path) && Path.GetExtension(path) == \".prefab\";","tryCatchPattern":null,"preventionTips":["Validate path with IsNullOrEmpty before calling LoadPrefabContents","If starting from GUID, check GUIDToAssetPath result for empty string","Always remember to call SaveAsPrefabAsset and UnloadPrefabContents after editing"],"tags":["unity","prefab","argument-null","asset-path","editor"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}