- Home /
How to get Game View Height from OnDrawGizmos?
I realized recently that calling Screen.width/height from OnDrawGizmos ALWAYS returns the dimensions of the Scene view, probably because gizmos are exclusive to that window. However, is there a convenient method to use to get the Game View's dimensions from OnDrawGizmos? For now, I'm going to be caching a reference to a camera in the game view, and using the pixelWidth/pixelHeight values from that, but if there's a better way, I'd be interested in hearing it!
Oh dear, looks like Unity 3.4 might have a bug where all Screen / pixelRect values are replaced by Scene View dimensions whenever running in an editor with a Scene View open. I filed a bug about it.
Answer by SupremeCookieDevDavid · Sep 23, 2020 at 12:55 PM
Super old post, but maybe some people are helped by the answer.
-
You could use "Screen.currentResolution" which gives back the current setting as depicted in the GameView.
-
Another solution is covered by this post using reflection https://answers.unity.com/questions/179775/game-window-size-from-editor-window-in-editor-mode.html