{"record":{"id":"df83a72b2007142e","repo":"Unity-Technologies/UnityCsReference","slug":"given-path-does-not-exist-path","errorCode":null,"errorMessage":"Given path does not exist: '{path}'","messagePattern":"Given path does not exist: '(.+?)'","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Prefabs/PrefabUtility.cs","lineNumber":2060,"sourceCode":"\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)\n            {\n                string projectRelativePath = Path.IsPathRooted(path) ? FileUtil.GetProjectRelativePath(path) : path;\n                string prefabGUID = AssetDatabase.AssetPathToGUID(projectRelativePath);\n                if (!VerifyNestingFromScript(new GameObject[] { instanceRoot }, prefabGUID, PrefabUtility.GetPrefabInstanceHandle(instanceRoot)))\n                    throw new ArgumentException(\"Cyclic nesting detected\");\n            }\n        }\n\n        private static void SaveAsPrefabAssetArgumentCheck(GameObject instanceRoot, string path, bool connectToInstance)\n        {\n            if (instanceRoot == null)\n                throw new ArgumentNullException(\"Parameter root is null\");\n\n            if (EditorUtility.IsPersistent(instanceRoot) && connectToInstance)\n                throw new ArgumentException(\"Can't save persistent Objects and connect them to the saved Prefab\");\n","sourceCodeStart":2042,"sourceCodeEnd":2078,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Prefabs/PrefabUtility.cs#L2042-L2078","documentation":"Thrown by ValidatePath when the parent directory of the target Prefab path does not exist on disk. Unity requires the destination folder to exist before writing the .prefab file; it does not auto-create intermediate directories during Prefab save operations.","triggerScenarios":"Calling a SaveAsPrefab API with a path whose directory portion is valid (resolves inside Assets) but has not been created yet. The check is directory.Length > 0 && !Directory.Exists(directory).","commonSituations":"Developer assumes Unity creates missing folders automatically. Path is dynamically generated with a subfolder that hasn't been created. Moving from a machine where the folder existed to a fresh checkout.","solutions":["Create the directory before saving: if (!Directory.Exists(dir)) Directory.CreateDirectory(dir);","Use AssetDatabase.CreateFolder(\"Assets\", \"NewFolder\") for folders inside the Assets hierarchy.","Verify the path is relative to the project root and the parent exists before constructing the full path."],"exampleFix":"// before\nPrefabUtility.SaveAsPrefabAsset(go, \"Assets/NewFolder/My.prefab\");\n// after\nstring dir = \"Assets/NewFolder\";\nif (!AssetDatabase.IsValidFolder(dir))\n    AssetDatabase.CreateFolder(\"Assets\", \"NewFolder\");\nPrefabUtility.SaveAsPrefabAsset(go, \"Assets/NewFolder/My.prefab\");","handlingStrategy":"validation","validationCode":"void EnsureDirectoryExists(string path)\n{\n    string dir = Path.GetDirectoryName(path);\n    if (!string.IsNullOrEmpty(dir) && !Directory.Exists(dir))\n    {\n        string parent = Path.GetDirectoryName(dir);\n        string folder = Path.GetFileName(dir);\n        if (AssetDatabase.IsValidFolder(parent))\n            AssetDatabase.CreateFolder(parent, folder);\n        else\n            Directory.CreateDirectory(dir);\n    }\n}","typeGuard":"static bool DirectoryForPathExists(string path) =>\n    string.IsNullOrEmpty(Path.GetDirectoryName(path)) ||\n    Directory.Exists(Path.GetDirectoryName(path));","tryCatchPattern":null,"preventionTips":["Always create the target folder before calling SaveAsPrefabAsset.","Use AssetDatabase.CreateFolder for paths inside Assets/.","Wrap batch-save scripts with a directory-ensure helper."],"tags":["unity","prefab","path-validation","missing-directory"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}