1
\$\begingroup\$

I am trying to capture different parts of a scene created in Unity. I have two cameras capturing different parts of the scene. Now, I need to take screenshots using these two cameras simultaneously. Right now, every time take a screenshot, it only captures scene from one camera. Thank you!

\$\endgroup\$
2
\$\begingroup\$

A screenshot is done at the hardware level. It only knows what is visible on your hardware screen. It is not camera dependent.

What you are looking for is the camera rendering. Unity documentation provides us with a nice code snippet of how to do this:

using UnityEngine;

public class Example : MonoBehaviour
{
    // Take a "screenshot" of a camera's Render Texture.
    Texture2D RTImage(Camera camera)
    {
        // The Render Texture in RenderTexture.active is the one
        // that will be read by ReadPixels.
        var currentRT = RenderTexture.active;
        RenderTexture.active = camera.targetTexture;

        // Render the camera's view.
        camera.Render();

        // Make a new texture and read the active Render Texture into it.
        Texture2D image = new Texture2D(camera.targetTexture.width, camera.targetTexture.height);
        image.ReadPixels(new Rect(0, 0, camera.targetTexture.width, camera.targetTexture.height), 0, 0);
        image.Apply();

        // Replace the original active Render Texture.
        RenderTexture.active = currentRT;
        return image;
    }
}
| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ How does this work if my camera doesn't have a render texture assigned? I want to capture the view of an AR camera. \$\endgroup\$ – waldgeist Jun 5 at 10:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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