[SOLVED] How to get a picture from my assets?

How to code?
image

It seems like doesn’t work by this way…

Did you try getting it by using attributes? If it didn’t work, try reaching out to @will or @yaustar.

Should I use the attributes??

Sometimes getting assets using code doesn’t work for me. When I use attributes, the bug is solved sometimes. Not sure if it will solve your problem though. But you could try.

var logoAsset = this.app.assets.find("UKGAMES.png") should work, it’s strange that you’re getting undefined for logoAsset.

If that did work, you would then get the URL via

logoAsset.getFileUrl();

The API requires the asset type AFAIK
https://developer.playcanvas.com/en/api/pc.AssetRegistry.html#find

Try:

var logoAsset = this.app.assets.find("UKGAMES.png", 'texture');

:joy:

So many undefined:joy::joy::joy::joy:


Hi @MaxmilianLiu,

Can you post a link to your project? Might make it easier for others on the forum to take a look and help out.

:joy:I already borrow a cloud service to store my pictures

Maybe the loading script can’t read the assets.

The API requires the asset type AFAIK

I’ve been using it successfully without the type, so it should still work.

I’ve noticed that you are using what looks like to be the old scripting system syntax. Here’s an example with current scripting system: https://playcanvas.com/editor/scene/792436

Oh,thx,I will try it,Can you use this script on loading.js??

Ah, you were trying to do this for the loading screen. In which case, hosting it externally would be better or use a base64 encoded string for the image. Otherwise you have to wait till the assets database is initialised.

See this thread for more details: [SOLVED] Load loading screen assets first

Thx for your reply:)I already done with this.