Why not dynamically change the layer of the camera?


I assign new arrays directly.

    this.layerNew = this.app.scene.layers.getLayerByName('New');
    var layers = this.camera.camera.layers;
    this.camera.camera.layers = layers;

Why don’t layers that dynamically change cameras render New Layer?The layer array debugging has changed, that is, it can’t render New.

This is an odd one. I would have thought that would work.

Can you post a link to your project? Perhaps there’s something in the setup of the layers that is causing the issue?

Wait a minute for me to make a demo.


push is effective;

remover is invalid;

After removal, drawcall did not decrease.

There does look like to be an issue where there’s no API to remove a camera from a layer.

This is my workaround: https://playcanvas.com/editor/scene/755356

Press 1 to add the layer, 2 to remove the layer.

1 Like

It did solve the problem. Why didn’t I think about it?:joy:

To be fair, I only found that out from looking through the camera source code. The disable function removes the camera from all the layers. I couldn’t find another way to remove the camera from the layer without going through the layer object itself which felt wrong to do.