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
- Articulation Body with 'Revolute' Joint Type has erratic behavior when Upper Limit is set to above 360
- WebGL Player fails to render Scene when Terrain with Detail Mesh is added and WebGPU Graphics API is used
- Inconsistent errors are logged when different types are passed into the Query "Q<>" method in UIToolkit and the ancestor VisualElement is null
- Crash on GetMaterialPropertyByIndex when opening a specific Scene
- Discrepancies in the styling are present when using a TSS file instead of a USS file in custom EditorWindow
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);
}