Material not updating the texture in script

The following code changes the material’s texture

this.entity.model.material.diffuseMap = this.tex_lens.resource;

But the below code gives error as : material.update is not a function

// declaration
Script.attributes.add('mat_lens', {type: 'asset', assetType: 'material',default: null });
this.mat_lens.diffuseMap = this.tex_lens.resource;// asset.resource;

Everytime if we have to take the object and then change the material properties then it becomes longer code. Is there anything wrong in the second code?

Asset attributes are referring to the pc.Asset not the resource itself. So in this case you should do

this.mat_lens.resource to access the material because this.mat_lens is the pc.Asset.

1 Like

Thank you Vaios. Only problem is many such important things are not easily available. Can you share some links.

You can find more information about script attributes in the User Manual here:

And also in the API reference here:

Let us know if you need any more help :slight_smile:

Thank you again.
Please help on the below query as well.