{"record":{"id":"c542234c9c595561","repo":"Unity-Technologies/UnityCsReference","slug":"invalid-relative-path-it-is-empty","errorCode":null,"errorMessage":"Invalid relative path (it is empty)","messagePattern":"Invalid relative path \\(it is empty\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/ScriptableSingleton.cs","lineNumber":44,"sourceCode":"        internal string filepath\n        {\n            get\n            {\n                if (m_FilePath == null && m_RelativePath != null)\n                {\n                    m_FilePath = CombineFilePath(m_RelativePath, m_Location);\n                    m_RelativePath = null;\n                }\n\n                return m_FilePath;\n            }\n        }\n\n        public FilePathAttribute(string relativePath, Location location)\n        {\n            if (string.IsNullOrEmpty(relativePath))\n            {\n                throw new ArgumentException(\"Invalid relative path (it is empty)\");\n            }\n\n            m_RelativePath = relativePath;\n            m_Location = location;\n        }\n\n        static string CombineFilePath(string relativePath, Location location)\n        {\n            // We do not want a slash as first char\n            if (relativePath[0] == '/')\n                relativePath = relativePath.Substring(1);\n\n            switch (location)\n            {\n                case Location.PreferencesFolder: return InternalEditorUtility.unityPreferencesFolder + \"/\" + relativePath;\n                case Location.ProjectFolder:     return relativePath;\n                default:\n                    Debug.LogError(\"Unhandled enum: \" + location);","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/ScriptableSingleton.cs#L26-L62","documentation":"Thrown by FilePathAttribute constructor when relativePath is null or empty. This attribute decorates ScriptableSingleton-derived classes to specify where their data file lives; an empty path means there is no valid location to serialize to. The path is later combined with a base directory depending on the Location enum.","triggerScenarios":"Declaring [FilePath(\"\")] or [FilePath(null)] on a ScriptableSingleton subclass. Dynamically constructing the attribute path from a constant that is conditionally defined and resolves to empty.","commonSituations":"Refactoring a ScriptableSingleton and accidentally clearing the path string. Copy-paste of a singleton class without updating the FilePath attribute.","solutions":["Provide a non-empty relative path in the FilePath attribute, e.g. [FilePath(\"MySettings.ext\")].","Ensure the path constant is defined and non-empty at compile time.","Use a meaningful filename including extension."],"exampleFix":"// before\n[FilePath(\"\")]\npublic class MySettings : ScriptableSingleton<MySettings> { }\n\n// after\n[FilePath(\"MySettings.ext\")]\npublic class MySettings : ScriptableSingleton<MySettings> { }","handlingStrategy":"validation","validationCode":"// Compile-time: ensure the attribute has a non-empty literal path.\n// [FilePath(\"MySettings.ext\")]","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always specify a non-empty path with a file extension in [FilePath].","Use a dedicated constant for the path to avoid accidental clearing."],"tags":["unity","scriptable-singleton","editor","validation","path"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}