GUI refresh problem

Hi

I have a problem with refreshing GUI.
I have a button which launch a quite long action (a few seconds). When this button is pressed, I change a text in a label on screen. The problem is that this text is not updated until the end of the action.

To understand better, my GUI code is:

void onGUI()
{
    // label containing the text I want to update
    UnityEngine.GUI.Label(new Rect(90, 288, 300, 30), "MyText");

    if(UnityEngine.GUI.Button(new Rect(7, 285, 68, 28), "Update"))
    {
        // this function changes text in the label
        UpdateMessage("blabla");

        // launches computation
        Process();
    }
}

void UpdateMessage(string text)
{
    UnityEngine.GUI.Label(new Rect(90, 288, 300, 30), text);
}

void Process()
{
   // action that lasts a few seconds
   // ...
}

My label is updated once the computation is finished. More, I can see that the whole GUI is blocked until the end of the function.
Do I have to launch the computation in another thread?
I tried to use StartCoroutine function for that, but the problem is the same.
Can’t I force Unity GUI to be updated before I start the function?

Thanks for your help

you must start process as coroutine, otherwise the ongui is never ended till process is through thus messing up the state

thanks for your quick answer.

I already tried to use coroutine to launch the process, but the problem is still here.
If I change the code in the process function, this solution works perfectly, the label is updated.
So I just found that it’s not a GUI or coroutine problem, but it’s about what the process does. It’s used to get some files from a ftp server. When this function is running, even with a coroutine, player is blocked until ftp finishes its work.

Loading… graphic problem.

I am having a similar issue.
I have a GUI window that is opened by a button the interface, In that window is a list of objects you can instantiate. when pressed, I call a function to load the object, then run through all children of the object adding code and colliders to it. That routine is in another script.

The problem is I enable a LOADING graphic when the button is pressed, but it does not show up, until this whole process is done (4-6 sec) depending on the object selected ( lots of polygons and children!!)

So a button creates a Window, where a button calls a function to load an object(instantiate a prefab) which then calls another script to search all the children of the loaded object to ensure it has the scripts and colliders attached it will need to function.

When the button it pressed I ENABLE a GUItexture, but it only shows up after the full code cycle(object is loaded on screen), which does not help.

How can I force a redraw or a GUI update before it goes off to do the rest of the work?

After enabling the loading graphic, wait one frame before doing the actual work.

–Eric