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!!

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.

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.