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
- Test Runner’s vertical scrollbar overlaps with the up and down arrows and upper toolbar tabs when the window is minimized
- The Input Field view is not updated when deleting lines of text
- The scrollbar does not respect empty lines in the Input Field
- “Texture Atlas Viewer“ button text overlaps another button when the UI Toolkit Debugger is narrowed
- Thresholds are no longer automatically calculated after deleting Motion fields in Blendtrees
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.