Looking for a workaround for DrawCamera/Game view crop bug

I’m looking for a workaround for this bug. I’m asking again here since this issue really bothers me and basically prevents me from doing anything more on what I’ve been working on.

What I’m trying to do is rendering a camera to an EditorWindow using Handles.DrawCamera(). The problem is, that the (normalized/pixel) rect of the camera is always cropped by the game view and I cannot render it the size I want (e.g. the full size of the EditorWindow). If the game view is not visible, it is cropped to 640x480, otherwise to the size of the game view.

What I’ve already tried:

  • Disabling the camera behavior in the scene
  • HandleUtility.PushCamera() / PopCamera()
  • Setting Camera.current back to the previous one after DrawCamera (Camera.SetupCurrent - if that is what this undocumented method does).
  • Handles.SetCamera(null) after drawing. This causes, aside from a NullReferenceException, another interesting behavior, since now the game view and DrawCamera mutually affect each others size, i.e. the game view still determines its max size, while the rect I pass into DrawCamera crops the game view’s render of the camera to a smaller size if I set it to be smaller.

In order to draw a camera correctly inside a GUI, the camera’s HideFlags has to be set to HideAndDontSave. (It has to be set to that flag exactly - HideFlags.HideInHierarchy alone won’t do it!)

Because of that, if you’d like to keep interactivity with the camera, you can create another camera and mirror it’s state to the hidden camera, which is the actual camera you’ll render.

To quickly copy the settings from one camera to another you can use Camera.CopyFrom. Remember to also copy the transform state!