How to call Camera.Render from Update


From Unity 5.6, I got the following error when Camera.Render() is called in Update() function:

Rendering camera ‘DrawSomethingToRenderTexture’, but calling code does not set it up as current camera (current camera: ‘Main Camera’)

I noticed that Camera has SetCurrent(Camera) static function, but this function did not help.

Is there any way to remove this error? Or, Camera.Render() should not be called in Update function? I need to call it in Update function to see a rendered texture in Editor. The script has “ExecuteInEditMode” attribute but camera events such as OnPostRender are not called in edit mode. So, I had to manually call Camera.Render() in Update function which will be called in edit mode.


Camera.Render directly renders that camera. It should not be called from Update. While the Update methods are called the rendering engine is not “active”.

Have a look at the flowchart in the docs. From there you should call Render() highly depends on the reason why you want to render the camera manually.

If you want to render the camera after all enabled cameras has been rendered you may want to use a coroutine with WaitForEndOfFrame or simply render it during the Repaint event in OnGUI.