x


GUI disappear on yield

I got a function called Spin() that is called when a user press a button drawn on OnGUI(). That function, at some point, says something like this:

var url : String = "mysampleurl";       
var query : WWW = new WWW (url);           
yield query;    

The things is that when Unity is waiting for query, the GUI disappears. If if comment that line, the GUI shows perfectly. How I need to write my code in order to have the GUI showing correctly and still wait for the query result?

EDIT: The code is from the function Spin() that's called on OnGUI();

more ▼

asked May 15 '12 at 10:10 PM

DarkSlash gravatar image

DarkSlash
41 12 14 16

could you write your OnGUI function and Spin function (only the relevant parts) ?

May 16 '12 at 04:50 AM Berenger

It's really extensive, like 500 lines... I think the important part is

function OnGUI() { Interface(); }

funcion Interface() { if(GUI.Button(something)) { Spin(); } }

function Spin() { var url : String = "mysampleurl";
var query : WWW = new WWW (url);
yield query; do something else; }

That's the basic! :)

May 16 '12 at 01:03 PM DarkSlash
(comments are locked)
10|3000 characters needed characters left

1 answer: sort newest

Because the query part is asynchronous, you need to make sure that gets split off into a separate Coroutine, instead of forcing the GUI to wait for it to finish. Keep a boolean variable outside of both functions, that takes care of the yield timing:

querying = true;
yield query;
querying = false;


GUI.enabled = !querying;
if(GUI.Button(whatever))
{
    StartCoroutine(Spin());
}
GUI.enabled = true;
more ▼

answered May 16 '12 at 05:03 AM

syclamoth gravatar image

syclamoth
15k 7 15 80

This prevents to blink, but the game crashes... May by there're 2 different issues! I'll work on that, thanks!! :)

May 16 '12 at 01:05 PM DarkSlash

The only thing I can think of is that you're doing something with the query's result in the GUI loop. But maybe the modification happens whilst the GUI is running, between two EventTypes. Try to commit the modification after a WaitForEndOfFrame() ?

May 16 '12 at 02:49 PM Berenger
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3813
x548

asked: May 15 '12 at 10:10 PM

Seen: 508 times

Last Updated: May 16 '12 at 02:49 PM