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
- 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
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.