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)
Comments (15)
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
- UI becomes unresponsive when using AppUI Navigation and Event System is attached
- PlayerPrefs get corrupted when a minimized fullscreen Player is closed through the Taskbar
- "To Debug, run app with -diag-job-temp-memory-leak-validation cmd line argument. This will output the callstacks of the leaked allocations." warning is printed when JobTempMemoryLeakValidation switch is enabled
- Main Thread stalling when loading Audio Source asset asynchronously while preloading another Audio Source asset
- Material artifacts occur in the Material Preview window when baked lighting is applied to scenes
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);
}