- Home /
EditorGUI refresh
I have this text field on the OnGUI function of an EditorWindow:
trace.print("This should be " + m_mapName);
m_mapName = EditorGUILayout.TextField("Map Name", m_mapName);
But when I change the value of m_mapName externally (by pressing another button, for example), the value doesn't refresh. For example, if I write something on the textfield, then call a function to set the value to:
m_mapName = "map";
I get
This should be map
But the control displays something. I tried to call Repaint after setting the value, but it doesn't seem to work.
GUILayout.TextField works as expected. So I'll try to report this as a bug, and see what feedback I get.
Answer by Veehmot · Nov 01, 2011 at 08:07 AM
Seems like it's a bug. It only happens when I have the focus on a textfield, and change the string value of the textfield. It doesn't refresh unless I set the focus to another textfield. So a quick workaround is:
GUIUtility.keyboardControl = 0;
Example:
m_field = EditorGUILayout.TextField("Field Value", m_field);
if (GUILayout.Button("Change Field")) {
GUIUtility.keyboardControl = 0;
m_field = "bar";
}
What the hell... Now in version 4.2, and I had to do just that to keep my TextField from keeping some kind of internal value. Weird.
Answer by oxium · Oct 31, 2011 at 01:16 AM
have you tried EditorUtility.SetDirty ?
Thanks for your answer. SetDirty works for objects only, I can't use it on TextFields or the EditorWindow. I'll report this as a bug.