{"record":{"id":"ba63c6d35bb75790","repo":"Unity-Technologies/UnityCsReference","slug":"path-is-null-or-empty","errorCode":null,"errorMessage":"path is null or empty","messagePattern":"path is null or empty","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Prefabs/PrefabUtility.cs","lineNumber":2041,"sourceCode":"\n            if (IsPartOfImmutablePrefab(asset))\n                throw new ArgumentException(\"Can't save an immutable Prefab\");\n\n            string path = AssetDatabase.GetAssetPath(asset);\n            if (String.IsNullOrEmpty(path))\n                throw new ArgumentException(\"Can't save a Prefab instance\");\n\n            var root = asset.transform.root.gameObject;\n            if (root != asset)\n                throw new ArgumentException(\"GameObject to save Prefab from must be a Prefab root\");\n\n            return SavePrefabAsset_Internal(root, out savedSuccessfully);\n        }\n\n        internal static void ValidatePath(GameObject instanceRoot, string path)\n        {\n            if (String.IsNullOrEmpty(path))\n                throw new ArgumentNullException(\"path is null or empty\");\n\n            if (!Paths.IsValidAssetPath(path, \".prefab\"))\n                throw new ArgumentException(\"Given path is not valid: '\" + path + \"'\");\n\n            if (Directory.Exists(path))\n                throw new ArgumentException(\"Overwriting a folder with an Asset is not allowed: '\" + path + \"'\");\n\n            string directory = Path.GetDirectoryName(path);\n\n            // We allow relative paths outside the Assets folder so we do not throw if isValidAssetFolder is false\n            bool isRootFolder = false;\n            bool isImmutableFolder = false;\n            bool isValidAssetFolder = AssetDatabase.TryGetAssetFolderInfo(directory, out isRootFolder, out isImmutableFolder);\n\n            if (isValidAssetFolder && isImmutableFolder)\n                throw new ArgumentException(\"Saving Prefab to immutable folder is not allowed: '\" + path + \"'\");\n\n            if (directory.Length > 0 && !Directory.Exists(directory))","sourceCodeStart":2023,"sourceCodeEnd":2059,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Prefabs/PrefabUtility.cs#L2023-L2059","documentation":"ValidatePath requires a non-null, non-empty path string for prefab save operations. A null or empty path cannot identify a target file, so ArgumentNullException is thrown at the start of the validation chain (before format checks).","triggerScenarios":"Calling a save API that routes through ValidatePath with path == null or path == \"\"; path constructed from a null/empty name component.","commonSituations":"Building a path from a missing prefab name field; user left the name blank in a save dialog; concatenation with a null variable.","solutions":["Build the path from a guaranteed non-empty name under a known folder, e.g., $\"Assets/{name}.prefab\".","Null/empty check the path before calling: if (!string.IsNullOrEmpty(path)).","Use AssetDatabase.GenerateUniqueAssetPath to produce a valid path from a base."],"exampleFix":"// before\nPrefabUtility.SaveAsPrefabAsset(instance, name);\n\n// after\nvar path = $\"Assets/{name}.prefab\";\nif (!string.IsNullOrEmpty(path))\n    PrefabUtility.SaveAsPrefabAsset(instance, path);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(path)) return;","typeGuard":"static bool HasNonEmptyPath(string path) => !string.IsNullOrEmpty(path);","tryCatchPattern":null,"preventionTips":["Construct the path from a guaranteed non-empty name under a known folder.","Null/empty-check the path before any save call routed through ValidatePath.","Use AssetDatabase.GenerateUniqueAssetPath to produce a valid path from a base."],"tags":["prefab","unity","path","validation"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}