{"record":{"id":"3b11dc42061b8b4c","repo":"CoplayDev/unity-mcp","slug":"preview-generation-was-aborted-due-to-a-change-of","errorCode":null,"errorMessage":"Preview generation was aborted due to a change of the scene","messagePattern":"Preview generation was aborted due to a change of the scene","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"TestProjects/AssetStoreUploads/Packages/com.unity.asset-store-tools/Editor/Previews/Scripts/Generators/Custom/TypeGenerators/TypePreviewGeneratorFromScene.cs","lineNumber":63,"sourceCode":"                EditorSceneManager.sceneOpened -= SceneOpenedDuringGeneration;\r\n                _cancellationTokenSource.Dispose();\r\n                if (!string.IsNullOrEmpty(originalScenePath))\r\n                    EditorSceneManager.OpenScene(originalScenePath);\r\n            }\r\n        }\r\n\r\n        protected abstract Task<List<PreviewMetadata>> GeneratePreviewsInScene(IEnumerable<UnityEngine.Object> assets);\r\n\r\n        private void SceneOpenedDuringGeneration(Scene _, OpenSceneMode __)\r\n        {\r\n            if (!_cancellationTokenSource.IsCancellationRequested)\r\n                _cancellationTokenSource.Cancel();\r\n        }\r\n\r\n        protected void ThrowIfSceneChanged()\r\n        {\r\n            if (_cancellationTokenSource.Token.IsCancellationRequested)\r\n                throw new Exception(\"Preview generation was aborted due to a change of the scene\");\r\n        }\r\n\r\n        protected Shader GetDefaultObjectShader()\r\n        {\r\n            switch (RenderPipelineUtility.GetCurrentPipeline())\r\n            {\r\n                case RenderPipeline.BiRP:\r\n                    return Shader.Find(\"Standard\");\r\n                case RenderPipeline.URP:\r\n                    return Shader.Find(\"Universal Render Pipeline/Lit\");\r\n                case RenderPipeline.HDRP:\r\n                    return Shader.Find(\"HDRP/Lit\");\r\n                default:\r\n                    throw new NotImplementedException(\"Undefined Render Pipeline\");\r\n            }\r\n        }\r\n\r\n        protected Shader GetDefaultParticleShader()\r","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/CoplayDev/unity-mcp/blob/c21bf496bca87d54e75bad048563c3adb1782081/TestProjects/AssetStoreUploads/Packages/com.unity.asset-store-tools/Editor/Previews/Scripts/Generators/Custom/TypeGenerators/TypePreviewGeneratorFromScene.cs#L45-L81","documentation":"Thrown by TypePreviewGeneratorFromScene.ThrowIfSceneChanged when the CancellationTokenSource has been cancelled. Cancellation is triggered by SceneOpenedDuringGeneration, which fires if the user or code opens a different scene during preview generation. This is a safety abort — the scene swap would corrupt in-progress preview capture.","triggerScenarios":"During GeneratePreviewsInScene execution, EditorSceneManager.sceneOpened fires (user opens/loads a scene), which calls _cancellationTokenSource.Cancel(). A subsequent ThrowIfSceneChanged() call observes the cancelled token and throws.","commonSituations":"User manually opens a different scene while preview generation is running; another editor script triggers scene loading during the async generation; automated test harness switches scenes; scene was double-clicked in Project window mid-generation.","solutions":["Do not change scenes while preview generation is in progress — wait for it to complete.","Wrap the Generate() call in a try-catch for this specific exception and restart generation if interrupted.","Lock scene switching in the editor (or show a progress bar with 'Cancel' instead of allowing manual scene changes) during generation.","If automating, ensure no concurrent scene operations run alongside preview generation."],"exampleFix":"// before\nvar previews = await generator.Generate();\n// unhandled exception if scene changes mid-generation\n\n// after\ntry\n{\n    var previews = await generator.Generate();\n}\ncatch (Exception ex) when (ex.Message.Contains(\"aborted due to a change of the scene\"))\n{\n    ASDebug.LogWarning(\"Preview generation interrupted by scene change. Retrying...\");\n    previews = await generator.Generate();\n}","handlingStrategy":"try-catch","validationCode":"// Prevent scene changes during generation by disabling scene operations\n// (no pure validation possible — the cancellation is triggered by an external event)\n// Best practice: show a modal progress bar that blocks user interaction\nEditorUtility.DisplayProgressBar(\"Preview Generation\", \"Generating previews...\", 0f);\ntry\n{\n    await generator.Generate();\n}\nfinally\n{\n    EditorUtility.ClearProgressBar();\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    previews = await generator.Generate();\n}\ncatch (Exception ex) when (ex.Message.Contains(\"aborted due to a change of the scene\"))\n{\n    ASDebug.LogWarning(\"Preview generation interrupted by scene change. Please avoid switching scenes during generation.\");\n    // Optionally retry after re-opening the preview scene\n    await PreviewSceneUtility.OpenPreviewSceneForCurrentPipeline();\n    previews = await generator.Generate();\n}","preventionTips":["Do not open or load scenes while preview generation is running.","Show a modal progress bar during generation to discourage scene switching.","In automation, ensure no concurrent scene operations run alongside generation.","Catch this specific exception and offer the user a retry option."],"tags":["unity","asset-store-tools","preview","scene","cancellation","concurrency"],"backgroundTag":null,"analyzedSha":"c21bf496bca87d54e75bad048563c3adb1782081","analyzedAt":"2026-08-13T17:36:56.095Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}