How to change the text of EditorGUILayout.TextField
I'm trying to build an editor tool that's gonna look for a gameobject with a name. I set up the window using GetWindow and did:
void OnGUI() {
EditorGUILayout.TextField("GameObject Name", name);
}
But I can't edit the key word, every time I press enter it will fall back to its default value. How can I set the value?
Answer by visca_c · Apr 24, 2017 at 02:34 PM
Apparently doing this solves the problem
GameObjectName= EditorGUILayout.TextField("GameObjectName", name);
Answer by rossadamsm · Oct 15, 2017 at 11:41 AM
I think the answer by @marche4ever is almost there.
When I do the following it works.
string name;
void OnGUI()
{
name = EditorGUILayout.TextField("GameObjectName", name);
}
I believe this is because OnGUI is called constantly like Update. So you need to be changing the variable 'name' and storing it back into the original variable 'name'.
Your answer
Follow this Question
Related Questions
How can I display a scriptable object in a custom editor ? 1 Answer
Editor Int sliders affecting each other 0 Answers
GUI.Window. Wanting to allow clickthrough 0 Answers
How to Have a ReoderableList in a Custom Editor Window 1 Answer
My EditorWindow won't display properly, even when commented out. 0 Answers