- Home /
How do I freeze the camera frame?
In certain scenarios in my game, I'd like to freeze the camera and stop all rendering but still show the last rendered frame.
Answer by jpthek9 · Feb 25, 2015 at 06:42 AM
The answer was pretty simple and intuitive but had some intuitive quirks. To freeze the camera, I had to set both the clear flags and culling mask to nothing so that the last rendering wouldn't be cleared and nothing new would be rendered. I couldn't set both on the same frame however, as the camera apparently needs time to render with the new settings so a coroutine did the trick:
IEnumerator FreezeCam()
{
//yield return null;
Camera.main.clearFlags = CameraClearFlags.Nothing;
yield return null;
Camera.main.cullingMask = 0;
}
Answer by Landern · Feb 25, 2015 at 12:20 AM
Pro
Application.CaptureScreenshot and Graphics.Blit
Non-Pro
Application.CaptureScreenshot and the method Camera.OnRenderImage
forget about the source and just stuff your screenshot texture as the destination parameter or forget about capturing a screenshot and use the source texture in OnRenderImage method, stuff that in some variable for current and future use, apply that as the destination until freeze frame has elapsed.
Either Pro or Free:
Screenshot Create a quad put it as a child to the camera, but ensure it's properly distanced and all that jazz. Enable Quad, put screenshot on quad.
Profit.
Ah, thanks. I was hoping for something more intuitive and efficient though as the tasks I'll be perfor$$anonymous$$g while the camera is paused are demanding. Is it possible to just pause the camera on its last rendering?
Answer by Tibor-Udvari · Jan 05 at 08:36 AM
I had a black screen on iOS metal with the ClearFlags approach. I managed to get it working with a temporary render texture. Attach this to your main camera doing the rendering. Then you just set the pause value, and celebrate.
public class CameraPause : MonoBehaviour
{
[SerializeField] private RenderTexture _cachedRenderTexture;
public bool paused;
public static CameraPause instance;
private void Awake()
{
instance = this;
}
void OnRenderImage(RenderTexture src, RenderTexture dest)
{
if (_cachedRenderTexture == null)
{
_cachedRenderTexture = new RenderTexture(src.width, src.height, src.depth);
}
if (paused)
{
Graphics.Blit(_cachedRenderTexture, dest);
}
else
{
Graphics.CopyTexture(src, _cachedRenderTexture);
Graphics.Blit(src, dest);
}
}
}
No, that would completely turn off the rendering. In my use case I needed to sample the cached render texture data.
Your answer
![](https://koobas.hobune.stream/wayback/20220613184242im_/https://answers.unity.com/themes/thub/images/avi.jpg)