Convert existing RenderTexture for a Spritesheet

I am trying to take a RenderTexture and use it as a texture for a Spritesheet (with animations). This RenderTexture was created from a screenshot and has since been cropped and processed.

Currently, my biggest hurdle is getting a Texture2D version of the RenderTexture. Unfortunately, GetPixels does not work on RenderTextures. Also, if I understand it correctly, ReadPixels only applies to an active render camera - but I want to convert an existing RenderTexture.

How can I convert this existing RenderTexture to a Texture2D? …or am I going about this wrong?

Not sure what you mean by this. Is there some other purpose for using a RenderTexture than rendering from a camera?

This is code straight from my game Horde Rush:

        { // Render the main camera
            Camera mainCam = Camera.main;

            mainCam.targetTexture = Game.Instance.Script.ScreenshotTexture;

            if (mainCam.targetTexture != null)
                mainCam.Render();

            mainCam.targetTexture = null;
        }
       ....
       {   // Create the texture from the RenderTexture

            RenderTexture screenshot = Game.Instance.Script.ScreenshotTexture;
            RenderTexture.active = screenshot;

            int width = screenshot.width;
            int height = screenshot.height;

            Texture2D tex = new Texture2D(width, height);
            tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
            tex.Apply();
            Persistence.Instance.Mobile.Screenshot = tex;   // Save the screenshot
        }
1 Like

Ah, I misunderstood what the “active” state was all about. Your code explains this perfectly, thank you!