[SOLVED] Layering In script Query

Hi all,

I wondering how layers work, atm, my custom layer, doesn’t render in the game.

Could I have a basic breakdown on how to get layers to work please?

Kind regards to all,

Adam Burgess

For Further reference, i have this and it has been added to my camera layers also

Hi @adamburgess38,

Layers are indeed used to create sets of models that can be rendered in a specified order.

You need to assign the layer you’ve added to your active camera, if you expected it to do any actual rendering.

You assign it in a similar way you do with the models, just with a slight difference, you need to set the anew array each you change the .layers property (to trigger the property setter):

const modelLayers = entity.render.layers;
modelLayers.push(newLayer.id);
entity.render.layers = modelLayers;

const cameraLayers = cameraEntity.camera.layers;
cameraLayers.push(newLayer.id);
cameraEntity.camera.layers = cameraLayers;

// same way with lights if required etc.
2 Likes

So this has to be done from the script? And cannot be done from the layer?

All this can be set up inside the Editor without a script. Have a look here at the manual please: Layers | Learn PlayCanvas

2 Likes

I’ve looked into this, but the world still does not seem to pick up my new layer

The layer has been added to my camera entity, my light entity and the sub layers order but still does not work.


image

@adamburgess38 try sharing a sample project then so we can take a look.

https://playcanvas.com/project/887667/overview/meshtest

Floor test Scene :slight_smile:

Editing it now, and it works on this. Very Strange indeed

You are still setting the layers like this:

You definitely need to change that to set a reference to the array, check my reply above.

1 Like

Thank you, the issue was I set the layer Transparent, rather than Opqaue

1 Like