Version: 2023.2
LanguageEnglish
  • C#

ScreenCapture.CaptureScreenshotIntoRenderTexture

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public static void CaptureScreenshotIntoRenderTexture(RenderTexture renderTexture);

Parameters

renderTexture RenderTexture that will get filled with the screen content.

Description

Captures a screenshot of the game view into a RenderTexture object.

This variant of screen capture makes it possible to read pixels asynchronously using AsyncGPUReadback, making the process consume less time on the main thread.

For information on when to invoke this method, see the note in ScreenCapture.CaptureScreenshotAsTexture.

using UnityEngine;
using System.Collections;
using UnityEngine.Rendering;

public class ScreenCaptureIntoRenderTexture : MonoBehaviour { private RenderTexture renderTexture;

IEnumerator Start() { yield return new WaitForEndOfFrame();

renderTexture = new RenderTexture(Screen.width, Screen.height, 0); ScreenCapture.CaptureScreenshotIntoRenderTexture(renderTexture); AsyncGPUReadback.Request(renderTexture, 0, TextureFormat.RGBA32, ReadbackCompleted); }

void ReadbackCompleted(AsyncGPUReadbackRequest request) { // Render texture no longer needed, it has been read back. DestroyImmediate(renderTexture);

using (var imageBytes = request.GetData<byte>()) { // do something with the pixel data. } } }