{"record":{"id":"ef238c74f0375e1d","repo":"Unity-Technologies/UnityCsReference","slug":"no-duplication-of-scenes-is-allowed","errorCode":null,"errorMessage":"no duplication of scenes is allowed","messagePattern":"no duplication of scenes is allowed","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"Editor/Mono/GI/Lightmapping.bindings.cs","lineNumber":608,"sourceCode":"        public static extern LightingSettings GetLightingSettingsForScene(Scene scene);\n\n        [FreeFunction]\n        public static extern LightingDataAsset GetLightingDataAssetForScene(Scene scene);\n\n        [FreeFunction(ThrowsException = true)]\n        public static extern void SetLightingDataAssetForScene(Scene scene, LightingDataAsset lda);\n\n        public static void BakeMultipleScenes(string[] paths)\n        {\n            if (paths.Length == 0)\n                return;\n\n            for (int i = 0; i < paths.Length; i++)\n            {\n                for (int j = i + 1; j < paths.Length; j++)\n                {\n                    if (paths[i] == paths[j])\n                        throw new System.Exception(\"no duplication of scenes is allowed\");\n                }\n            }\n\n            if (!EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())\n                return;\n\n            var sceneSetup = EditorSceneManager.GetSceneManagerSetup();\n\n            // Restore old scene setup once the bake finishes\n            Action OnBakeFinish = null;\n            OnBakeFinish = () =>\n            {\n                EditorSceneManager.SaveOpenScenes();\n                if (sceneSetup.Length > 0)\n                    EditorSceneManager.RestoreSceneManagerSetup(sceneSetup);\n                Lightmapping.bakeCompleted -= OnBakeFinish;\n            };\n","sourceCodeStart":590,"sourceCodeEnd":626,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/GI/Lightmapping.bindings.cs#L590-L626","documentation":"Lightmapping.BakeMultipleScenes explicitly rejects duplicate scene paths in the input string[] with System.Exception, because Unity loads each path additively for the combined bake and duplicates would conflict. The comparison is an exact string equality check (ordinal, case-sensitive).","triggerScenarios":"Passing a string[] containing the same path twice (e.g. {\"Assets/A.unity\", \"Assets/A.unity\"}); building the array from selection/dependencies without dedup; including the active scene path that is also listed.","commonSituations":"Programmatic multi-scene bake scripts that assemble paths from a set that lost uniqueness; path strings that differ only by casing are treated as distinct (and both load), while exact duplicates throw.","solutions":["Deduplicate paths before calling: paths = paths.Distinct(System.StringComparer.Ordinal).ToArray();","Build the array from a HashSet<string> using an ordinal comparer.","Reject empty/null entries and verify each path resolves to a distinct scene."],"exampleFix":"// before\nLightmapping.BakeMultipleScenes(paths);\n// after\nvar deduped = paths.Where(p => !string.IsNullOrEmpty(p))\n                   .Distinct(System.StringComparer.Ordinal)\n                   .ToArray();\nLightmapping.BakeMultipleScenes(deduped);","handlingStrategy":"validation","validationCode":"var deduped = paths.Where(p => !string.IsNullOrEmpty(p))\n                   .Distinct(System.StringComparer.Ordinal)\n                   .ToArray();\nLightmapping.BakeMultipleScenes(deduped);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Dedup scene paths with an ordinal comparer before baking.","Reject empty/null path entries.","Build the path list from a HashSet<string> to prevent duplicates at the source."],"tags":["lightmapping","gi","multi-scene","validation","duplicate","unity"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}