• 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 madmike6537 · Jan 13, 2013 at 04:37 PM · gui.textfield

Cant override GUI.textfield

Update: so I changed the default of what is in the Gui.Textfield and now I can sort of type in there, but it doesnt override the default text that I put in there "Enter Name Here". and it saves my character name as "Enter Name here " :(

Hello Unity,

For some reason, I cant type into a GUI.Textfield - I have never had a problem like this before. Would someone mind taking a look and seeing if they can see something I did that would not allow me to type? I have tried running as a standalone build and in the editor, neither let you type into the field.

This is a window that opens and allows you to put in character information for creating a character, then it is supposed to save that into binary(which I havent gotten working either).

     //Save Character Window Function
     void SaveCharDataWindow(int windowID)
     {
         PlayerDataClass myChar = new PlayerDataClass();
         GUI.Label(new Rect(10,10,150, 25), "Enter Character Name");        
         myChar.playerName = GUI.TextField(new Rect(5,30, 150, 25), "Enter Name Here");
         
         //Set Default values for the new character
         myChar.playerXP = 0;
         myChar.playerLevel = 1;
         
         if(GUI.Button(new Rect(offset, 150, 450, 50), "Save"))
         {
             MyCharacters.Add(myChar);
             openCreateCharacterScreen = false;
             numberOfCharacters++;
             //Save this data to playerprefs file:
             var b = new BinaryFormatter();
             var m = new MemoryStream();
             //save info
             b.Serialize(m, MyCharacters);
             PlayerPrefs.SetString("MyCharacters",Convert.ToBase64String(m.GetBuffer()));
         }                
     
 
     }
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 $$anonymous$$ · Oct 30, 2014 at 01:01 PM 0
Share

This helped me out SO $$anonymous$$UCH!!!! I was getting an headache over this!!!! At first, I thought it was because of my FocusControl() method causing the issue. Thanks so much for posting this!!!!

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by madmike6537 · Jan 13, 2013 at 04:46 PM

Gah it never fails - I ask a question on here and figure it out right after I finish typing it lol.

The solution for those interested was I needed (apparently) a temporary variable to store my player name in, I couldnt assign the name in the same line as its being typed.

So I used this code:

         tempName = GUI.TextField(new Rect(5,30, 150, 25), tempName);
         myChar.playerName = tempName;
Comment
Add comment · Show 2 · 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 Bunny83 · Jan 13, 2013 at 04:51 PM 0
Share

Of course you can assign it in the same line, but the important thing is that you have to pass the current name into the TextField function. So this should work as well:

 myChar.playerName = GUI.TextField(new Rect(5,30, 150, 25), myChar.playerName);
avatar image madmike6537 · Jan 13, 2013 at 04:52 PM 0
Share

Hmm. Strange that is actually what I was using before - but it wasnt allowing me to type anything into the textbox which was the original issue causing me to post (before I updated it). It might be an issue with my myChar.playerName though? Not sure.

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

9 People are following this question.

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

Related Questions

GUI interferring with another GUI 1 Answer

GUI.TextField input control/forma 1 Answer

3d text to trigger mobile keyboard 2 Answers

how to set object's x,y,z based on GUI.Texfield's content? thanks 1 Answer

How to stop GUI.textfield from starting a new line when I hit enter 2 Answers


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