{"record":{"id":"192f39908ebaa08b","repo":"CoplayDev/unity-mcp","slug":"captured-scene-view-viewport-is-empty","errorCode":null,"errorMessage":"Captured Scene view viewport is empty.","messagePattern":"Captured Scene view viewport is empty\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"MCPForUnity/Editor/Helpers/EditorWindowScreenshotUtility.cs","lineNumber":65,"sourceCode":"            bool includeImage,\n            int maxResolution,\n            out int viewportWidth,\n            out int viewportHeight,\n            string folderOverride = null)\n        {\n            if (sceneView == null)\n                throw new ArgumentNullException(nameof(sceneView));\n\n            int effectiveSuperSize = NormalizeSceneViewSuperSize(superSize);\n\n            FocusAndRepaint(sceneView);\n\n            Rect viewportRectPixels = GetSceneViewViewportPixelRect(sceneView);\n            viewportWidth = Mathf.RoundToInt(viewportRectPixels.width);\n            viewportHeight = Mathf.RoundToInt(viewportRectPixels.height);\n\n            if (viewportWidth <= 0 || viewportHeight <= 0)\n                throw new InvalidOperationException(\"Captured Scene view viewport is empty.\");\n\n            Texture2D captured = null;\n            Texture2D downscaled = null;\n            try\n            {\n                captured = CaptureViewRect(sceneView, viewportRectPixels);\n\n                var result = PrepareCaptureResult(fileName, effectiveSuperSize, ensureUniqueFileName, folderOverride);\n                byte[] png = captured.EncodeToPNG();\n                File.WriteAllBytes(result.FullPath, png);\n\n                if (includeImage)\n                {\n                    int targetMax = maxResolution > 0 ? maxResolution : 640;\n                    string imageBase64;\n                    int imageWidth;\n                    int imageHeight;\n","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/CoplayDev/unity-mcp/blob/c21bf496bca87d54e75bad048563c3adb1782081/MCPForUnity/Editor/Helpers/EditorWindowScreenshotUtility.cs#L47-L83","documentation":"CaptureSceneViewViewportToProject resolves the Scene View viewport pixel rect, then checks that viewportWidth and viewportHeight are positive. If both dimensions resolved to zero or negative, it throws InvalidOperationException. This means the rect computation succeeded (no earlier exception) but produced an empty area — the Scene View exists but has no drawable surface.","triggerScenarios":"Capturing a Scene View that is docked but has zero visible area (fully covered by other tabs/panels), minimized, or in a headless/batchmode Editor session where no actual viewport is rendered.","commonSituations":"Running Unity in batchmode (-batchmode flag) where there is no rendered Scene View. The Scene View tab is hidden behind a maximized Game View or Inspector. Capturing during a layout transition. Running in a CI environment without a display.","solutions":["Ensure the Scene View window is visible and has non-zero area before capturing.","Do not call scene capture in batchmode or headless Unity sessions.","If in CI, run with a display or use off-screen rendering alternatives."],"exampleFix":"// before\nvar result = EditorWindowScreenshotUtility.CaptureSceneViewViewportToProject(sceneView, ...);\n\n// after\nif (sceneView.position.width <= 0 || sceneView.position.height <= 0)\n    throw new InvalidOperationException(\"Scene View is not visible.\");\nvar result = EditorWindowScreenshotUtility.CaptureSceneViewViewportToProject(sceneView, ...);","handlingStrategy":"validation","validationCode":"Rect pos = sceneView.position;\nif (pos.width <= 0 || pos.height <= 0) return;\nif (Application.isBatchMode) return;","typeGuard":"public static bool IsSceneViewCapturable(SceneView sv) =>\n    sv != null && sv.position.width > 0 && sv.position.height > 0 && !Application.isBatchMode;","tryCatchPattern":"try { CaptureSceneViewViewportToProject(sceneView, ...); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"viewport is empty\"))\n{ Debug.LogWarning(\"Scene View has no visible area; cannot capture.\"); }","preventionTips":["Never call scene capture in batchmode or headless Unity.","Ensure the Scene View is visible and has non-zero dimensions before capturing.","Check Application.isBatchMode before invoking capture."],"tags":["screenshot","scene-view","viewport","headless","editor"],"backgroundTag":null,"analyzedSha":"c21bf496bca87d54e75bad048563c3adb1782081","analyzedAt":"2026-08-13T17:36:56.095Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}