Image Rendering Issue

Hi,
I am trying to dynamically update images to a single material, the current issue I am facing is that while referrring to the material of the required entity, I am getting the reference as undefined

Here, I am attaching the project url for reference.
https://playcanvas.com/editor/scene/1723704

Can someone help me with issue here
Thanks in advance

Hi @Sripal,

I found a couple of critical problems in your script (ImgParser.js) that kept it from working.

The first is on line 18. When calling an asset attribute, you’re actually calling the Playcanvas Asset object as opposed to the asset itself. To call the material, line 18 should read:

this.entity.model.material = this.imgAsset.resource;

That led to a new error where the script was trying to upload an empty texture to the material before the image had been loaded. To remedy this, I changed line 75 in my fork to:

if(this.upload) this.ImgParser.upload();

and then went to line 56 to set this.upload to true once the image loaded:

this.upload = true;

There was a bit of other weirdness in the script when I looked it over, but since there were no additional errors and the material seemed to update, I stopped digging.

I hope this is helpful!

1 Like

Also as a side note, since you’re using just a static image file, you don’t need to upload the texture to the material every frame. You can do it once when the image loads, and then not again until you load a new image.