Search Issue Tracker
Not Reproducible
Votes
7
Found in
4.3.2f1
Issue ID
598763
Regression
No
Screen.width and Screen.height values in "OnEnable" function are incorrect
When Screen.width or Screen.height are called in an "OnEnable" call in the editor and the component is enabled (i.e. by checking the 'enabled' box), the Screen.width and Screen.height that are reported are from the 'inspector' panel's size and not the game's view size.
Reproduced with:
Unity Version 4.3.2f1 (0517a5ae8669)
Unity Version 4.3.4f1 (e444f76e01cd)
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- TutorialManager Warnings are thrown when creating Test Track or LEGO Templates
- Incorrect ScrollToItem behavior when called on a deattached ListView
- Zooming in/out in Scene View window on the display the zoom takes place in does not work
- Changing Game View resolution when there are 2 Game View Windows on 2 different displays makes the view stretched
- Maximising Game view window on one display makes black bars appear on another display
SioHio
Oct 12, 2018 13:53
Still happens in 2018.2.10f1
void OnEnable ()
{
Debug.Log (Screen.width);
}
differs from e.g.
void Update()
{
Debug.Log (Screen.width);
}
if the gameobject is activated on runtime
MarkKreitler
Apr 03, 2018 15:30
Same behavior in 2017.2.0f3.
marc851
Jun 19, 2017 18:25
Still exists in 5.6.1f1
jjxtra
Nov 18, 2016 02:58
Still exists in 5.4.X...
THHT
Apr 21, 2015 21:44
This is still a problem in Unity 5. Place the following code in a script on the camera, run the game, and toggle the camera off and on. The second Screen.width value noted in the console will return the Inspector panel's width. If you change the size of the Inspector panel, the returned Screen.width value will be different. Therefore, the returned value is NOT the Game View's current resolution.
void OnEnable ()
{
Debug.Log (Screen.width);
}