Using TextField Cuases GUILayout.Window To Flicker

I’m displaying a small window to let the user enter a name for his new character. The window looks great until the user interacts with the TextField. With every input event (mouse and keyboard), the window momentarily shrinks and then re-expands to its original size.

Here’s how it normally looks:


And this is how it looks when you click or type in the TextField:


It immediately snaps back to the original size, hince the “flicker”. Here’s my code:

windowRect.width = 350;
windowRect.height = 200;
windowRect.x = h - (windowRect.width / 2);
windowRect.y = v - (windowRect.height / 2);
windowRect = GUILayout.Window (0, windowRect, DrawPromptNameDialog, "");


void DrawPromptNameDialog (int windowID)
    GUILayout.Space (50);
    GUILayout.Label ("Enter character name:");
    characterName = GUILayout.TextField (characterName);
    GUILayout.BeginHorizontal ();
      if (GUILayout.Button ("Continue", "SmallButton", GUILayout.ExpandWidth (true)))
        // TODO: Validate name
        state = State.PromptSkipTutorial;
      if (GUILayout.Button ("Cancel", "SmallButton", GUILayout.ExpandWidth (true))) {
        state = State.Menu;
    GUILayout.EndHorizontal ();

It’s not quite clear from the code snippet you provided, but it looks as if you’re declaring the Rect from within OnGUI. If you haven’t already, move the windowRect.x,y,width,and height settings to Start. Since OnGUI is called multiple times per frame, when your Rect size is set in OnGUI, it draws the window at the size you set before GUILayout can take over and size it properly.