Hello, I’m trying to implement my own GUI-System into Unity.
I don’t want to use OnGUI because of the well known performance issues.
Altough I have a license for EZGUI, i’d like to create my own system so i can learn something new.
As I see it, there are 2 Approaches:
- Using a second orthographic camera for the GUI and overlaying it on the main camera using a Render Texture.
- Keep everything in the Perspective Camera and calculating the correct Distance/Scale of the Object for it to be pixel perfect.
Most people seem to go for the 1st approach. Isn’t there quite a bit of Overhead in this, because of the render texture?
I prefer approach 2. I already made several tests and it works surprisingly well. I just calculate the correct Scale of the Object (plane) from the distance to camera (with some trigonometry).
This way the texture is pixel perfect (after moving it 0.5 pixels, took me forever to figure this one out…).
Even drag and drop works like a charm. For MouseOver- or Click-effects I just move the UV coordinates of the mesh (I don’t use Material Offset, so the Objects can still be batched).
I know this approach is quite a bit more complicated (and also more difficult to maintain) but I think performance-wise it’s better.
What are your thoughts?
Should I continue (I intend to code a full framework like EZGUI) like this or should I Switch to the Orthographic Approach with a RenderTexture and second camera. What are the Overheads of a Rendertexture?
I can't see those options out-performing OnGUI. I suggest you run some benchmarks before you get too far.
– WazWhy not just use a second orthographic camera rendering on top of your perspective camera clearing depth only?
– equalsequalsHow would I just render the second camera on top of the main cam, without using a Rendertexture? Is that possible? I was looking for something like that but didn't find anything. Wouldn't it be some overhead just because there's a second camera to render? I will do some benchmarks then. I think the main gain in performance should come from all of it being just 1 drawcall (using a texture atlas), that's the reason why EZGUI is faster than OnGUI. The calculations only happen at Awake(), after that everything is just static planes in front of the camera.
– maikkelsubmitted answer with step-by-step instructions of how to set that up.
– equalsequalsI don't have time to do it myself but if you google for "unity animation events tutorial" you can find plenty there. Good luck!
– SurreyMuso