Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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
1
Question by Ruben · May 04, 2010 at 11:12 AM · textfieldtextareaclear

Clearing TextArea / Text field

hi

i have a textfield in a gui. i have a bool to display the gui and activate the textfield, when i am done editing it and return to the window, my previous text is still in the window. how do i clear the textfield so when i open the gui again the textfield is empty?

thanks!!

Comment
Add comment
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

2 Replies

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

Answer by Ray-Pendergraph · May 04, 2010 at 04:53 PM

The text field only displays what you call it with, it is stateless (for the most part). You need to clear the string that you are holding onto the edited value with so that its empty when you pass it in.

So looking at the documentation: http://unity3d.com/support/documentation/ScriptReference/GUI.TextField.html you would set stringToEdit = ""; when you wanted to clear the text field.

Comment
Add comment · Show 4 · 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 Ruben · May 05, 2010 at 08:08 AM 0
Share

this is my code: newOrb.comments = GUI.TextArea (Rect (30, 250, 400, 100), newOrb.comments,300);

the comment field is initialized to empty string as you stated above, but it still holds the previous data. i switch the window on and of via bool value, is this a problem?

avatar image Ray-Pendergraph · May 05, 2010 at 12:16 PM 0
Share

It's initialized to empty string but gets reassigned on every OnGUI depending on what is being typed in the text control. It need to be reset to "" whenever the boolean to display is set to false. That will not happen automatically. The GUI object does not store this type of state, so whatever is in newOrb.comments is what will get displayed. I would suggest putting some print lines to print out the value before and after the event that clears the comment. $$anonymous$$aybe store the TextField() results in a temp string and compare to the comments field after the call... this might be helpful.

avatar image Ruben · May 05, 2010 at 02:44 PM 0
Share

will try it thank you!

avatar image Ruben · May 06, 2010 at 08:14 AM 0
Share

that worked awesomely, thanks!!

avatar image
0

Answer by intrepidolivia · Jul 28, 2019 at 04:41 AM

I know this is old, but I'm having this problem in Unity and the accepted answer is not helping me. Even when I have two entirely different string variables assigned to entirely separate text fields, the text is being carried over from one text field to the next when I disable one text field and display the other one.

 screen.text = EditorGUILayout.TextField ("screen text:", screen.text, GUILayout.Height(64));
 
 newScreenID = EditorGUILayout.TextField ("New screen ID:", newScreenID, null);

Does anyone have any additional input about this? Surely there must be some kind of string buffer in the GUI or this wouldn't be able to happen.

Comment
Add comment · 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

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.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Problem with clearing textfield C#. 0 Answers

Clear gui Text field 1 Answer

GUI Text field? How do I make the text so it goes on more then one line? 1 Answer

Prevent IOS keyboard from showing 0 Answers

Trying to create both a text field and a text area, getting BCE0043 error 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