GUi Button in Foreach Loop

So I have this code which goes through an array and creates a button out of each one item in it. But it is really weird, it adds about 25 draw calls for 5 buttons. But that seams absurd, 5 draw calls a button? It also displays them oddly with extra GUI around them (I am pretty sure its a weird error but I am sure its my code
1633220--100723--$Capture.PNG

        if (MenuShowing == true)
        {
            foreach(MenuControls Control in MenuControlsList){
                if (GUI.Button(new Rect(Control.XLocation, Control.YLocation, Control.Width, Control.Height), Control.Text)) { }
            
            }
        }

Thank you so much!
Have a lovely day!

Probably you have the script running on multiple objects or something.

–Eric

Hmm, that is a good thought but I only have one game object in the scene. I checked though, that was a good thought. Didn’t work :confused:

Any thoughts?

Nothing off the top of my head but try posting the whole script.

Actually looks to me like the elements are crammed inside a Box or Area.

That is all the code in the GUI… If you want to see the code that adds to the array I can show you that but I am not sure if that would help. All the code there is all that is happening…

I would do a count on MenuControlsList, if thats no go. I would then put a Debug.Log("ran "+counter) right after If statement, my guess is the condition is satisfied 5 times more :slight_smile: