Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to create some image effect. I've written a script that draws a cube mesh at the render target and then copies the render texture at the screen. I don't want to render anything except Mesh(M) in my RenderTexture(rt):

    void OnRenderImage(RenderTexture src, RenderTexture dest)
        RenderTexture rt = RenderTexture.GetTemporary(Screen.width / 1, Screen.height / 1 );

        Graphics.DrawMeshNow(M, new Vector3(0.0f, 0.0f, -8.0f), Quaternion.identity);
        Graphics.Blit(rt, dest);


Where M is GameObject.CreatePrimitive(PrimitiveType.Cube).GetComponent<MeshFilter>().sharedMesh;

When I moved my camera, I see this: enter image description here

It seems like the RenderTexture didn't cleared itself when released. Or maybe I did something wrong? Please explain why this happened and how can I fix this.

share|improve this question
up vote 4 down vote accepted

That is correct: RenderTextures are not necessarily cleared after being released or reacquired.

According to the documentation:

You can not depend on any particular contents of the RenderTexture you get from GetTemporary function. It might be garbage, or it might be cleared to some color, depending on the platform.

If you want the RenderTexture to be cleared, then you'll need to clear it yourself after acquiring it.

share|improve this answer
+1 Documentation. – Patrick Hughes Mar 10 '14 at 4:18
Yep, docs rules. Thanks a lot! – Netherwire Mar 10 '14 at 18:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.