- Home /
Custom Editor Window Nodes Unresponsive Button
I'm writing a custom editor window for dialogue trees. That has a series of nodes to represent lines of dialogue.
I want to have a button inside these Node Windows that calls a function. The button is, however, unresponsive and I can't figure out why.
Here's the code from OnGUI in the EditorWindow class that draws all of the nodes (they're in a scroll area):
GUILayout.BeginVertical();
{
scrollPos = GUI.BeginScrollView(new Rect(0f, scrollViewYStartPos, position.width, position.height-110f), scrollPos, new Rect(0, 0, 10000, 10000));
{
BeginWindows();
for (int i = 0; i < dialogues.Count; i++)
dialogues[i].windowRect = GUILayout.Window(i, dialogues[i].windowRect, DrawNodeWindow, dialogues[i].windowTitle);
EndWindows();
}
GUI.EndScrollView();
}
GUILayout.EndVertical();
The node windows are created within the BeginWindows and EndWindows. The function to create them is:
private static void DrawNodeWindow(int id)
{
dialogues[id].DrawWindow();
}
And the code in the actual node that defines its display is:
public virtual void DrawWindow()
{
if (GUI.Button(new Rect(windowRect.width - 44f, 1f, 36f, 14f), "Size"))
{
ChangeWindowHeight();
}
}
^That's the button that isn't responding though. It just seems to get stuck when I press it.
Any help would be appreciated!
Thanks, Matt
Alright, I think this question essentially boils down to - How do I get buttons working when those buttons are called inside EditorWindow.BeginWindows; and EditorWindow.EndWindows();?
Answer by Bunny83 · Aug 22, 2016 at 02:44 PM
Well, first of all you're mixing GUILayout and GUI stuff inproperly. Things inside a GUILayout group should all be "layouted" automatically. So using GUI functions inside a GUILayout group makes no sense.
GUI windows can be a bit tricky. In most cases it's better to use GUI.Window instead of GUILayout.Window. The only difference is that the content of the window can cause the window rect to resize automatically (growth only). Since your window content isn't layouted content you should use GUI.Window
Also your "BeginVertical" makes no sense since there's no layouted content in between BeginVertical and EndVertical. It seems you want to use the normal (manual) GUI system, so you should replace GUILayout.Window with GUI.Window.
This works for me without any problems:
scrollPos = GUI.BeginScrollView(new Rect(0f, scrollViewYStartPos, position.width, position.height-110f), scrollPos, new Rect(0, 0, 10000, 10000));
{
BeginWindows();
for (int i = 0; i < dialogues.Count; i++)
dialogues[i].windowRect = GUI.Window(i, dialogues[i].windowRect, DrawNodeWindow, dialogues[i].windowTitle);
EndWindows();
}
GUI.EndScrollView();
If it doesn't work for you it might depend on what you do inside "ChangeWindowHeight();"
If you have trouble understanding how the IMGUI works, have a look at my GUI crash course over here. Maybe if i find the time i could add a few lines about GUI windows as well ^^.
I ended up doing this in a different way because I couldn't get the button to work. I know the difference between GUILayout and GUI. That wasn't my issue. It wasn't ChangeWindowHeight() either. The button simply never returned true when pressed.
Thanks for the response though. And that's a good crash course in Unity GUI :).
Your answer
Follow this Question
Related Questions
Custom Editor Button Style like the one in the Hierarchy 0 Answers
Custom HUD Hierarchy in Editor Window 2 Answers
Popup options not changing in custom editor script 0 Answers
Handles.Button unresponsive in custom editor after custom asset serialization 2 Answers
How to trigger button press on a button in an editor window by pressing the return key ? 0 Answers