I’m trying to make a custom editor window that has a window area and an inspector-like area to the right, as follows:
![1]
It behaves as expected, but I have an issue: I need to know which window is current selected, so I’m holding the current window ID in a property, as follows:
void windowFunc(int id){
if ((Event.current.button == 0) && (Event.current.type == EventType.MouseDown)) {
selectedWindow = id;
}
// More window stuff...
}
and, on OnGUI function, I reset the selected window so whenever I click outside an window but inside window area, i de-select any selected window:
void OnGUI () {
// Some GUI stuff...
if ((Event.current.type == EventType.MouseDown) && (Event.current.button == 0) && bounds.Contains(Event.current.mousePosition)) {
// reset selected window
selectedWindow = -1;
}
BeginWindows();
// More GUI stuff, and a catch later...
}
So far, so good. The problem lies when I need to modify the side view to show/hide content based on selected window:
void OnGUI() {
// The same OnGUI as before...
if (selectedWindow != -1){
EditorGUI.indentLevel++;
// draw some controls over here...
EditorGUI.indentLevel--;
}
// if statement is false, don't draw extra items
}
This code works flawless if the amount of controls is higher than before (in the image example, if a window has more outputs than the window selected before). Otherwise, the error pops up on console:
ArgumentException: Getting control 5's position in a group with only 5 controls when doing mouseDown
I know why the error occurs (I shouldn’t change window content between a layout and a repaint event), but how can I work-around this issue? Does removing “Layout” functions should get rid of these errors (yes, I’m using Layout functions to draw the controls)?