- Home /
How do you stop the camera redrawing the frame when nothing has moved?
If nothing in the visible scene has changed, I want to save computing power by not redrawing the frame, so that the last one continues to be displayed.
I can set up a bool to let me know when something has changed in the visible scene.
bool visibleSceneHasChanged;
It seems like Camera.OnPreRender() would be a good place to use this to tell the camera "don't draw this frame, just carry on to the next Update() cycle", but how do I do that? Should I do something in Camera.OnPreCull() instead?
Rarely you would need this kinda stuff, at least, what game is so boring that nothing changes in a frame transition?
I'd suggest you disable the camera, and call Render() on it manually at the end of frame only when you have moved something. Use some boolean for it. Like:
If something moves, it sets flag to true Camera script checks this boolean, renders if true and resets it.
Did you ever find a solution? I'm building an app as apposed to a game and it's wasteful to redraw UI components every frame when nothing has changed.
I don't know about any builtin solution. Just disable your camera, have some custom dirty flag for it - when you do some visual change, call the Render on camera, or, if you want to stay in sync with other cameras and/or batch multiple changes to the single redraw, use the flag - set the flag dirty on change; then, at the end of the frame, redraw the camera if flag is set
The example on this API page makes use of the Render method of a camera when its turned off to show how to manually render with a camera:
https://docs.unity3d.com/ScriptReference/Camera.Render.html
The docs are not particularly clear about OnPreRender and if it is also called of the camera is off, but you could just test that.
Your answer
Follow this Question
Related Questions
How to Check if my Score is Divisible by 10 for More than 1 Frame? 2 Answers
vBlank Drift - Locking unity to the vBlank? 1 Answer
is there a way i can make a game object destroy itself pixel by pixel frame by frame 1 Answer
Camera performance issue 0 Answers
render unity camera's frame buffer on to an external application 0 Answers