So I’m having an odd issue while writing an editor script. I have a lot of EditorGUILayout.FloatField/StringField/IntField… being displayed. The values in these fields are cleared by another portion of the script in certain situations.
conFloat.Value = EditorGUILayout.FloatField(conFloat.Value);
Lets say this hypothetically (where conFloat.Value is a float). If I edit conFloat.Value from another source it properly edits the value, but the GUI does not update. Even if I close/re-open the window the value is not updated.
Is there any way to force these fields to update/clear?
Example scenario:
I have a string set up just like that float which is used to create new objects. You type the name in and click the button next to it and it does what it needs to do. Clicking the button clears the string automatically (which properly clears the variable), but the GUI does not clear with it.
Any thoughts on how to achieve this?
If this is anything like what i experienced recently the values wouldn’t update until I clicked back in the window.
Try Repaint() when you change the values.
1 Like
Thanks! For the most part it’s working great.
Kyle, greetings… did you ever get a full solution to this?
I am hitiing the same problem and its always (in my case) the last text, int or whatever field on editor GUI that’s holding it’s value until the form is clicked again even if other types of GUI field follow it that do update correctly…
What’s really frustrating is that debug.log entries show the field as empty, but the onGUI routines are not properly populating the field.
I have tried pretty much everything, and also posted it in scripting section, but no-ones come back from there with an answer. I also tried playing with the focus to try and force a refresh and also with “repaint” but to no effect. Always the last one doesn’t update even though the field is not saying what the variable associated with it has as a value…
I am thinking currently, about putting a dummy hidden text field at the end of the form, as it always moves to the last one not being updated but haven’t tried this yet so not sure if a hidden field would be treated as the last one on a form.
Regards
Graham
For Those of you struggling with this, use inheritance and call your Runtime-Space Script from your Editor-Space script like this:
public class MyGameObject : MonoBehaviour {
public static EditorWindow MyEditorWindow;
private GameObject _previouslySelectedGameObject;
protected void Update () {
if( selection.activeGameObject !=_previouslySelectedGameObject) {
_previouslySelectedGameObject = Selection.activeGameObject;
MyEditorWindow.Repaint();
return;
}
}
public class MyEditorWindow : EditorWindow
{
public static void ShowWindow()
{
MyEditorWindow window = GetWindow<MyEditorWindow>("My Window");
MyGameObject.MyEditorWindow = window;
window.minSize = new Vector2(200, 300);
window.Focus();
}
}
My specific use case included the fact that I have MonoBehaviour code running at editor-time with the [ExecuteAlways] tag.
2 Likes