{"record":{"id":"c542dda7580a7442","repo":"Unity-Technologies/UnityCsReference","slug":"a-mode-named-0-already-exists-in-section-1","errorCode":null,"errorMessage":"A mode named {0} already exists in section {1}","messagePattern":"A mode named (.+?) already exists in section (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/SceneView/SceneView.cs","lineNumber":4640,"sourceCode":"            // Let's not persist the vertex snapping mode on 2D/3D mode change\n            HandleUtility.ignoreRaySnapObjects = null;\n            Tools.vertexDragging = false;\n            Tools.handleOffset = Vector3.zero;\n\n            var gridSettings = GridSettings.instance;\n            gridSettings.rotation = Quaternion.identity;\n            gridSettings.position = Vector3.zero;\n        }\n\n        public static CameraMode AddCameraMode(string name, string section)\n        {\n            if (string.IsNullOrEmpty(name))\n                throw new ArgumentException(\"Cannot be null or empty\", \"name\");\n            if (string.IsNullOrEmpty(section))\n                throw new ArgumentException(\"Cannot be null or empty\", \"section\");\n            var newMode = new CameraMode(DrawCameraMode.UserDefined, name, section);\n            if (userDefinedModes.Contains(newMode))\n                throw new InvalidOperationException(string.Format(\"A mode named {0} already exists in section {1}\", name, section));\n            userDefinedModes.Add(newMode);\n            return newMode;\n        }\n\n        private static bool IsValidCameraMode(CameraMode cameraMode)\n        {\n            foreach (var mode in Enum.GetValues(typeof(DrawCameraMode)))\n            {\n                if (SceneRenderModeWindow.DrawCameraModeExists((DrawCameraMode)mode) && cameraMode == GetBuiltinCameraMode((DrawCameraMode)mode))\n                {\n                    return true;\n                }\n            }\n\n            foreach (var tempCameraMode in userDefinedModes)\n            {\n                if (tempCameraMode == cameraMode)\n                {","sourceCodeStart":4622,"sourceCodeEnd":4658,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/SceneView/SceneView.cs#L4622-L4658","documentation":"Thrown by SceneView.AddCameraMode as an InvalidOperationException when the newly constructed CameraMode already exists in the static userDefinedModes list. Duplicate mode registration (same name and section) is not allowed because the dropdown would show ambiguous entries and the lookup logic assumes uniqueness.","triggerScenarios":"Calling AddCameraMode with the same name and section twice. Editor initialization code that runs on every domain reload re-registering modes without checking for existence. Multiple packages each registering the same mode name.","commonSituations":"InitializeOnLoad method that registers modes on every script recompilation. Two independent editor extensions using the same mode name in the same section.","solutions":["Check userDefinedModes (or use a helper) for an existing mode with the same name and section before adding.","Guard registration with [InitializeOnLoad] deduplication logic.","Use a unique name/section namespace prefix for your package's modes."],"exampleFix":"// before\nSceneView.AddCameraMode(\"MyMode\", \"Custom\");\n\n// after\nvar existing = SceneView.userDefinedModes.FirstOrDefault(m => m.name == \"MyMode\" && m.section == \"Custom\");\nif (existing == null)\n    SceneView.AddCameraMode(\"MyMode\", \"Custom\");","handlingStrategy":"validation","validationCode":"bool ModeExists(string name, string section)\n{\n    return SceneView.userDefinedModes.Any(m => m.name == name && m.section == section);\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    SceneView.AddCameraMode(name, section);\n}\ncatch (InvalidOperationException)\n{\n    // Mode already registered; retrieve existing instead.\n}","preventionTips":["Deduplicate mode registration in [InitializeOnLoad] methods.","Use unique name/section pairs per package to avoid collisions."],"tags":["unity","scene-view","editor","duplicate","validation"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}