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…
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.
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.
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.
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?