Why not dynamically change the layer of the camera?


#1

https://developer.playcanvas.com/en/api/pc.CameraComponent.html#layers

I assign new arrays directly.

    this.layerNew = this.app.scene.layers.getLayerByName('New');
    var layers = this.camera.camera.layers;
    layers.push(this.layerNew.id);
    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.


#2

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?


#3

Wait a minute for me to make a demo.


#4

https://playcanvas.com/editor/scene/755347

push is effective;

remover is invalid;

After removal, drawcall did not decrease.


#5

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.


#6

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


#7

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.