[SOLVED] Asset loading duplicate

For example, this code will be executed multiple times.

loadAsset.ready((asset) => {
    // ready
});
this.app.assets.load(loadAsset);

Will the asset be loaded only once?
In the rest, all calls to “loadAsset.ready” will cause a callback, but without loading the asset?

Hi @SARJ,

No, the ready callback will only fire if the asset is unloaded and you call assets.load(). Otherwise it will not fire.

Should I use a similar script in this case?

if (loadAsset.loaded === true) {
	// Asset actions
} else {
	loadAsset.ready((asset) => {
		// Asset actions
	});
	this.app.assets.load(loadAsset);
}

No need for that check. If the asset is loaded, the ready callback will be executed immediately, otherwise it will load it first, then execute it.

2 Likes

Great! So I can use the script from the example in the first post :slightly_smiling_face:

1 Like

Yes my bad, it seems that if the asset is loaded then there is no need to load the asset again, the ready callback is fired as soon as you register it.

2 Likes