Layer Constructor Arguments

Hi @dave seems like there is a little issue with layers, but I’m not sure.

Is option parameter required for constructor? According to code, it isn’t and there are default properties, but I can’t create layer without parameter.

I was just like:
var layer = new pc.Layer();

And I got

TypeError: Cannot read property 'id' of undefined
    at new Layer (playcanvas-stable.js:16591)
    at script.Ship.initialize (ShipControl.js?id=8882054:82)
    at Func._scriptMethod (playcanvas-stable.js:24939)
    at Func._onInitialize (playcanvas-stable.js:24956)
    at Func._callComponentMethod (playcanvas-stable.js:25203)
    at Func._onInitialize (playcanvas-stable.js:25209)
    at Function.fire (playcanvas-stable.js:640)
    at Function.initialize (playcanvas-stable.js:22349)
    at Application.start (playcanvas-stable.js:21893)
    at launch.js:6847

However var layer = new pc.Layer({}); works good

[moved to a new topic]

Looks like you need to pass in the options object at the moment in order to create a new layer. We’ll update this to make the input options, err…, optional.

Out of interest, why are you creating a new Layer in code?

Currently we have no examples and tutorials, only API reference, so I try to investigate that.

As I can see that is engine-level feature, so probably It would be necessary to add some levels.

User manual: https://developer.playcanvas.com/en/user-manual/graphics/layers/
Engine example: https://github.com/playcanvas/engine/blob/master/examples/layers/index.html

1 Like

Wow, thanks, That’s exactly what I need right now!

I wonder why this manual doesn’t cover callbacks? I think it’s a one of the most great opportunity…

And why layers use callbacks instead of events?..

We will document the various callbacks too. These are called every frame - using events is more expensive especially if you do it every frame.

1 Like