x


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.

more ▼

asked Mar 18 '10 at 08:00 PM

Cyclops gravatar image

Cyclops
7.1k 33 63 115

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Mar 18 '10 at 08:07 PM

Eric5h5 gravatar image

Eric5h5
80.3k 42 132 521

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.

Mar 18 '10 at 08:46 PM Cyclops

@Cyclops: Yep, two totally different systems.

Mar 18 '10 at 08:57 PM Eric5h5

@Eric5h5, thanks. Though that brings up performance questions, now :) which I suppose should be in a separate question.

Mar 18 '10 at 09:04 PM Cyclops
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3698
x3014
x150

asked: Mar 18 '10 at 08:00 PM

Seen: 4096 times

Last Updated: Mar 18 '10 at 08:00 PM