- Home /
How to move GUI objects to separate Camera Layer - and why?
I read the suggestion (somewhere) that the GUI elements should be on their own layer, with their own camera, separate from the game layer. Unfortunately, I can't find the post again. :) So I have two question about that.
First, why? What are the consequences of having the GUI on a separate layer? Assume that I write reasonably modular code, and all my GUI display elements are in one script (and they only set State variables that other scripts use).
Second, (and I hate to ask this :) but how? I have followed every step in the Unity Layers Guide. I have created a new Layer called GUI, and assigned my GUI_gameobject (called GuiTop) to that layer. Then I unchecked GUI on the main (only) Scene Camera Culling Mask. At this point, I am presuming that my GUI buttons would not be visible, since the only existing Camera is not supposed to display that layer. Yet they display...
The GuiTop is an empty GO that has a script attached - this script has the usual OnGUI() and GUI.Button() type statements. Is it sufficient for GuiTop to be assigned to the Layer GUI, or do I need to also do the script component?
Or is there some other step I'm missing?
Ah, I also removed the GUILayer component from the Camera, although as far as I can tell, this is only for GUITextures, shouldn't have an effect - and didn't.
Answer by Eric5h5 · Mar 18, 2010 at 08:07 PM
1) I have no idea...toggling the GUILayer component will turn on and off all GUIElements anyway.
2) OnGUI is different from GUIElements, does not use the GUILayer camera component, and cannot be put on a separate layer. It's always drawn on top of everything.
So they're two totally different systems? Well, that explains things. And looking at the main Unity Game Elements page, they sort of mention that, but it's definitely not made clear.
@Eric5h5, thanks. Though that brings up performance questions, now :) which I suppose should be in a separate question.
Do I understand it in the right way that we still do not know why one should use a dedicated camera for the GUI?
Because I am having the same difficulties as Cyclops of understanding that concept/recommendation.
Wild guess here, and I'm almost certain it's not the "best" answer.
$$anonymous$$aybe it has to do with Field of View and controlling GUI settings. If you have a first person shooter, and wish to allow the player to have the ability to change the field of view; you can safely do so without the GUI beco$$anonymous$$g too big or small because of it. On the other hand, you can re-size the GUI without affecting the game's settings.