Search Unity

UI Design Tool Pros vs. Cons: UnityGUI, GuiTextures, 3D Mesh, or 3rd party tools?

Discussion in 'Immediate Mode GUI (IMGUI)' started by bigkahuna, Feb 7, 2011.

  1. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    I'm about to start a project that is going to have a fairly intensive UI with lots of dials, gauges, etc. There a a number of routes I can go for each element and I'd like to open a discussion on the advantages and disadvantages of the various tools we have at our disposal to create a user interface in Unity as well as options / tricks to gain maximum benefit from them. This first post is intended to open the conversation and is by no means complete nor definitive. Any corrections, advice or info you might want to add would be very welcome.

    UnityGUI:
    Pros -
    Includes most elements needed such as radio buttons, scrolling bars, interactive buttons, etc. etc.
    Includes most forms of interaction needed such as hover, clicked, active, etc. etc.
    Pixel accurate (textures and other elements can be sized or positioned at specific pixels).

    Cons -
    Performance "sponge" (runs 2x as much as Update() so if not used carefully it can rapidly cause performance issues).
    No easy way to rotate textures (as in a needle for a speedometer).
    No easy way to scale rendertextures.
    Opposite coordinate system of GUITextures/GUIText.
    I don't understand the reasons why, but it appears there is direct correlation between using UnityGUI and the frequency of "Garbage Collection" spikes in the Profiler.

    GUITexture/GUIText:
    Pros -
    Performance is potentially 1/2 as consuming as UnityGUI
    Textures and rendertextures can be scaled easily
    Easy to consistently position elements regardless of screen size (edit transform in the inspector)

    Cons -
    No easy way to add interactivity
    Opposite coordinate system of UnityGUI

    3D Mesh:
    Pros -
    Easy to rotate and scale textures
    Easy to create a consistently sized UI regardless of screen size.

    Cons -
    Not pixel accurate
    Scales objects / textures with larger window / screen size

    GUIx / EZGui:
    I really don't know much about either of these and would greatly appreciate any information anyone can offer, especially a comparison of the two.
     
  2. KevS

    KevS

    Joined:
    Apr 21, 2010
    Posts:
    51
    Unfortunately I can't help you but I am really interesting about a replacement of UnityGUI.
    I'm facing the problem of spikes due to the OnGUI function. I can't understand why a single empty OnGUI function in a scene triggers the garbage collector and ruins the performance (specially on low/medium hardware) while without this function my game runs smoothly with any call of the GC.
     
  3. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    @blizhard - Those "garbage collector spikes" are one of the reasons I thought I'd start this thread: to find out what methods people are using to fix / avoid them. In another thread (sorry but I don't have a link to it) it was recommended that GUITexture's be used instead which would call the texture once per frame instead of twice. I'm also going to experiment with a UI that's 100% 3D mesh, GUITexture and GUIText based to see how that performs.

    Have you tried using one of the 3rd party GUI replacements (GUIx or EZGUI)? If so, how does that compare performance-wise?
     
  4. Krobill

    Krobill

    Joined:
    Nov 10, 2008
    Posts:
    282
    Pixel accuracy is not really a con for a custom GUI made with 3D meshes. It's really easy to get pixel accurate GUI elements with an ortho camera and the correct orthographic size. And they do not have to be scaled either...

    I can't speak for GUIx or EZGUI but we're in the process of implementing our own GUI system with quad meshes and it sure doesn't have the same performance overhead that Unity's native GUI. I'm quite sure these 2 popular packages benefit from the same boost.
     
  5. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    @Krobill - Thanks for the correction. For your GUI system, are you using separate quads for each GUI element?

    Anyone with GUIx / EZGUI experience want to jump in and give the low-down? ;)
     
  6. Krobill

    Krobill

    Joined:
    Nov 10, 2008
    Posts:
    282
    We've tried several options on this particular point. What is sure is that we're atlasing all our GUI textures into one if possible.
    Now for the PC/Mac version of our project we're quite happy with what the dynamic batching is able to do with separate quads if they share the same material. The draw calls are kept low enough and it's more convenient to handle mouse interactions with rotated elements.
    For the iOS plateform or some extreme cases, we have the possibility to use merged quads. It becomes useful when you're creating / destroying a lot of elements on an update() basis because you can use a 'high poly' mesh as a pooling system for quads (what the SpriteManager is doing basically)
     
  7. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    @Krobill - If you don't mind me asking, are you using any dynamic text elements and if so how are you implementing them? What I've done in the past was to just use GUIText wherever I could, but I'm thinking about adding some dynamic text in perspective view so might try some 3DText elements (although I haven't used that much in the past).

    Anyone know if GUIx / EZGUI supports text elements in 3D and if so how do they do it?
     
  8. Krobill

    Krobill

    Joined:
    Nov 10, 2008
    Posts:
    282
    Yes we are using dynamic texts that we implement but that's still a field where we have some work to do. In fact in our current prototype we're still using some GUIText which will be replaced later ^^
    The basic concept is that we use one mesh per text field. Each letter uses a quad. Quads are spaced horizontally according to fond size and kerning informations and vertically according to line breaks (automatic or manual). And obviously the whole thing uses a texture with all characters like GUIText...
     
  9. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    What you just described is how we handled text in 3D games way back in the "old days" (long before Unity or even Windows). [Edit: That's also how Unity's 3D Text works.] I thought about doing the same thing but decided it would be more work than I really want to invest in this. I also wondered if GUIx / EZGUI might use this method? I don't know.

    Today I plan on experimenting with Unity's 3D Text, which although I've used Unity for a long while I've never used its 3D Text in an actual project before (4+ years using Unity and still learning something new every day ;) ).
     
    Last edited: Feb 8, 2011
  10. KevS

    KevS

    Joined:
    Apr 21, 2010
    Posts:
    51
    @bigkahuna - I didn't try GUIX and EZGUI because there are not free :/ The fact that they are not free is not a problem, but actually I develop my game in solo (waiting to find a job xD), and as my operations on the GUI are just drawing labels or buttons in a simple way, i expected to use a simple "solution".
    Especially that I use the Unity Free version and these "frameworks" maybe need the pro version to work (I will check that)

    If I need to develop my own GUI system, I will do it, but I don't know how and where to start xD (I assume that I have to play with raycasts on gameobjects but it still confused in my mind).
    But the most disappointing point for me here is that the UnityGUI is in a way not usable even for basic stuff ... :(
     
  11. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    I've just started experimenting with 3D Text, but so far zero GC spikes:

    $3DtextTest.jpg
     
  12. Krobill

    Krobill

    Joined:
    Nov 10, 2008
    Posts:
    282
    Short of blitting individual glyphs on a larger texture (not precise enough for small fonts) or using 3D / Vector Text (which will cost a lot for big chunks of text), it is actually the only way to handle dynamic texts that I am aware of.
     
  13. tomvds

    tomvds

    Joined:
    Oct 10, 2008
    Posts:
    1,028
    The GC spikes are new in Unity 3 and seem to be a bug in the OnGUI calling mechanism, which apparently is leaking meshes even when no GUI functions are called. It starts as soon as a single OnGUI function is enabled in your scene (even if the function is completely empty).

    Sadly, this makes OnGUI virtually unusable during gameplay (interface screens are less of a problem), at least for our recent Unity3 games. Currently we are using a system where every HUD element is drawn on quads (even text, which is pre-rendered with GUIText into a single texture).
     
  14. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Thanks Tom, that explains why I don't recall having to deal with GC in the past (I've just recently made the leap to 3.x). Has UT commented on when we might expect a fix for this, perhaps it will come with the new GUI design system?

    FWIW I did a quick test comparison between a UI made with GUITextures and another with a simple 3D mesh (<300 polys, single material). The performance was virtually identical (drawcalls, frame rate, video RAM, etc.) between the two.
     
  15. KevS

    KevS

    Joined:
    Apr 21, 2010
    Posts:
    51
    With the release of Unity 3.2, I read some clues about a new GUI system for the next Unity update, maybe we can expected the best ^^ (I guess at least no more spikes from the GC ^^)
     
  16. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Just thought I'd update this thread. I did some simple tests and further investigating and decided that using GUITexture, GUIText and 3D mesh is the way to go for an efficient UI system. Although I could get a 3rd party plugin (such as EZGui) that would do everything I wanted, $200 seems like an awful lot of money to spend when 99% of what I need to do is already built into GUITexture and GUIText. So I'm currently looking at rolling my own solution. After investigating this further, I found a few other resources that may interest others.

    First, is the bitverse unity gui google project: http://code.google.com/p/bitverse-unity-gui/ This looks to be very similar to EZGui with the added benefit of being free. If you are using Unity 3.x be sure to get the latest beta version otherwise you'll get errors. (Edit: As it turns out, this also uses UnityGUI but for some reason I'm not seeing garbage collector spikes when using it. I am seeing substantial performance drops when more gui elements are on screen.)

    Next is a simple gui framework that Yoggy created years ago but still works in 3.x: http://www.unifycommunity.com/wiki/index.php?title=Box_Script You'll need to update one line of code for this to be current (otherwise you'll get a warning but it will still work).

    Lastly there are a number of scripts on the wiki submitted by aarku, Erich5h, and others that could become the base for some basic gui using GUITextures:
    http://www.unifycommunity.com/wiki/index.php?title=Button
    http://www.unifycommunity.com/wiki/index.php?title=DraggableGUIElement
    ... search the GUI section of the wiki for more.

    Hope this helps.
     
    Last edited: Feb 20, 2011
  17. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
  18. lusho_games

    lusho_games

    Joined:
    Jun 4, 2011
    Posts:
    63
    thanks for making those tests and posting here the results.
    I couldn't understand why my frame rate went so low when using unityGUI, I'm rethinking my whole game to achieve the same results with 3D meshes or GUiItextures untill it's fixed.

    I'm checking out that bitverse-unity-gui, looks promising.
     
  19. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Forgot about this thread. ;) Since starting this thread in February, I've done a couple projects using OnGUI and without. I've run into a few situations where it just wasn't possible to create the gui I wanted without OnGUI. I've also found that with the newer version(s) of Unity (3.4.x) I don't notice the GUI spikes quite as often, although they haven't gone away entirely and seem to get worse for no apparent reason.
     
  20. jedy

    jedy

    Joined:
    Aug 1, 2010
    Posts:
    579
    Have you considered CSS3 GUI?

    Pros:
    -CSS3 is a beauty.
    -You can add jQuery effects and goodies in your gui ( pretty easy )
    -Easy development after initial initialization
    -Great performance if the implementation is correct
    Cons:
    -Pretty hard setup ( you need an ingame browser rendering here and there and atop of that you need to set up a connection between the browser and unity )
    -Not appliable for all platforms
    -Slow performance if not implemented good also depends on the performance of the unity browser tool that you're using

    Anyway with a bit of work on the base - development will be cake.