Unity-Technologies/UnityCsReference · error · ArgumentException
Folder relative path cannot start with a slash.
Error message
Folder relative path cannot start with a slash.
What it means
Thrown by LibraryFolderPathAttribute constructor when relativePath starts with a forward slash. The attribute prefixes the path with 'Library/' internally, so a leading slash would create a malformed path (e.g., 'Library//foo'). An empty or null path is handled separately via Debug.LogError (not an exception), but a leading slash is a hard error.
Source
Thrown at Editor/Mono/ScriptableSingletonDictionary.cs:31
{
// Use the LibraryFolderPathAttribute when you want to have your scriptable singleton dictionary
// to persist between unity sessions.
// Example: [LibraryFolderPathAttribute("EditorWindows")]
[AttributeUsage(AttributeTargets.Class)]
class LibraryFolderPathAttribute : Attribute
{
public string folderPath { get; set; }
public LibraryFolderPathAttribute(string relativePath)
{
if (string.IsNullOrEmpty(relativePath))
{
Debug.LogError("Invalid relative path! (its null or empty)");
return;
}
// We do not want a slash as first char.
if (relativePath[0] == '/')
throw new ArgumentException("Folder relative path cannot start with a slash.");
folderPath = "Library/" + relativePath;
}
}
internal abstract partial class ScriptableSingletonDictionary<TDerived, TValue> : ScriptableObject
where TDerived : ScriptableObject
where TValue : ScriptableObject
{
[AutoStaticsCleanupOnCodeReload]
private static TDerived s_Instance;
static readonly string k_Extension = ".pref";
protected string m_PreferencesFileName;
public static TDerived instance
{
getView on GitHub (pinned to 225b0fbdb5)
Solutions
- Remove the leading slash from the relative path.
- Use a relative path without a leading separator, e.g., [LibraryFolderPath("MyFolder")].
- Trim leading slashes if the path is dynamically generated: path.TrimStart('/').
Example fix
// before
[LibraryFolderPath("/MyFolder")]
internal class MyData : ScriptableSingletonDictionary<MyData, MyType> { }
// after
[LibraryFolderPath("MyFolder")]
internal class MyData : ScriptableSingletonDictionary<MyData, MyType> { } Defensive patterns
Strategy: validation
Validate before calling
// Compile-time: ensure the path does not start with '/'.
// [LibraryFolderPath("MyFolder")] Prevention
- Never prefix LibraryFolderPath paths with a leading slash.
- If generating paths dynamically, call TrimStart('/') before use.
When it happens
Trigger: Declaring [LibraryFolderPath("/MyFolder")] on a ScriptableSingletonDictionary subclass. Path constructed by concatenating a separator at the front.
Common situations: Copy-paste of absolute-style paths into the attribute. Convention mismatch where developers assume a leading slash is needed like in Unix paths.
Related errors
- Invalid relative path (it is empty)
- 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/c3c4e0087758057b.
Report an issue: GitHub.