- Home /
GUI Redraw stall while loading a new prefab. Loading... message
I have a Model Viewer program that can load several different Hi-poly models. I run a script on each model to add things to it for use on the screen (each part has a gizmo script and collider added/verified)
I have a series of button created in the ONGUI, one is to list the models you can load. That is a spawned Window from the ONGUI. The buttons in there calls the LoadModel Function, which instantiates the prefab and then calls a separate script to do some more work.
In the meantime, I wanted a LOADING... Texture to appear, but it does not appear until the model is done (meaning it waits until all the work is done)
So the function calls are stalling any GUI redraws.
My Question is, how do i force the GUI to put up the message LOADING... before doing the work to load the models. (so the user is not wondering what is going on for the 4-6 seconds it seems to be doing nothing and presses the button again!)
The ONGUI function calls seem to be stalled while the load and other script are running, like control has been given to them before continuing the normal cycle.
I can fix this with a series of booleans and work arounds, but figured there might be a force REDRAW or some kind of command, but can't seem to find that...
Any suggestions?
Answer by Molix · May 26, 2011 at 01:38 PM
This sounds like a good time to use a coroutine. When the button is pressed, start a coroutine to do the load. The loading coroutine should yield periodically to allow the rest of the game (e.g. the OnGUI) to run. There's a good example of yielding when doing 'work' in this question (where it Iterate()s you'd be loading some chunk of your model).
was confused since Javascript does not use StartCouroutine. $$anonymous$$y solution was so easy, I was laughing. I just put a yield; as the first line of my load$$anonymous$$odel function, and walla, the loading pops up and the load$$anonymous$$odel continues as designed. I should have ready more closely that only C# scripts need the StartCoroutine Thanks for your help. : ]
Your answer
Follow this Question
Related Questions
My unity project won't load my level for editing on a different PC 0 Answers
How can I store and load levels efficiently? 2 Answers
Scene Loading occasionally breaks Rigid Bodies... 1 Answer
WebGL loading optimization 0 Answers
Load file on Android 1 Answer