Unity-Technologies/UnityCsReference · error · ArgumentException
Invalid relative path (it is empty)
Error message
Invalid relative path (it is empty)
What it means
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.
Source
Thrown at Editor/Mono/ScriptableSingleton.cs:44
internal string filepath
{
get
{
if (m_FilePath == null && m_RelativePath != null)
{
m_FilePath = CombineFilePath(m_RelativePath, m_Location);
m_RelativePath = null;
}
return m_FilePath;
}
}
public FilePathAttribute(string relativePath, Location location)
{
if (string.IsNullOrEmpty(relativePath))
{
throw new ArgumentException("Invalid relative path (it is empty)");
}
m_RelativePath = relativePath;
m_Location = location;
}
static string CombineFilePath(string relativePath, Location location)
{
// We do not want a slash as first char
if (relativePath[0] == '/')
relativePath = relativePath.Substring(1);
switch (location)
{
case Location.PreferencesFolder: return InternalEditorUtility.unityPreferencesFolder + "/" + relativePath;
case Location.ProjectFolder: return relativePath;
default:
Debug.LogError("Unhandled enum: " + location);View on GitHub (pinned to 225b0fbdb5)
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.
Example fix
// before
[FilePath("")]
public class MySettings : ScriptableSingleton<MySettings> { }
// after
[FilePath("MySettings.ext")]
public class MySettings : ScriptableSingleton<MySettings> { } Defensive patterns
Strategy: validation
Validate before calling
// Compile-time: ensure the attribute has a non-empty literal path.
// [FilePath("MySettings.ext")] Prevention
- Always specify a non-empty path with a file extension in [FilePath].
- Use a dedicated constant for the path to avoid accidental clearing.
When it happens
Trigger: 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.
Common situations: Refactoring a ScriptableSingleton and accidentally clearing the path string. Copy-paste of a singleton class without updating the FilePath attribute.
Related errors
- Folder relative path cannot start with a slash.
- Incorrect file extension: {prefabAssetPath}. Must be '.prefa
- The LibraryFolderPathAttribute[] attribute is required for t
- Attempting to set an incorrect number of icons for {namedBui
- The setting label can't be null or empty.
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/c542234c9c595561.
Report an issue: GitHub.