Search Issue Tracker

Not Reproducible

Votes

7

Found in

4.3.2f1

Issue ID

598763

Regression

No

Screen.width and Screen.height values in "OnEnable" function are incorrect

Scripting

-

When Screen.width or Screen.height are called in an "OnEnable" call in the editor and the component is enabled (i.e. by checking the 'enabled' box), the Screen.width and Screen.height that are reported are from the 'inspector' panel's size and not the game's view size.

Reproduced with:
Unity Version 4.3.2f1 (0517a5ae8669)
Unity Version 4.3.4f1 (e444f76e01cd)

Comments (15)

  1. SioHio

    Oct 12, 2018 13:53

    Still happens in 2018.2.10f1

    void OnEnable ()
    {
    Debug.Log (Screen.width);
    }

    differs from e.g.

    void Update()
    {
    Debug.Log (Screen.width);
    }

    if the gameobject is activated on runtime

  2. MarkKreitler

    Apr 03, 2018 15:30

    Same behavior in 2017.2.0f3.

  3. marc851

    Jun 19, 2017 18:25

    Still exists in 5.6.1f1

  4. jjxtra

    Nov 18, 2016 02:58

    Still exists in 5.4.X...

  5. THHT

    Apr 21, 2015 21:44

    This is still a problem in Unity 5. Place the following code in a script on the camera, run the game, and toggle the camera off and on. The second Screen.width value noted in the console will return the Inspector panel's width. If you change the size of the Inspector panel, the returned Screen.width value will be different. Therefore, the returned value is NOT the Game View's current resolution.

    void OnEnable ()
    {
    Debug.Log (Screen.width);
    }

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.