{"record":{"id":"93d67ee7ea0042b6","repo":"Unity-Technologies/UnityCsReference","slug":"given-path-is-not-valid-path-93d67e","errorCode":null,"errorMessage":"Given path is not valid: '{path}'","messagePattern":"Given path is not valid: '(.+?)'","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Prefabs/PrefabUtility.cs","lineNumber":2044,"sourceCode":"\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))\n                throw new ArgumentException(\"Given path does not exist: '\" + path + \"'\");\n\n            if (isValidAssetFolder)","sourceCodeStart":2026,"sourceCodeEnd":2062,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Prefabs/PrefabUtility.cs#L2026-L2062","documentation":"ValidatePath throws ArgumentException when Paths.IsValidAssetPath(path, \".prefab\") fails — the path is not a syntactically valid prefab asset path. This covers wrong/missing extension, invalid characters, or a path that does not conform to Unity's asset path rules.","triggerScenarios":"Passing a path without the .prefab extension, with backslashes on a project that expects forward slashes, with illegal characters, or an absolute path instead of a project-relative one.","commonSituations":"Mixing System.IO.Path separators with Unity asset paths; forgetting the extension; passing an absolute OS path; copy-pasting a path with stray characters.","solutions":["Ensure the path is relative to the project folder and ends with .prefab.","Normalize separators to forward slashes and use AssetDatabase.GenerateUniqueAssetPath for a valid base.","Verify with Paths.IsValidAssetPath(path, \".prefab\") before calling when accessible, or check extension and characters manually."],"exampleFix":"// before\nPrefabUtility.SaveAsPrefabAsset(instance, @\"C:\\\\prefabs\\\\MyPrefab\");\n\n// after\nstring path = \"Assets/Prefabs/MyPrefab.prefab\";\npath = AssetDatabase.GenerateUniqueAssetPath(path);\nPrefabUtility.SaveAsPrefabAsset(instance, path);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(path) || !path.EndsWith(\".prefab\")) return;\npath = path.Replace('\\\\', '/');","typeGuard":"static bool IsValidPrefabPath(string path) =>\n    !string.IsNullOrEmpty(path) && path.EndsWith(\".prefab\")\n    && path.IndexOfAny(Path.GetInvalidPathChars()) < 0;","tryCatchPattern":null,"preventionTips":["Use forward slashes and a project-relative path ending in .prefab.","Normalize separators before constructing asset paths.","Prefer AssetDatabase.GenerateUniqueAssetPath to guarantee a valid, collision-free path."],"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"}