- Home /
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();
}
}
public class TestingBug : EditorWindow {
int num = 0;
[$$anonymous$$enuItem("aaa/bbb")]
static void GettingWindow()
{
GetWindow<TestingBug>();
}
private void OnGUI()
{
num = EditorGUILayout.TextField(num++.ToString(), GUILayout.Width(200));
}
}
Answer by steo · Jan 09, 2017 at 10:47 AM
While textField control is focused, it saves value you pressed and doesn't feel changes made from code. Try this and look what happens:
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));
abc = EditorGUILayout.TextField(abc, GUILayout.Width(200));
num++;
abc = num.ToString();
}
}
I see now that this was more related to what the OP was referring to. $$anonymous$$y apologies for misunderstanding the original question.
Your answer
Follow this Question
Related Questions
EditorGUILayout.TextField changes back to first value I input [GIF of the problem inside] 1 Answer
How to use an Editor script? 0 Answers
How do I change the pre-processing order of models imported with an Editor AssetPostprocessor? 0 Answers
Is there a way to get all editable fields of a component in a script? 2 Answers
Play Unity Editor from VSCode? 0 Answers