Dynamic content in custom EditorWindow

Hi,

I am beginner to the EditorWindow scripting and am in need of support from you guys.

I would like to create a custom EditorWindow with my own dynamic content (just like a list).

I thought it would be simple to make but the following code is not working. Can you help please ?

public void OnGUI() {
        if (GUILayout.Button("Press me !")) {
            GUILayout.Label("Hello !!!");
            Debug.Log("Call from OnGUI");
        }
    }

I get the message in the Debug.Log() but the label does not show.

I’ve added the Repaint() to the Update() method and still nothing. When I make the code static i.e. take out the label from the if() the it shows properly … but this is not what I want to achieve.

Any guides would be helpfull.

Thanks

This is because Button() only returns true on the frame it’s pressed. So, your label would only draw for 1/60th of a second.

You need to store a separate boolean and have the button toggle it, then check that boolean for whether or not to draw the label.

Works ! Thanks !

public void OnGUI() {
        if (GUILayout.Button("Press me !")) pressed = true;

        if (pressed) { 
            GUILayout.Label("Hello !!!");
            Debug.Log("Call from OnGUI");
        }
    }