Frustum Culling and UI element issue

I have a scene with frustum culling set on the camera. If I create a UI element in the editor it is always displayed ( the yellow cog ). However, if I create a similar UI element in code ( the white cog) then the element will appear and disappear as I move the camera around with the 3 person controller. If I disable frustum culling then this issue doesn’t happen. There is probably something wrong in my code or setup but I can’t see it. Any ideas? Below is the test app. The app starts with the white cog not being shown. Move the camera around 360 and the white cog will appear.

https://playcanvas.com/project/913583/overview/culluitest
https://playcanvas.com/editor/scene/1391812
https://playcanvas.com/editor/code/913583?tabs=78008457

Hi @Kulodo133,

Hmm, most likely this is a bug, since the behavior of code generated elements should be same. Try posting an issue in the engine repo about this.

In the meantime here is a quick fix to set culling to all UI mesh instances to false. Run this after you added your UI elements in code:

this.app.scene.layers.getLayerById(pc.LAYERID_UI).transparentMeshInstances.forEach(o => o.cull = false);

Note: that would change the culling for all UI elements. If you have world space elements, apart from screen space, you should filter those out since frustum culling makes sense for those.

2 Likes

Hi @Leonidas,

Great your quick fix worked :+1: I will raise an issue in the engine repo.

https://github.com/playcanvas/engine/issues/4199

1 Like