Search Issue Tracker
By Design
Votes
0
Found in
2017.4.0f1
Issue ID
1025328
Regression
No
Screen.width/Screen.height in OnEnable/Awake shows incorrect values when duplicating object or re-enabling script component
How to reproduce:
1. Open attached project ("ScreenBug.zip")
2. Enter Play mode
3. In Hierarchy window, disable and enable "PrintResolution" object's "Print Resolution (Script)" component
4. Observe Console window
5. In Hierarchy window, right-click "PrintResolution" object and press "Duplicate" (does not work when duplicating with shortcut Ctrl+D)
6. Observe Console window
Expected result: On reenable or duplication, printed Screen.width/Screen.height values show Game view screen
Actual result:
- On reenable, printed values, in OnEnable, OnDisable functions, show Inspector window screen
- On duplication, printed values in Awake, OnEnable, OnDisable functions show Hierarchy window screen
Reproducible with: 5.6.5p4, 2017.1.3p3, 2017.2.2p4, 2017.4.2f1, 2018.1.0f1, 2018.2.0b2
-
huulong
Nov 19, 2022 20:52
There is no explanation on why this is by design, and the API doc doesn't mention these edge cases either, so I have reported this bug again for a more recent version (I'm not the original poster, but stumbled on the same bug). Will post updates here.
-
SioHio
Oct 12, 2018 13:56
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
- [Mobile] Developer Console does not appear when an error is thrown
- [HDRP] Game view renders artifacts when Camera's Component "Post Anti-aliasing" is set to "TAA" and Dynamic Resolution's "Forced Screen Percentage" is changed
- A deactivated Prefab's name color becomes white when a GameObject in the scene is deactivated
- The Game view becomes blank when using Frame Debugger with MSAA and Texture binding enabled in Play Mode
- NullReferenceException is thrown when changing the Inspector preview selection
Resolution Note:
Screen.height / Screen.width returns the pixel size of the focused Editor window.
https://docs.unity3d.com/ScriptReference/Screen.html
When using Debug line "EditorWindow.focusedWindow.ToString()" it is visible on which window the Editor is focused on.