• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Moohasha · Oct 05, 2012 at 12:34 AM · textfieldguilayout.window

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:

alt text

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

alt text

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 ();
   }

normal.png (245.9 kB)
small.png (204.0 kB)
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Moohasha · Oct 06, 2012 at 01:45 AM 0
Share

Or if nobody knows what the problem is, can somebody post a code snippet of a small window you are using similar to this that works?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by burnumd · Jan 30, 2013 at 07:01 PM

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Moohasha · Feb 03, 2013 at 01:46 PM 0
Share

Sorry, I didn't make the code very clear. windowRect is a class member variable and I just update its dimensions before calling GUILayout.Window() in OnGUI. I never adjust the width or height of the rect, just the position to make sure it's in the center of the screen.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

making bold word or coloured letter in a string, 2 Answers

Help! Iphonekeyboard has only number appear in textfield 0 Answers

Using GUI.FocusControl on TextField selects all text 4 Answers

How to restrict different characters in different text fields? 0 Answers

TextField, Event.current, Input.GetKey, and GUI.FocusControl locking 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges