Unity-Technologies/UnityCsReference · error · Exception
no duplication of scenes is allowed
Error message
no duplication of scenes is allowed
What it means
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).
Source
Thrown at Editor/Mono/GI/Lightmapping.bindings.cs:608
public static extern LightingSettings GetLightingSettingsForScene(Scene scene);
[FreeFunction]
public static extern LightingDataAsset GetLightingDataAssetForScene(Scene scene);
[FreeFunction(ThrowsException = true)]
public static extern void SetLightingDataAssetForScene(Scene scene, LightingDataAsset lda);
public static void BakeMultipleScenes(string[] paths)
{
if (paths.Length == 0)
return;
for (int i = 0; i < paths.Length; i++)
{
for (int j = i + 1; j < paths.Length; j++)
{
if (paths[i] == paths[j])
throw new System.Exception("no duplication of scenes is allowed");
}
}
if (!EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
return;
var sceneSetup = EditorSceneManager.GetSceneManagerSetup();
// Restore old scene setup once the bake finishes
Action OnBakeFinish = null;
OnBakeFinish = () =>
{
EditorSceneManager.SaveOpenScenes();
if (sceneSetup.Length > 0)
EditorSceneManager.RestoreSceneManagerSetup(sceneSetup);
Lightmapping.bakeCompleted -= OnBakeFinish;
};
View on GitHub (pinned to 225b0fbdb5)
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.
Example fix
// before
Lightmapping.BakeMultipleScenes(paths);
// after
var deduped = paths.Where(p => !string.IsNullOrEmpty(p))
.Distinct(System.StringComparer.Ordinal)
.ToArray();
Lightmapping.BakeMultipleScenes(deduped); Defensive patterns
Strategy: validation
Validate before calling
var deduped = paths.Where(p => !string.IsNullOrEmpty(p))
.Distinct(System.StringComparer.Ordinal)
.ToArray();
Lightmapping.BakeMultipleScenes(deduped); Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- index must be between 0 and {albedoTexturePropertiesCount -
- index must be between 0 and {emissiveTexturePropertiesCount
- index must be between 0 and {transmissiveTextureCount - 1},
- index must be between 0 and {transmissiveTexturePropertiesCo
- index must be between 0 and {GetCookieCount() - 1}, but was
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/ef238c74f0375e1d.
Report an issue: GitHub.