[SOLVED] Layer#renderTarget has been removed, maybe the API has been changed in 2.0?

Hi, I just found the error in running following script, (running under version 2.10)

ApplyTexture.prototype.postInitialize = function () {

    var layer = this.app.scene.layers.getLayerByName(this.layerName);
    if (layer !== null) {
        // get the instance this script is attached to
        var portal = this.entity;

        // create a new material
        var material = new pc.StandardMaterial();
    
        portal.render.material = material;
        console.log('layer.renderTarget is ', layer.renderTarget);
        material.diffuseMap = layer.renderTarget.colorBuffer;

        material.update();
    };
};

How could I resolve this problem in ver 2.x?

thanks a lot

The RenderTarget on the Layer has been deprecated for few years now, and fully removed in 2.0.

You will need to change the code to use RenderTarget on the Camera instead. There’s one of the examples here:
https://playcanvas.vercel.app/#/graphics/render-to-texture

Thank you very much, it’s solved.

1 Like