Search Unity

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,089
    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.