Skip to content

fix(screenshot): capture full Game view — multi-camera + Screen Space-Overlay UI (#33)#34

Open
travlake wants to merge 1 commit into
youngwoocho02:mainfrom
travlake:fix/screenshot-game-view-full-capture
Open

fix(screenshot): capture full Game view — multi-camera + Screen Space-Overlay UI (#33)#34
travlake wants to merge 1 commit into
youngwoocho02:mainfrom
travlake:fix/screenshot-game-view-full-capture

Conversation

@travlake

Copy link
Copy Markdown
Contributor

Problem

screenshot --view game returns a black / UI-less image on projects whose Game view is composited from multiple stacked cameras and/or whose HUD lives on Screen Space - Overlay canvases (#33).

Root cause

CaptureGameView rendered a single camera.Render() (Camera.main, else an arbitrary FindObjectOfType<Camera>()) into an offscreen RenderTexture. That cannot reproduce a multi-camera stack, and camera.Render() never includes Screen Space - Overlay UI — overlay canvases are composited onto the back buffer after camera render. So the capture came back black / with the UI missing.

Fix

Capture the actual composited back buffer via ScreenCapture.CaptureScreenshot (every stacked camera + all UI, including overlay), awaited end-of-frame using the router's existing async Task<object> handler support (same pattern as RunTests/ManageEditor).

  • Completion via PNG IEND chunk — the wait checks for the trailing IEND bytes rather than length > 0, so a partially written file is never returned (ScreenCapture's write is not atomic).
  • Bounded wait — by both frame count (120) and wall-clock (3s), and torn down on beforeAssemblyReload, so an in-flight capture can never leak the update subscription or hold the command lock indefinitely.
  • Fallback — if no frame renders in time (no Game view, batch mode), falls back to a depth-ordered multi-camera composite that honors each camera's clear flags. Its response message explicitly warns that Screen Space - Overlay UI is omitted (so the degradation is never silent). Note: camera.Render() compositing assumes the built-in render pipeline.

Scene view behaviour is unchanged (single SceneView camera). Adds super_size (1-4) for the primary path; width/height continue to size the fallback.

Verification

Built against the connector in Unity 2021.3.45f2 (built-in pipeline) and exercised end-to-end through the live connector: screenshot --view game now captures the full Game view — multi-camera background and all UI canvases — in both edit mode and play mode, where it previously returned solid black.

Fixes #33.

`screenshot --view game` rendered a single camera into an offscreen
RenderTexture (Camera.main, else an arbitrary camera). That cannot
reproduce a multi-camera stack, and camera.Render() never includes
Screen Space - Overlay UI (overlay canvases composite onto the back
buffer after camera render) - so the capture came back black / with
the UI missing. Fixes youngwoocho02#33.

Game view now captures the actual composited back buffer via
ScreenCapture.CaptureScreenshot (every stacked camera + all UI,
including overlay), awaited end-of-frame using the router's existing
async Task<object> handler support. Completion is detected by the PNG
IEND chunk so a partially written file is never returned; the wait is
bounded by both frame count and wall-clock and is torn down on domain
reload. If no frame renders in time (no Game view, batch mode) it falls
back to a depth-ordered multi-camera composite whose response message
explicitly warns that Screen Space - Overlay UI is omitted.

Scene view behaviour is unchanged. Adds super_size (1-4) for the
primary path.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

unity-cli screenshot --view game 실행시 UI 표시 되지 않음

1 participant