- Home /
Camera Culling Mask for UI Elements not working
Hello, I am trying to use culling mask for UI elements that are in world space. I have a layer named "360" and I want to use culling mask to render only UI elements that are in "360" layer. It seems like culling mask are all ignored for UI... Does anybody know how to fix this? Thank you in advance,
Edit: I haven't solved this problem yet but I founded out odd thing. Even I assigned a different layer to the UI object, culling mask works as UI. Although the layer was not "UI" layer when I checked the script...
Answer by sisse008 · Sep 16, 2019 at 11:56 AM
I know this is old but it took me a while to figure it out and there's really nothing on this any where I looked. So if you change the layer of a certain UI element and set a camera's culling mask to render only that layer, it wont work. The layer of the canvas (parent of the UI element) will determine if you see the children (ALL the UI elements) or not.
a work around it to add the "Canvas" component to the UI elements with the unique layer.
Answer by auhfel · Dec 01, 2019 at 06:43 PM
I thought this was a bug for a while but it is not. Yes, the culling layers do not work on any UI if that UI is on a canvas that is marked 'Screen Space Overlay'. They do not work because of how screen space overlays(SSO's) work. With SSO what happens is this -- The camera decides what to render based on it's culling layers, then renders it to the screen. Then, the UI is drawn and overlaid upon the screen (hence the name Screen Space Overlay). So, the UI doesn't even exist in the camera's rendering system, and the camera's sorting layers wouldn't matter for SSO Canvas UI because it simply doesn't exist until after that camera has been rendered.
This can be solved by marking the canvas "Screen Space - Camera". This is functionally different than SSO, as now any image effects and antialiasing and whatnot will affect the UI if it exists on the Camera, and also the UI now is a plane with some distance between it and the camera.. so if you set that distance too high, game objects will be drawn over the UI if they are closer.
Anyways, there you have it. It's actually not a bug because of how it is designed, and here's how you can fix it. Change the canvas it is on to 'Screen Space - Camera', set the camera, and tweak the plane distance to something preferable (probably a value that is just a tiny fraction larger than the camera's near plane, so it doesn't z-fight with the camera near plane but still renders over everything else) and now you can use layers.
I have my Canvas Render$$anonymous$$ode set to ScreenSpace - Camera, a camera with Culling $$anonymous$$ask as RenderCamera, but it doesnt' work. The only layer that the camera will cull correctly is the one of the root Canvas GameObject (tried on 2019.1.9 and 2019.2.5).
@nolwenn_bigoin Correct. For an UI in Screen Space - Camera mode, the camera culls based on ONLY the Canvas’s layer at least on 2019.1 and 2019.2 and not a fully fledged functional layer system like it seems to be implied on the answer. What was answered only was that SS-Overlay doesn’t allow the use of layers (there’s no camera interface to do the culling) and that SS-Camera does allow the use of layers. However the limitation is still there... changing the layer of canvas’s child UI element to a supposedly invisible one to the camera will still result in that UI element to be visible.
Answer by JonPQ · May 17, 2018 at 12:19 AM
Its not ignored, but for Ui with a parent object that has a 'Canvas' component, look at the Canvas component, check the "Sorting layer" setting on that component. Also check on the same component, variable "Render Camera" make sure that it is set to the Camera that you are rendering with.
Thank you for your answer. I believe sorting layer is not same layer system as the layer system that used in culling for cameras. If you are talking about "Event Camera", I already set up.
Culling working for other objects but not for any UI Object. Such as gameobjects that have Text or Image component. I want to use culling for those UI object. Does anybody know how to fix this?
Answer by Alejandro-Martinez-Chacin · Oct 29, 2019 at 03:07 PM
Just stumbled upon this same issue. Culling layers do not work on Canvas's children elements, the camera will only cull the layers based on the base 'Canvas' object's layer. Is this the expected/designed behavior?
Your answer
Follow this Question
Related Questions
Second UI camera only works when I refresh Clear Flags setting 1 Answer
Canvas layer overrides child layer in light culling mask - Expected behavior? 0 Answers
I can't hide a RawImagen in a camera view 1 Answer
UI with layer always displaying 0 Answers
How can you hide Canvas objects using Camera Culling Mask? 1 Answer