Editor: Hitting "Play" does not give focus to the "Game" window fast enough in 3.0?

Hello again,

(Posting my separate issue in a separate thread to make it easier for people with similar issues to find them in search)

In the Unity 3.0 editor I am having an issue with hitting “Play.” My game does a lot of GUI positioning/setup in the Start() function of various classes. In Unity 2.6’s editor, the Start() function was always called after the “Game” tab received focus from the Scene tab. However, this is not the case in Unity 3.0

In Unity 3.0, if I am in say the “Wide” layout and I hit the Play button while “Scene” has the focus, my GUI elements are all misplaced when the game actually starts. An example of how the elements are placed is:

void Start () {
        _windowRect = new Rect(Screen.width / 2 - 260, Screen.height / 2 - 200, 520, 100);
}

It seems that Screen.width/Screen.height are not reporting the correct values when the game is still in the Start() phase for Unity 3.0

For now, this can be worked around by manually navigating to the “Game” tab before hitting play each time.

Thanks for taking a look!

Yes, I ran into this issue as well. One workaround is to do something like

function Start () {
    yield;
    yield;
    // stuff with Screen.width/Screen.height, which is correct by now
}

Obviously that doesn’t work in all cases.

–Eric

Awesome, I am in the middle of submitting a bug report - as soon as I my client is free again I’ll give this a shot. Thanks for the tip!