Screen.height/width via [ContextMenu] click return dimensions of righ-clicked editor panel

I got this piece of code attached to an empty GameObject in an otherwise empty scene in 5.5.0f2

using UnityEngine;

public class Test : MonoBehaviour {

    void Start() {
        Debug.Log("START width " + Screen.width + " height " + Screen.height);
    }

    [ContextMenu("Test")]
    void TestMe() {
        Debug.Log("TEST width " + Screen.width + " height " + Screen.height);
    }
}

When I press Play, and then right-click the Monobehaviour and click on the “Test” item in the dropdown, i get these outputs:


When I resize the inspector panel of holding the MonoBehaviour, the output produced through the context-menu click changes to match the size of the inspector panel (I believe).

Sounds like a bug. Have you filed a bug report?

Now i have, though i botched a copy-paste-edit in the description, but it’s OK still :stuck_out_tongue:
https://fogbugz.unity3d.com/default.asp?855755_jip8b5fjeq0jmhqo

Mmkay. Seems like Camera.pixelHeight and pixelWidth are the correct values to use. I think there’s even some Unity learning material that should be changed to use these values instead of Screen.width/height. I’m pretty sure that’s where i picked up the habit of using Screen.XXXX values years ago.

Yes it seems to be by design. Screen returns the state of the current rendering context (which is the inspector in this case). Much of the editor and many 3rd-party editor extensions rely on this behavior. However, I agree that the API is a bit vague about what it should be used for. We’ve been looking into a better solution for this API.