- Home /
Question by
Shnayzr · Jan 06, 2017 at 10:13 PM ·
editor-scriptingcustom editortextfieldeditor scriptingeditorscript
EditorGUILayout.TextField changes back to first value I input [GIF of the problem inside]
When I input for example "aaa" in that text from the custom editor and then change it from another code. and then i click on the field again, my initial input "aaa" is set as the current value.
https://gfycat.com/SoggyBigCrow
here is the full code:
public class TestingBug : EditorWindow {
string abc = "0";
int num = 0;
[MenuItem("aaa/bbb")]
static void GettingWindow()
{
GetWindow<TestingBug>();
}
private void OnGUI()
{
abc = EditorGUILayout.TextField(abc, GUILayout.Width(200));
num++;
abc = num.ToString();
}
}
Comment
I have updated the main post, a gif of the probelm+full codes are added.
Thanks
Answer by Adam-Mechtley · Jan 08, 2017 at 09:38 AM
I don't understand what the example is supposed to do, but the TextField displays the value of the variable abc
. After you store the user's input back in abc
, you just end up overwriting it with the assignment abc = num.ToString ()
, and num
is just incrementing every time OnGUI is called.