I cannot make buttons dynamically into a GUI.Window


I can retrieve the data after clicking “Obtener DB”, but it doesn’t create new buttons. The simple Button for example “sdadas DB” (highlighted with the 2nd arrow) is not created after clicking, but the script works.

It is a “foreach” to create so many buttons as long the array is, but it doesn’t create anything.

So, Am I not allowed to make buttons in this way? How should I make it?

Thank you.

I would truly recommend using the [newer] UI system, as opposed to GUI.Button and so on.

Separate note: Please try to read the pinned forum post on how to insert/use code tags, which will let you write and/or paste code into the thread (a little nicer and easier to read … probably even easier for you to show, too).

With the UI system buttons, you can instantiate a button and give a component script or its text data/strings… whatever you want to do; i don’t really know what it is you want, but I do know you can create as many buttons as you need and further work with them, as described :slight_smile:

1 Like

I will look for docs about newer UI System. I know only this way.

About the code, I made it so intentionally, to highlight the problem. Maybe what I need till, is a short video about how it runs, because, buttons, yes, i can create.

The problem is, I cannot create by execution, another button.

I want it make clearer. Once the application is running, I get the button “Obtener DB” (Get Database). I click it, and nothing happens. And it is not about the code, because I just created a simple button to show for testing purpose, and nothing happens.

It looks that, once the window is showed, I cannot make modifications.

Yep, I would really recommend looking at the UI button I mentioned.
Another thought, is that maybe since your code depends on having clicked the button, that’s why you never see the new buttons later on, eh?
I think that’s how that button (GUI.Button) works.
For that kinda of setup, you could set a variable to say you’ve clicked it, then check that variable and if it’s ‘set’, you do the draws and new buttons etc that you want.
But still, it won’t hurt to see the other stuff. I promise it’s not hard, and easier in many ways, etc… :slight_smile:

And I knew what you meant, that the other button wasn’t created, but the first one was… :slight_smile:

1 Like

Ok… Recorded Video Sessions on UI - Unity Learn

I was looking the scripting for new GUI, and they are new from v4.6. So really, I didn’t find nothing new to learn.

Yep, I realize they’re old/new at the same time… but I guess my point was that that video and what I was talking about, both are not “GUI.Label/Button/etc”
They are objects you add… it’s a totally different system.

1 Like

Hello again! it looks we find us each other at same time. Shade that i must go to work briefly.

Yes, I thought as you did, keeping the button down. But it shouldn’t be so in my understanding. It is a click answer reaction.

If (button clicked) { execute this }

it is not

while (button clicked) { execute this }

Thank you for answering.

Yes, that is the point. I think that I am not allowed new GUIs implementations into a Window if it is running.

The code, yes. I click, and it is executed. First window connect to MySQL Server. Second window should throw every database found like new button. But, I cannot create new GUI elements.

The new GUI stuff can be added to a window when it’s running. Yes you can add dynamically to it.

As for your other GUI.Button : Yes, you can click = execute, that is true.
When you connect to the DB, you’re asking it to perform an action, and it does that.
I believe that you are also creating extra buttons in the other part, but the problem is, that the next OnGUI call (which happens many times per second), it checks “did you click the button” again, and the answer is ‘No’ and so it doesn’t “keep drawing the buttons”.
OnGUI buttons , labels, etc… have to be called every frame/OnGUI call.
That’s why I mentioned the variable to check if it’s’ been clicked… Then, each and every other OnGUI call could check this variable and draw them if it’s set.
Hope that makes sense :slight_smile:

1 Like

Yes it does. Thank you! I will try it in another way and I will post it 8)

Cool :slight_smile: It’ll get there… don’t worry lol

1 Like

As you said, the button was only true while it is pressed, just an instant.

To check it, I just made:

        if (!_mostrarListaDB)
        {
            if (GUI.Button(new Rect(10, 10, 100, 50), "Get DB"))
            {
                _ListDB = GetComponentInParent<MySQL_Connect>().Get_ListDatabase();
                _showListDB = true;
            }
        }

so I stand turned to on a condition.

next, I could make the buttons with the condition true:

        if (_showListDB)
        {           
            _index = GUI.SelectionGrid(new Rect(5, 20, 295, 295), _index, _ListDB.ToArray(), 1);
        }

Just I need keeping in my mind, the OnGUI() is in every frame called. Really, I have forgotten completely.

This problem is solved.

Thank you very much for your time :slight_smile:

No problem :slight_smile: Cheers.

1 Like