- Home /
Layers and UI not behaving as expected.
Hey everyone.
I have a bunch of different prefabs that have their own World Space canvases, all set to the default UI layer. Within that canvas is two different images, each on their own layers. The reason it's set up this way is that I'd like to programmatically hide one while the other is active by switching off the layer visibility in the camera. As there are a lot of these prefabs, I gathered this would be the cheapest and least code-heavy approach as opposed to finding all objects of that layer and manually disabling the image component, or disabling the gameobject (definitely undesirable, as they need to stay active).
The problem I'm having is that the objects don't cull themselves even when their respective layer is disabled, and I'm guessing it has to do with the parent object (on the UI layer) overriding this somehow. I've tested this with a similar setup using gameobjects with spriterenderer components, and that works perfectly fine. Does anyone know if this is a bug, or if there's an alternative workaround?
Answer by seth_slax · Aug 18, 2016 at 12:41 PM
Well, I've found a hacky solution, but it doesn't involve enabling/disabling objects. If you have sub-canvases with the objects you want separated by the layers as their children, the sub-canvases can have their own layers set independent of the main canvas.
I'm sure there's probably some overhead to having a canvas with 2+ child canvases, but it seems to work for now. A better and more elegant solution would be more than welcome!
Your answer
![](https://koobas.hobune.stream/wayback/20220612091047im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Canvas layer overrides child layer in light culling mask - Expected behavior? 0 Answers
Text gets hidden on frames where other text is behind it 1 Answer
Canvas UI Priority layers 1 Answer
How to display 3D object on top of UI World Space Canvas in VR 0 Answers
Display a world-space canvas to overlay all the meshes but not the other UI objects 0 Answers