[SOLVED] How can I change images dynamically?

I have a json of images and need to fill a carousel with them. I can create new elements but Im missing how to attach the image resource to them

The docs are really lacking

Assuming you have a reference to the texture asset, https://developer.playcanvas.com/en/api/pc.ElementComponent.html#textureAsset

I have a reference to the png asset on the folder - would that be the texture?

Yes, that would work. If you select the asset in the project pane, the inspector will tell you what type of asset it is.

You can also use the AssetRegistry to get an asset by name, tag or a custom filter (https://developer.playcanvas.com/en/api/pc.AssetRegistry.html)

Thanks, how do you assign the texture to the image element with code?

Example here where I find the asset by name in the AssetRegistry and use the API reference doc that I linked to earlier: https://playcanvas.com/project/626800/overview/load-texture-asset-to-ui

// initialize code called once per entity
LoadImageToUi.prototype.initialize = function() {
    var textureAsset = this.app.assets.find("Camera1.png");
    this.entity.element.textureAsset = textureAsset;
1 Like

Brilliant, thanks a lot

Yaustar - that worked flawlessly thanks.

Got a similar method to add a model to the entity and texture it? Im making a custom particle system and want to spawn 3D rotating coins for example

Think I found it

Same process except you will be needing the model asset (or mesh asset, I can’t remember the actual name) and corresponding material assets.