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
Comments (2)
-
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
- Inspector window flickers when a selector is created using a Style Class List Section
- [iOS] "UnityBatchPlayerLoop()" causes a freeze in the iOS application when it is put to the background and brought back to the foreground
- "Perform Selected" of Shortcut Manager window does not perform the shortcut in some cases
- Crash on mono_get_hazardous_pointer when running Play Mode tests in a specific project
- [iOS] ‘확인’(Done) and '취소'(Cancel) text is displayed as '...' in the on-screen keyboard when the System preferred language is set to Korean
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.