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
ao_196419
Nov 08, 2023 09:17
Still reproducible in 2021.3.19f1
huulong
Nov 19, 2022 20:53
The more recent bug report is here: https://issuetracker.unity3d.com/issues/screen-dot-width-slash-screen-dot-height-in-onenable-shows-inspector-window-size-when-the-component-is-enabled-by-a-toggle-in-inspector-window
It has been closed as By design without explanation, so I re-opened a bug report and will post my updates on the more recent bug report until a new one is opened, or it is reopened.
mboyle_tp
Jan 25, 2022 12:38
Still reproducible in 2021.2.3f1.
Revolter
Nov 10, 2021 13:23
Still reproducible in Unity 2020.3.21f
t1ny_bear
Mar 16, 2021 15:31
Same behaviour in version 2020.2.3f1.
CDMcGwire
Aug 13, 2020 00:40
Still not resolved in 2020.1.0b14
daxiongmao
Jul 13, 2020 20:48
I just saw this today on 2019.4.3f1. Gives me the inspector sizes when toggling the enable on and off and reading screen in the OnEnable function.
The values are correct the very first time. After the game is running and toggling the enable in the editor the values return the inspector sizes.
Ratatoeskr
Mar 24, 2020 13:32
I can admit that Screen.width has incorrect values in OnValidate, even when OnValidate is called during play mode.
Unity 2019.3.6f1 (Windows)
ouijahija
Aug 22, 2019 11:05
This is my code:
private void AdjustZoom()
{
Debug.Log(Screen.height + ", " + Screen.width);
}
The function is called in OnValidate and it's Logging the height/width of the inspector window and not the game window (as it probably is intended!). When playing it's logging the game window height/width.
Reproducible in Unity 2019.2.0f1!
This thread is not resolved!
Lumpazy
Aug 13, 2019 17:11
This IS SOOOOOO NOT Resolved.
and it is Reproducible !