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

Scripting

-

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

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

Comments (2)

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

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.