CoplayDev/unity-mcp · error · Exception
Preview generation was aborted due to a change of the scene
Error message
Preview generation was aborted due to a change of the scene
What it means
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.
Source
Thrown at TestProjects/AssetStoreUploads/Packages/com.unity.asset-store-tools/Editor/Previews/Scripts/Generators/Custom/TypeGenerators/TypePreviewGeneratorFromScene.cs:63
EditorSceneManager.sceneOpened -= SceneOpenedDuringGeneration;
_cancellationTokenSource.Dispose();
if (!string.IsNullOrEmpty(originalScenePath))
EditorSceneManager.OpenScene(originalScenePath);
}
}
protected abstract Task<List<PreviewMetadata>> GeneratePreviewsInScene(IEnumerable<UnityEngine.Object> assets);
private void SceneOpenedDuringGeneration(Scene _, OpenSceneMode __)
{
if (!_cancellationTokenSource.IsCancellationRequested)
_cancellationTokenSource.Cancel();
}
protected void ThrowIfSceneChanged()
{
if (_cancellationTokenSource.Token.IsCancellationRequested)
throw new Exception("Preview generation was aborted due to a change of the scene");
}
protected Shader GetDefaultObjectShader()
{
switch (RenderPipelineUtility.GetCurrentPipeline())
{
case RenderPipeline.BiRP:
return Shader.Find("Standard");
case RenderPipeline.URP:
return Shader.Find("Universal Render Pipeline/Lit");
case RenderPipeline.HDRP:
return Shader.Find("HDRP/Lit");
default:
throw new NotImplementedException("Undefined Render Pipeline");
}
}
protected Shader GetDefaultParticleShader()
View on GitHub (pinned to c21bf496bc)
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.
Example fix
// before
var previews = await generator.Generate();
// unhandled exception if scene changes mid-generation
// after
try
{
var previews = await generator.Generate();
}
catch (Exception ex) when (ex.Message.Contains("aborted due to a change of the scene"))
{
ASDebug.LogWarning("Preview generation interrupted by scene change. Retrying...");
previews = await generator.Generate();
} Defensive patterns
Strategy: try-catch
Validate before calling
// Prevent scene changes during generation by disabling scene operations
// (no pure validation possible — the cancellation is triggered by an external event)
// Best practice: show a modal progress bar that blocks user interaction
EditorUtility.DisplayProgressBar("Preview Generation", "Generating previews...", 0f);
try
{
await generator.Generate();
}
finally
{
EditorUtility.ClearProgressBar();
} Try / catch
try
{
previews = await generator.Generate();
}
catch (Exception ex) when (ex.Message.Contains("aborted due to a change of the scene"))
{
ASDebug.LogWarning("Preview generation interrupted by scene change. Please avoid switching scenes during generation.");
// Optionally retry after re-opening the preview scene
await PreviewSceneUtility.OpenPreviewSceneForCurrentPipeline();
previews = await generator.Generate();
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Width should be larger than 0
- Height should be larger than 0
- Depth should be larger than 0
- Native width should be larger than 0
- Native height should be larger than 0
AI-assisted analysis of CoplayDev/unity-mcp@c21bf496bc (2026-08-13).
Data as JSON: /api/errors/3b11dc42061b8b4c.
Report an issue: GitHub.