OnGUI game slowdown

I am currently creating a word game. In the game, you click and drag on a grid of letters to find words one at a time (similar to a word search). I am using a GUI to show the word on the screen that you must find.

However, I’ve run into a very strange problem. The moment I add an OnGUI() function, the game gets sluggish. The framerate goes down from ~600 FPS to ~450 FPS, which shouldn’t cause any noticeable problems, but it takes a few tenths of a second longer for the game to recognize an OnMouseEnter event. Even if the OnGUI() function has absolutely nothing in it, this happens.

Any ideas why? Does the GUI system not play nice with mouse events, by any chance?

GUI slows down the Unity application - get used to it :slight_smile:

Up until now, I’d only heard of it slowing down the framerate, though. With such a high framerate after OnGUI was added, I thought I might be missing something.

Unfortunately, it looks like there are some problems with the GUI and the garbage collector.

http://forum.unity3d.com/threads/60217-Garbage-collector-spikes-because-of-GUI

I don’t know if it’s that problem for you, but all I know is that I didn’t have this problem with Unity 2.6 and that it ruins my personal project :frowning:

Just for info: GUI was always slow. The moment you put a button into the app, the frame rate drops. The good news is that’s only the initial drop, and if having 100 buttons - it won’t make such a difference from when there’s only one.

I think Unity team should take it seriously, because from my experience, Unity has a great chance to be the business application platform (such as Flash an Silverlight - but running on Mac, iPhone, iPad etc ;)) - if you don’t believe, just look at this beauty with auto-layout.

GUI shouldn’t be taken as a second-grade citizen!

dkozar, I agree with that.

We do take it seriously and we are working on improving the system.

As mentioned, though the overhead is introduced when you enable the system - it doesn’t scale linearly as you add GUI components.

Yes, you got to realize that you have the application platform which could work on many platforms but is more powerful robust than HTML/Javascript. :sunglasses:

Well, I still don’t know what the problem was, but the update to Unity 3.2 completely fixed it. It’s running far faster than it was. Thanks, Unity team!

I have this problem also, I was hoping 3.2 would do something about GUI, but my iphone game is still laggy as hell…Please make GUI a higher priority!

You generally should not use OnGUI on iOS for anything but menus - as outlined by the iOS development performance guidelines.

As mentioned, we are aware of the issues with the current system and are working on improving it. That being said, a lot of stuff is on our roadmap and “DOETH!” messaging won’t change that. Everyone has their own thing which to them is the most important bit in the world.

I understand that you guys must be working on it already, but what I ment is this issue should have increasing priority since it is a very old issue that has not had a significant fix. The only answer right now is to buy other GUI tools. Some people even only recommend using Unity GUI as a placeholder. I hope GUI gets a performance boost in future updates because it would make Unity a lot easier for many people and not just my self.

Here’s a free alternative that I’m in the process of evaluating: Google Code Archive - Long-term storage for Google Code Project Hosting. Be sure to get the latest beta version (released in January) as the older version will throw errors with Unity 3.2.

I’ve got the same problem, my fps get down from 450-500 fps into 20-43 fps, the gui only contain 2 getobject, 2 getcomponent on awake, and in ongui 2 realtime slider for assigning its var into those 2 object var, it’s pretty horrible i should say the unity’s gui performance, that awake function itself consume 65 ms to run based on profiler o_0;, and gui repaint took mostly 25 ms.

Changing the rendering into forward has no use, only gained 2-9 fps differences. I would say if the gui only consume 2-5 fps it would the best thing every happened for me in unity :).

just give them some time, if ant is saying they are working on it, i am pretty sure they do. There is no point on saying it
and not doing it. be patient guys.

I am evaluating if changing all the OnGUI stuff in my project to GUIText and GUItexture (a lot of them) or wait for the improvements in the Unity GUI.

For me the temporary fix i switch with bitverse-gui it’s free and free from these garbage collector problem, so far my testing it consume 5-20 drawcalls with free custom gui skin by unity from the asset store, the functionality i have been mentioned above :), works fine so far only few bug on the gui editor sometime corrupt so save more :smile:.

I’ve reverted back to using GUITextures and GUIText. My UI is pretty simple, so it wasn’t too hard to do. Performance is much better, but I have to admit it’s disappointing that here we are at 3.2 and I’m using Unity 1.x technology to achieve better performance. :stuck_out_tongue:

“I have to admit it’s disappointing that here we are at 3.2 and I’m using Unity 1.x technology to achieve better performance.”

Yes, you are right.

this ^