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?

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!