Unity-Technologies/UnityCsReference · error · ArgumentException
GetCodeEditorForPath: Does not allow null editorPath
Error message
GetCodeEditorForPath: Does not allow null editorPath
What it means
ArgumentException thrown by CodeEditor.GetCodeEditorForPath when editorPath is null. The method resolves the IExternalCodeEditor for a path (with a SystemDefaultPath special case), iterating m_ExternalCodeEditors and falling back to m_DefaultEditor; null is explicitly rejected before lookup.
Solutions
- Null-check editorPath before calling and substitute CodeEditor.SystemDefaultPath.
- Set the script editor preference via CodeEditor.SetCodeEditor before resolving by path.
- Surface a clear error to the user (no code editor configured) rather than passing null.
Example fix
// before var editor = CodeEditor.GetCodeEditorForPath(path); // after var resolved = path ?? CodeEditor.SystemDefaultPath; var editor = CodeEditor.GetCodeEditorForPath(resolved);
Defensive patterns
Strategy: validation
Validate before calling
if (editorPath == null) editorPath = CodeEditor.SystemDefaultPath; var editor = CodeEditor.GetCodeEditorForPath(editorPath);
Prevention
- Substitute SystemDefaultPath for null paths.
- Validate preferences are set before resolution.
- Surface a clear 'no editor configured' message to users.
When it happens
Trigger: Calling CodeEditor.GetCodeEditorForPath(null). Happens when the path is sourced from preferences/detection that returned null, or when a caller forgets to supply the path.
Common situations: Unset external script editor preference; tooling that reads the editor path from a config that may be missing; migration where the pref key differs between Unity versions.
Related errors
- GetInstallationForPath: Does not allow null editorPath
- SetCodeEditor: Does not allow null editorPath
- A command with id already exists
- Android textureCompressionFormats can't be null or empty
- Attempting to assign an incorrect amount of layers to an…
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/2daec2cb73c92be1.
Report an issue: GitHub.
Appendix: source
Thrown at Editor/Mono/CodeEditor/CodeEditor.cs:140
return installation;
}
foreach (var codeEditor in m_ExternalCodeEditors)
{
if (codeEditor.TryGetInstallationForPath(editorPath, out installation))
{
return installation;
}
}
m_DefaultEditor.TryGetInstallationForPath(editorPath, out installation);
return installation;
}
public IExternalCodeEditor GetCodeEditorForPath(string editorPath)
{
if (editorPath == null)
{
throw new ArgumentException("GetCodeEditorForPath: Does not allow null editorPath");
}
if (editorPath == CodeEditor.SystemDefaultPath)
{
return m_DefaultEditor;
}
foreach (var codeEditor in m_ExternalCodeEditors)
{
if (codeEditor.TryGetInstallationForPath(editorPath, out _))
{
return codeEditor;
}
}
return m_DefaultEditor;
}
public Dictionary<string, string> GetFoundScriptEditorPaths()View on GitHub (pinned to 225b0fbdb5)