- Home /
 
 
               Question by 
               Diogo Teixeira · May 09, 2011 at 12:07 AM · 
                scenesizeviewviewport  
              
 
              How to find out the real viewport/screen size in Scene view?
Screen.width/height always returns 640x480 in Scene view. Is there a workaround for this?
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by Diogo Teixeira · May 09, 2011 at 11:23 AM
Found a way using Unity's hidden "SceneCamera". This camera can only be found when the scene-view is visible and focused:
GameObject sceneCamObj = GameObject.Find( "SceneCamera" );
if ( sceneCamObj != null )
{
    // Should output the real dimensions of scene viewport
    Debug.Log( sceneCamObj.camera.pixelRect );
}
 
                
              Answer by persijn · May 11, 2016 at 02:40 PM
These two vectors here get the screensize:
 Vector2 screenBounds = Camera.main.ScreenToWorldPoint(new Vector2(Screen.width, Screen.height));
 Vector2 screenOrigo = Camera.main.ScreenToWorldPoint(Vector2.zero);
 
               Then if i want to check if something is going outside the screenRect i can check it with:
 Vector3 pos = transform.position;
 if (pos.x > screenBounds.x || pos.x < screenOrigo.x)
 {
     DoStuff();
 }
 else if (pos.y > screenBounds.y || pos.y < screenOrigo.y)
 {
    DoStuff();
 }
 
              Answer by IgorAherne · Oct 07, 2018 at 08:27 PM
Here is the solution, which takes into the account the Scene-View's ribbon:
https://forum.unity.com/threads/mouse-position-in-scene-view.250399/#post-3760579
Your answer