- Home /
UnityGUI display delay
I'm not sure if I'm doing something with UnityGUI that's not recommended, or if it's common for there to be delays the first time labels are displayed. I have up to 2 seconds of delay sometimes when displaying labels. However, after displayed the first time, it is smooth after that.
I assume this delay is from Unity doing something to create the label for the first time. Is there a way to do all this first-time prep before displaying stuff so it displays immediately the first time?
Could you post some source code? This sounds very strange to me, I've never encountered any such behaviour.
Answer by Eric5h5 · Mar 16, 2011 at 01:15 AM
OnGUI code is immediate mode, which means it's recreated and drawn every frame. So basically it's impossible for there to be any inherent delay; either it's drawn or not. Something in the way your code works is probably the issue.
Alright, I'll see if I can give you a simplified example after looking at my code.
There is definitely a delay the first time GUI elements are drawn. I assume this is because they have to be created the first time, but are drawn from a buffer after that. I noticed that it only happens on my $$anonymous$$acbook, not on my beefier Windows desktop PC. I suppose it may only be noticeable on slower PC's.
@Gillissie: There is no delay on my 2007 $$anonymous$$ac $$anonymous$$i, which is nearly identical in specs to the older $$anonymous$$acbooks. As I said, the GUI is recreated every frame, so delays aren't even possible, since it's a synchronous operation. You have something else going on. It's not something that happens even on the original iPhone, which is probably 50X slower than your $$anonymous$$acbook. The only thing I can think of offhand is that you're drawing an extremely large texture in the GUI.Label, in which case there will be a freeze when it's first uploaded to the GPU. That's a general issue though, not related to OnGUI.
There is a 256x256 image on the main menu, and a 16x16 image, but that's it. Everything else is text of various styles. I have 5 GUI modes that display different text. The first time I go to any of the modes, there is the pause. But when I exit the mode and return to it, there is no pause. There's really nothing fancy going on. Here is my entire GUI script code in its entirety: https://gist.github.com/891849
I've found that dynamic fonts can take quite a bit of time to load. A coroutine that runs once in the background and calls font.RequestCharactersInTexture
fixed the problem for me.
Answer by Uriel_96 · Mar 16, 2011 at 12:33 AM
Not 100% efficient but maybe this can work:
var startgame = false;
function Update(){
if(startgame == true){
//There go your code
}
}
function OnGUI(){
//Create your label
if(startgame == false){
startgame = true;
}
}
The why of this question I don't know maybe is error of Unity or maybe is yours but this code will make that your game starts when the GUI's are shown
No need at all to go about that business. See the event order. OnGUI is called after Update. I'm sorry but it is completely redundant. http://unity3d.com/support/documentation/$$anonymous$$anual/Execution%20Order.html
By the way I am not quite sure what you're trying to do with this snippet. Delay Update until OnGUI has been called once? What is it that you're trying to solve here?
Is because at the final of the question he ask if there is a way to first appear the GUIs and then the do the other stuff so with this as you say update is first but in this case it can not do anything because startgame is false so I GUI after set the label startgame = true so the update function will ask again and it will pass because is true
Answer by vogg666 · Oct 05, 2015 at 10:06 AM
I had the same issue and i solved it. When i load a level that has some UI Elements, it does a delay. In my case the problem was the font of the UI Text (which is Arial by default). I changed it to Helvetica and the delay is gone. It seems odd but it solved my problem.
Your answer
Follow this Question
Related Questions
Need Text to Display After 5 Seconds 1 Answer
Display GUI Text after delay ? 1 Answer
Problem Displaying Score on GUI text 0 Answers
Display problem with OnGUI 3 Answers
How will display values like table? 1 Answer