Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Screenshot issue

Discussion in 'Scripting' started by -RaganorK-, Sep 1, 2015.

  1. -RaganorK-

    -RaganorK-

    Joined:
    May 9, 2014
    Posts:
    14
    Hello, I am facing an issue while taking a screenshot.
    I have placed a new camera in the scene, and whenever player is passing below the camera, I am enabling the camera and rendering the camera (Camera.Render () ) and taking a screenshot. The problem is, whenever I am doing this, it is rendered on the screen (means the main camera shows what the other camera is rendering). I don't want it to show what the other camera is rendering. Its a strange issue as it is not happening in the iOS platform but only on Android platform.
     
  2. tonemcbride

    tonemcbride

    Joined:
    Sep 7, 2010
    Posts:
    1,077
    You can create and render to a camera in code without displaying to the screen if you use a render texture. e.g.

    // Create camera
    GameObject RenderCamera = new GameObject();
    RenderCamera.AddComponent( typeof( Camera ) );

    // Create temp render texture
    RenderTexture renderTexture = RenderTexture.GetTemporary(GrabWidth , GrabHeight, 24);
    RenderTexture.active = renderTexture;

    // Set camera to use render texture and then render the frame
    RenderCamera.camera.targetTexture = renderTexture;
    RenderCamera.camera.Render();

    // Save screenshot here using renderTexture
    // TO-DO

    // Destroy camera
    RenderTexture.active = null;
    RenderTexture.ReleaseTemporary( renderTexture );
    GameObject.Destroy( RenderCamera );
     
  3. -RaganorK-

    -RaganorK-

    Joined:
    May 9, 2014
    Posts:
    14
    tonemcbride: Thanks, but it is still rendering on the screen for a fraction of time, but very visible.