How to Use ScreenCapture.captureScreenShot in Unity
Save Unity’s rendered screen to a PNG with CaptureScreenshot, choose paths and resolution, handle Android timing, and fix common errors.
Use ScreenCapture.CaptureScreenshot. The spelling ScreenCapture.captureScreenShot is not the Unity API name. The method captures the final rendered screen, including the combined output of all cameras, and writes it to the filename you provide.
using UnityEngine;
public class ScreenshotExample : MonoBehaviour
{
void OnMouseDown()
{
ScreenCapture.CaptureScreenshot("SomeLevel.png");
}
}
Unity documents three overloads: a filename, a filename plus an integer superSize, and a filename plus ScreenCapture.StereoScreenCaptureMode. A .png filename produces PNG output. See the Unity 6 CaptureScreenshot reference.
1. Add a practical screenshot component
This component saves a uniquely named PNG when you press a key. Attach it to any active GameObject.
using System;
using System.IO;
using UnityEngine;
public sealed class RuntimeScreenshot : MonoBehaviour
{
[SerializeField] private KeyCode captureKey = KeyCode.F12;
[SerializeField] private string filePrefix = "screenshot";
private void Update()
{
if (Input.GetKeyDown(captureKey))
{
Capture();
}
}
public void Capture()
{
string filename = $"{filePrefix}_{DateTime.Now:yyyyMMdd_HHmmss_fff}.png";
string path = Path.Combine(Application.persistentDataPath, filename);
ScreenCapture.CaptureScreenshot(path);
Debug.Log($"Screenshot requested: {path}");
}
}
Using a timestamp prevents a later capture from overwriting an earlier one. Unity overwrites an existing file when the destination is the same.
2. Choose the output path correctly
| Target | Relative filename behavior | Recommended approach |
|---|---|---|
| Android or iOS | Unity appends the filename to Application.persistentDataPath. |
Pass a filename or an explicit path under persistentDataPath. |
| Windows or macOS Editor | A relative filename resolves against the Unity project directory, the folder containing Assets. |
Use an absolute path when another system needs to find the file. |
| Other desktop targets | Unity’s Unity 6 reference describes paths relative to the project directory. | Verify the target platform’s path rules in the version-specific documentation. |
For a predictable writable location, build the path yourself:
string path = Path.Combine(
Application.persistentDataPath,
"captures",
"level-01.png");
Directory.CreateDirectory(Path.GetDirectoryName(path));
ScreenCapture.CaptureScreenshot(path);
Do not assume the file is in Assets or beside the executable on every platform. Log the complete path and expose it in your in-game support screen if users need to retrieve captures.
3. Increase resolution with superSize
The integer overload multiplies the captured width and height. Unity’s example uses 4 for an image four times wider and four times taller, which produces sixteen times as many pixels.
// Normal output
ScreenCapture.CaptureScreenshot("normal.png");
// Four times the width and four times the height
ScreenCapture.CaptureScreenshot("large.png", 4);
Higher values require more memory, disk space and encoding time. Use the smallest multiplier that meets your output requirement, especially on mobile devices. Check the resulting dimensions on the actual target because the base screen size varies by device and window.
4. Capture stereoscopic output
For stereoscopic applications, use the overload that accepts ScreenCapture.StereoScreenCaptureMode and select the eye texture required by your project.
using UnityEngine;
public class StereoCapture : MonoBehaviour
{
public void CaptureStereo()
{
ScreenCapture.CaptureScreenshot(
"stereo.png",
ScreenCapture.StereoScreenCaptureMode.LeftEye);
}
}
The correct mode depends on how your project renders stereo content. Do not assume a single mode is right for every headset or rendering setup; confirm the available enum values and test on the target hardware.
5. Android completion timing
On Android, CaptureScreenshot returns immediately while Unity continues the capture in the background. The file may be written several seconds later. Code that opens, uploads or shares the image immediately after the call can therefore fail.
Poll for the file before consuming it, with a timeout:
using System.Collections;
using System.IO;
using UnityEngine;
public class AndroidCaptureConsumer : MonoBehaviour
{
public void CaptureAndProcess()
{
string path = Path.Combine(
Application.persistentDataPath,
"capture.png");
ScreenCapture.CaptureScreenshot(path);
StartCoroutine(WaitForCapture(path));
}
private IEnumerator WaitForCapture(string path)
{
const float timeoutSeconds = 15f;
float deadline = Time.realtimeSinceStartup + timeoutSeconds;
while (Time.realtimeSinceStartup < deadline)
{
if (File.Exists(path))
{
Debug.Log($"Capture ready: {path}");
// Read, upload or share the file here.
yield break;
}
yield return new WaitForSecondsRealtime(0.25f);
}
Debug.LogError($"Capture was not ready before timeout: {path}");
}
}
Use a unique path for each request if multiple captures can overlap. A file existing at the path does not prove that a newly requested capture has finished; remove or version old files before starting a new operation when that distinction matters.
6. What exactly gets captured?
The API captures the final rendered output shown to the user. It is not restricted to one selected Camera. When several cameras contribute to the frame, their combined result is captured. This makes it suitable for HUDs, post-processing and multi-camera compositions, but it is not a way to export an individual camera’s render texture.
7. Troubleshooting checklist
| Symptom | Likely cause | Fix |
|---|---|---|
Compiler error for captureScreenShot |
Incorrect casing or method name. | Use ScreenCapture.CaptureScreenshot with a capital C and S. |
| No file appears in the expected folder | Relative paths resolve differently by platform. | Log Application.persistentDataPath and pass an absolute path when needed. |
| The previous image was replaced | The destination filename was reused. | Generate a timestamp, GUID or sequence number. |
| Android code cannot open the image immediately | Android capture completes asynchronously. | Poll for file existence or use a later application-specific completion check. |
| Image is much larger than expected | superSize multiplies both dimensions. |
Lower the multiplier and calculate memory and storage needs before capture. |
| Only one camera appears in the result | The other camera did not contribute to the rendered frame. | Check camera enablement, depth/order and the frame in which capture is requested. |
| Capture works in Editor but not on device | Path, permissions, storage or platform timing differs. | Use persistentDataPath, log the resolved path and test on the shipping platform. |
8. Performance, reliability and storage
- Resolution: Pixel count grows with the square of
superSize; large captures increase memory pressure and encoding time. - Frequency: Avoid capturing every frame unless you have profiled the target device. Queue requests or rate-limit user actions.
- Disk space: PNG files can be large. Keep a retention policy, delete obsolete files and surface storage failures clearly.
- Reliability: Treat the call as a request. On Android, wait for the file before reading it. On every platform, handle missing directories and write failures.
- Consistency: Capture only after the desired scene, UI and camera state are active. If a transition is still rendering, the screenshot records that intermediate frame.
Or skip the browser setup
If your goal is a website screenshot rather than a Unity frame, ScreenshotNeo provides a single HTTP request. The API documentation covers all options.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
Cookie banners, newsletter popups and chat widgets are removed before the shot. Bot checks, blank pages and failed loads are never billed, and response headers identify the page verdict and billing status. An MCP server lets Claude, Cursor and other MCP clients take screenshots. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000.
Create your free ScreenshotNeo account.
FAQ
Does the method capture a Camera or the screen?
It captures the final rendered screen, including the combined output of cameras contributing to that frame.
Can I save JPEG instead of PNG?
The documented examples and behavior use a filename such as .png. CaptureScreenshot does not provide a format argument in the listed overloads; use the documented filename behavior for PNG output.
Can I rely on the file being ready when the method returns?
Not on Android. Unity documents background capture there, so wait before reading or uploading the file.
What happens if the filename already exists?
The existing file is overwritten. Generate unique names when retaining history matters.
Where can I confirm version-specific behavior?
Check the Unity 6 reference and the Unity 2017.3 reference for the version you target.


