Unity-Technologies/UnityCsReference · error · ArgumentException
Cannot be null or empty
Error message
Cannot be null or empty
What it means
Thrown by SceneView.AddCameraMode when the name parameter is null or empty. A custom camera mode requires a non-empty display name to appear in the scene view draw mode dropdown. This is the first of two guards in AddCameraMode (name, then section).
Source
Thrown at Editor/Mono/SceneView/SceneView.cs:4635
LookAt(pivot, lastSceneViewRotation, size, m_LastSceneViewOrtho);
if (Tools.current == Tool.Rect)
Tools.current = Tool.Move;
}
// Let's not persist the vertex snapping mode on 2D/3D mode change
HandleUtility.ignoreRaySnapObjects = null;
Tools.vertexDragging = false;
Tools.handleOffset = Vector3.zero;
var gridSettings = GridSettings.instance;
gridSettings.rotation = Quaternion.identity;
gridSettings.position = Vector3.zero;
}
public static CameraMode AddCameraMode(string name, string section)
{
if (string.IsNullOrEmpty(name))
throw new ArgumentException("Cannot be null or empty", "name");
if (string.IsNullOrEmpty(section))
throw new ArgumentException("Cannot be null or empty", "section");
var newMode = new CameraMode(DrawCameraMode.UserDefined, name, section);
if (userDefinedModes.Contains(newMode))
throw new InvalidOperationException(string.Format("A mode named {0} already exists in section {1}", name, section));
userDefinedModes.Add(newMode);
return newMode;
}
private static bool IsValidCameraMode(CameraMode cameraMode)
{
foreach (var mode in Enum.GetValues(typeof(DrawCameraMode)))
{
if (SceneRenderModeWindow.DrawCameraModeExists((DrawCameraMode)mode) && cameraMode == GetBuiltinCameraMode((DrawCameraMode)mode))
{
return true;
}
}View on GitHub (pinned to 225b0fbdb5)
Solutions
- Provide a non-empty, non-null name string.
- Validate the name with string.IsNullOrEmpty before calling AddCameraMode.
- Use a sensible default name if the source value is empty.
Example fix
// before SceneView.AddCameraMode(modeName, "Custom"); // after string name = string.IsNullOrEmpty(modeName) ? "UnnamedMode" : modeName; SceneView.AddCameraMode(name, "Custom");
Defensive patterns
Strategy: validation
Validate before calling
bool IsValidModeName(string name)
{
return !string.IsNullOrEmpty(name);
} Prevention
- Validate the name parameter with string.IsNullOrEmpty before calling AddCameraMode.
- Provide a sensible default name when the source value is empty.
When it happens
Trigger: Calling SceneView.AddCameraMode with an empty string or null for name. Programmatic mode creation where the name is derived from user input or config that can be empty.
Common situations: Editor extension that registers custom draw modes based on configurable names. Data-driven mode registration where a config entry is missing the name field.
Related errors
- Use cameraMode to set user-defined modes
- The provided camera mode {0} is not registered!
- A mode named {0} already exists in section {1}
- 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/5a277695325171f9.
Report an issue: GitHub.