How do I detect when an asset is really ready?

I have a bunch of GLBS loading at runtime from resources for which I am using:

big_assets[x].once('ready', this.onAssetLoaded());

…which seems to be triggering correctly except for the fact that even after this trigger I still see textures popping in and being put on the object during runtime.

To me it looks the the ‘ready’ event just means ‘available’ and not actually yet ready.

Shouldn’t the ready function mean ‘fully ready’ or is there another event for that?

In my case, I am trying to switch the textures on an object as soon as it is ready and so I need to know the exact point that it is completely ready. :slight_smile:

This will invoke onAssetLoaded immediately, which might not be what you want

big_assets[x].once('ready', this.onAssetLoaded());

What you’re probably looking for is…

big_assets[x].once('ready', _ => this.onAssetLoaded());

Hmm, the onAssetLoaded function doesnt ever seem to run with that. ?

Can you share the project link?

Its a huge project and for a client so I don’t think I can (I will ask). Weirdly the textures are already loaded so I don’t know why mapping them to the object takes extra time.
Any idea if I should be using ‘ready’ or ‘load’ as the event?

Looks like you want the ‘load’ event, ‘ready’ doesn’t seem to exist. Asset | PlayCanvas API Reference

Cheers. In the end the following code worked:
I use the bind in this way, I use ‘load’ as the event and I run the onAssetLoaded function even if its already loaded .

if (big_assets[x].loaded) 
      console.log("already loaded")
      big_assets[x].once('load', this.onAssetLoaded.bind(this));

How do you know which of the assets is loaded? I’d suggest something like this, which should work for both cases - when an asset is loaded and when it still needs to be loaded:

asset.ready(loadedAsset => {