- Home /
RenderTexture not working when in Editor
I've come to a point where my code works when compiled and run as standalone, but not when running within the editor.
I was wondering if there is something wrong in my code, or a limitation of some sort that I missed maybe.
Using the following code will work when compiled, but not in the editor. It's not a problem, as long as you know it does work in the end...
function TakePreview () {
// creating a Texture to Render to
var myRenderTexture = new RenderTexture(128, 96, 24);
myRenderTexture.Create();
// Setting the Camera to Render to the Texture
Camera.main.targetTexture = myRenderTexture;
// Setting the Texture to be the Active Texture to read from
RenderTexture.active = myRenderTexture;
// Creating a new Texture2D
var myTexture2D = new Texture2D (128, 96, TextureFormat.RGB24, false);
// Wait for the Frame to be fully rendered
yield WaitForEndOfFrame();
// Read pixels from the Render Texture into the Texture 2D
myTexture2D.ReadPixels(new Rect(0, 0, myRenderTexture.width, myRenderTexture.height), 0, 0);
myTexture2D.Apply();
// Reset Camera and Release the RenderTexture
Camera.main.targetTexture = null;
RenderTexture.active = null;
myRenderTexture.Release();
}
Where exactly does the code break? I'm not that experienced in Unity, but knowing what part of the method fails would help.
Answer by Jaroslav-Stehlik · Jul 13, 2015 at 02:19 PM
I know this will not help, but I have the same exact problem on Unity 5.1.1f1 OSX
Your answer
Follow this Question
Related Questions
Render Texture Black on Android Only 1 Answer
RenderTexture to create a movie very fast 1 Answer
RenderToCubemap with Image effect? 0 Answers
Do multiple viewpoints require Unity Pro? 1 Answer
RenderTarget in scripts 0 Answers