Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Editor GUI - Force window to refresh the displayed value?

Discussion in 'Immediate Mode GUI (IMGUI)' started by KyleStaves, May 16, 2011.

  1. KyleStaves


    Nov 4, 2009
    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.

    Code (csharp):
    2. 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?
  2. JAHansens


    Aug 21, 2010
    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.
    AbgaryanFX likes this.
  3. KyleStaves


    Nov 4, 2009
    Thanks! For the most part it's working great.
  4. MaliceA4Thought


    Feb 25, 2011
    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.