Legacy Documentation: Version 4.6.2
Language: English
  • C#
  • JS
  • Boo

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

RenderTexture.active

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

Sumbission failed

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

Close

Cancel

public static var active: RenderTexture;
public static RenderTexture active;
public static active as RenderTexture

Description

The active render texture.

All rendering goes into the active RenderTexture. If the active RenderTexture is null everything is rendered in the main window.

When a RenderTexture becomes active its hardware rendering context is automatically created if it hasn't been created already.

// Get the contents of a RenderTexture into a Texture2D.
function GetRTPixels(rt: RenderTexture) {
	// Keep a note of the currently active RenderTexture.
	var currentActiveRT = RenderTexture.active;
	
	// Set the supplied RenderTexture as the active one.
	RenderTexture.active = rt;
	
	// Create a new Texture2D and read the RenderTexture image
	// into it.
	var tex = new Texture2D(rt.width, rt.height);
	tex.ReadPixels(new Rect(0, 0, tex.width, tex.height), 0, 0);
	
	// Set the previously active RenderTexture back before returning.
	RenderTexture.active = currentActiveRT;
	return tex;
}
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    Texture2D GetRTPixels(RenderTexture rt) {
        RenderTexture currentActiveRT = RenderTexture.active;
        RenderTexture.active = rt;
        Texture2D tex = new Texture2D(rt.width, rt.height);
        tex.ReadPixels(new Rect(0, 0, tex.width, tex.height), 0, 0);
        RenderTexture.active = currentActiveRT;
        return tex;
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	def GetRTPixels(rt as RenderTexture) as Texture2D:
		currentActiveRT as RenderTexture = RenderTexture.active
		RenderTexture.active = rt
		tex as Texture2D = Texture2D(rt.width, rt.height)
		tex.ReadPixels(Rect(0, 0, tex.width, tex.height), 0, 0)
		RenderTexture.active = currentActiveRT
		return tex