Waves script not working

Hello, what is wrong in this script it give an error in the getAssetById line

var Lake = pc.createScript('lake');
Lake.attributes.add('materialAsset', {type:'asset', assetType:'material'});
Lake.attributes.add('speed', {type:'number', default:0.1});

// initialize code called once per entity
Lake.prototype.initialize = function() {
    this.entity.tmp = new pc.Vec2();
            if (this.materialAsset) {
                this.material = this.app.assets.getAssetById(this.materialAsset).resource;
            } 
};

// update code called every frame
Lake.prototype.update = function(dt) {
    var tmp = this.entity.tmp;
    
    // Calculate how much to offset the texture
    // Speed * dt
    tmp.set(this.speed, this.speed);
    tmp.scale(dt);

    // Update the diffuse and normal map offset values
    this.material.diffuseMapOffset = this.material.diffuseMapOffset.add(tmp);
    //this.material.normalMapOffset.add(tmp);
    this.material.update();
};

Hi @ayrin,

As far as I know there is no method called getAssetById on the assets registry. That would be:

this.material = this.app.assets.get(anID);

But why do you need to do that since you are already referencing that asset using a script attribute? So the material can be retrieved like this:

this.material = this.materialAsset.resource;

i don’t need to do it like that, it was made so with the legacy scripts, but seems to work fine like you suggested, i will confirm it when i solved my troubles with the raycast :frowning: