situation:
For my Editor Extention, i create buttons in a loop according to a list array of the selected GameObject.
Each click on a button should call a function for the button.
It’s very unhealthy to remove an element from the loop when within a loop. UnityGUI system doesn’t like that.
You should just mark it as a candidate and delete it later. For instance:
int index = -1;
for (int i = 0; i < buttonList.Count; i++) {
if(GUILayout.button("button label")){
index = i;
}
}
if (index != -1) {
buttonList.RemoveAt(i);
index = -1;
}