- Home /
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
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.
I don't have an answer but I'll go on a little rant that's somewhat related and at least it will bump your thread.
The Unity editor seems to have a lot of undesired behavior with specific screen sizes or resolutions being displayed.
For example trying to use 1920x1080 in the Game View is not truly 1920x1080 or an accurate representation of what it should be. I almost feel like I need a 2560x1440 monitor to use the Unity Editor properly for 1920x1080, kind of ridiculous. Then again it's my first project so on my next one hopefully I can avoid problems that have anything to do with every resolution setting for all monitors/devices...
Another thing, why doesn't full screen windowed mode work correctly if it's your screens resolution, other games are able to do this with Unity it seems it won't fit right with the bars on top always visible? Need to research if there's a solution to that...
But anyways I'm not sure if I follow your exact problem. But hopefully someone can help you.
It seems Unity requires a dual monitor set up to use efficiently. Even then there are some strange things going on with Unity, windowed mode, and resolution settings within the editor.
Answer by asafsitner · Mar 07, 2014 at 08:05 AM
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!
Hi, I actually was the one who submitted the issue. I thought I tested this thoroughly but the hideFlags solution actually works! I've been spending like a week trying to fix this issue and mailing back and forth with Unity, thank you so much!
Hi, really glad I could help!
It's a weird bug (feature?) for sure, I spent a lot of time battling it as well. :)
Hey, I tried your solution but it didn't work. I am on Unity 2019.4. You just set the HideFlags of the camera and it worked ? Could you show the code just to be sure that I do it correctly.