- Home /
GUI Menu Major Performance Issues
Hey,
I have been working on a trading system for some time and I got everything to work, but the menu is extremely laggy. The performance is about 170 FPS when I am not in the trade menu, but as soon as I open it, my frames drop to about 20 FPS and I have no clue why. I am using the exact same method of drawing these elements as in my inventory and the inventory stays at constant 170 FPS. Maybe you guys can help me somehow, I am clueless. I have tried so many things and nothing even slightly increased the frame rate.
The problem is the ShowTradeOptions() method.
List<Item> tradeItems = new List<Item>();
Item selectedItem = new Item();
Rect moveRightButtonRect, moveLeftButtonRect;
void ShowTradeOptions()
{
for (int i = 0; i < availableItems.Count; i++)
{
GUI.Box(myItemsRects[i], "", gameDatabase.inventorySkin.GetStyle("Slot"));
GUI.DrawTexture(myItemsRects[i], availableItems[i].itemIcon);
GUI.Box(tradeItemsRects[i], "", gameDatabase.inventorySkin.GetStyle("Slot"));
GUI.DrawTexture(tradeItemsRects[i], tradeItems[i].itemIcon);
}
}
I am sorry for bumping this post, but I really do need help with this. I have been tweaking the code and trying to find the problem for nearly 4 hours now. It just does not make any sense.
Before we move on to the discussion about your problem, I would like to let you know that 'do not post comment as answer'.
Now moving on to your issue, we would need additional information like platform you are developing for to provide you with precise details.
One of the reason off the top of my head is that use of Unity GUI since Unity GUI is draw call heavy and you will get a performance hit due to it if there are just too much GUI elements are drawn on the screen. Also the GUI elements used also make a large difference. To know more about it read GUI Basics.
One of the options would be to use any GUI assets from asset store like NGUI or create one yourself using GUIElements.
Another option is that you can wait for new Unity GUI to come out (which people are waiting for a long time....) and then use that.
N.B.: I have converted your answer to comment for you this time. But just take care about it from next time. :-)
Thank you for your help and the clarification. I am developing my game for the PC and I have read the GUI Basics prior to posting this. The GUI is definitely draw call heavy, but I just don't understand why my Inventory menu is very stable performance wise and the trade menu is not. The inventory even has 45 draw calls, whereas the trade menu only has 43. It just does not make any sense that the FPS drops so significantly when the code I am using for the trade menu is way more efficient than the actual inventory script. The inventory even uses a nested loop. I have been waiting for the new GUI system as well, buying NGUI just because the FPS magically drop to an unplayable state does not really make me want to spend that much since I am not even doing anything special GUI-wise. There has got to be a reason for this performance issue.
Answer by freshgamer10 · Jun 24, 2014 at 06:14 PM
I am now posting an answer to my issue because I managed to fix it.
The issue was that I was trying to draw a texture that was null and Unity could not handle that properly. It does not give you an error, but it results in significant frame rate drops below the playable state.
So, I am now only setting a texture if the texture is not null.
Your answer
Follow this Question
Related Questions
Creating Fps Game Menu 2 Answers
Graphics.PresendAndSync, CPU Usage Performance issue 0 Answers
Paused Menu backdrop 1 Answer
menu item and add gadjet 1 Answer
Close my GUI button by repressing the same Hot-key. 3 Answers