CoplayDev/unity-mcp · error · Exception

Preview loading timed out.

Error message

Preview loading timed out.

What it means

Thrown by NativePreviewGenerator.WaitAndWritePreviews (NativePreviewGenerator.cs:254) as a generic Exception after InitialPreviewLoadingTimeoutSeconds (10s) elapse without AssetPreview producing a single preview for the current batch (remainingObjectCount never drops below initialObjectCount). Unlike the Validate() errors, this is thrown inside GenerateImpl()'s try/catch, so it is captured into result.Exception with result.Success = false rather than propagating. It indicates Unity's AssetPreview subsystem is not delivering textures in time.

Solutions

  1. Let Unity finish importing the target assets before generating (wait for the import queue to drain), then re-run.
  2. Enable ChunkedPreviewLoading with an adequate ChunkSize so the AssetPreview cache (sized ChunkSize*2) is not starved.
  3. Switch to WaitForPreviews=false, which uses WritePreviewsWithoutWaiting and does not poll/timeout.

Example fix

// before: waitForPreviews true, chunkSize 0 -> validation throws first; if set but previews stall, you hit the timeout
var s = new NativePreviewGenerationSettings { InputPaths = paths, OutputPath = out, ChunkSize = 5, WaitForPreviews = true };

// after: non-blocking path avoids the polling timeout entirely
var s = new NativePreviewGenerationSettings { InputPaths = paths, OutputPath = out, ChunkSize = 100, WaitForPreviews = false };
Defensive patterns

Strategy: retry

Validate before calling

// Nothing to validate pre-call; instead ensure assets are imported first.
if (EditorApplication.isCompiling || EditorApplication.isUpdating)
    throw new InvalidOperationException("Wait for Unity to finish importing/updating before generating previews.");

Try / catch

// GenerateImpl captures this into result.Exception; check the result, not an exception:
var result = await generator.Generate();
if (!result.Success && result.Exception?.Message.Contains("timed out") == true) { /* let imports finish, then retry or fall back to WaitForPreviews=false */ }

Prevention

When it happens

Trigger: Running the native generator with WaitForPreviews=true on assets whose previews AssetPreview never loads within 10 seconds. Common when target assets (large models/textures/materials) are still importing, when the AssetPreview texture cache is starved by a too-small ChunkSize, or under Unity Editor streams where AssetPreview loading is known to be inconsistent (see the code comment 'works inconsistently across Unity streams').

Common situations: Generating previews immediately after an AssetDatabase.Refresh / import that hasn't finished; very large asset sets; a Unity version with a flaky AssetPreview; running headless/batchmode where preview generation is unreliable.

Understand the failure class

Related errors


AI-assisted analysis of CoplayDev/unity-mcp@c21bf496bc (2026-08-13). Data as JSON: /api/errors/6d98aba43c322cf1. Report an issue: GitHub.

Appendix: source

Thrown at TestProjects/AssetStoreUploads/Packages/com.unity.asset-store-tools/Editor/Previews/Scripts/Generators/NativePreviewGenerator.cs:254

        private async Task WaitAndWritePreviews(List<PreviewMetadata> objects, List<PreviewMetadata> generatedPreviews)
        {
            var initialObjectCount = objects.Count();
            if (initialObjectCount == 0)
                return;

            await WaitAndWritePreviewIteration(objects, generatedPreviews);
            var remainingObjectCount = objects.Count;

            // First iteration may take longer to start loading objects
            var firstIterationStartTime = EditorApplication.timeSinceStartup;
            while (true)
            {
                if (remainingObjectCount < initialObjectCount)
                    break;

                if (EditorApplication.timeSinceStartup - firstIterationStartTime > InitialPreviewLoadingTimeoutSeconds)
                    throw new Exception("Preview loading timed out.");

                await WaitAndWritePreviewIteration(objects, generatedPreviews);
                remainingObjectCount = objects.Count;
            }

            if (remainingObjectCount == 0)
                return;

            while (true)
            {
                await WaitForEndOfFrame(1);
                await WaitAndWritePreviewIteration(objects, generatedPreviews);

                // If no more previews are being loaded, try one more time before quitting
                if (objects.Count == remainingObjectCount)
                {
                    await WaitForEndOfFrame(1);
                    await WaitAndWritePreviewIteration(objects, generatedPreviews);

View on GitHub (pinned to c21bf496bc)