engine icon indicating copy to clipboard operation
engine copied to clipboard

Should AssetRegistery#add also load assets if marked as preload?

Open yaustar opened this issue 4 years ago • 4 comments

https://github.com/playcanvas/engine/blob/main/src/framework/asset/asset-registry.js#L244

This means that on the launch of an application, when the assets are added via Application#configure (using _parseAssets), they are already loading despite Applications#preload not being called yet.

Preload function doesn't actually start any loading in our case, just sets up the events.

yaustar avatar Apr 20 '21 21:04 yaustar

Just got in touch with this issue on a recent project. We were customizing preloading routine to support asset tags, and turns out app.preload() doesn't do anything because app.configure() already starts loading everything via AssetRegistry#add. In my opinion, it shouldn't be the case - if assets marked with preload: true are added to the registry manually, the preload routine should also be called manually.

cognitiveplus avatar May 08 '21 15:05 cognitiveplus

I believe it should not. As preload is very much convenience things for bootstrapping a project, which is Editor case as well. Also, "preload" is tied to "loading" screen. And if developer wants to add manually asset, they can manually call load straight away if needed.

If load would be automatic, it will require to ensure there is no preload:true flag, and if there is, it won't be apparent to a developer of the behaviour. Basically a "magic behaviour". It is best to avoid such cases.

If it can be done by explicit call - great, let it be done by explicit call. Without introducing branching behaviours.

Maksims avatar May 08 '21 16:05 Maksims

Just ran into this issue. See this forum thread: https://forum.playcanvas.com/t/assetregistry-not-available-in-custom-loading-script-v2/40918

Only relevant when using the playcanvas editor.

TLDR: With engine v2 there is currently no way to modify/customize the preloading of assets before they are added to the AssetRegistry. If they are marked as preload in the editor they will always load. In v1 it was possible to set preload to false in a custom loading script by using the AssetRegistries add event. Unfortunetly this isn't working with v2, because the AssetRegistry isn't available yet, at the time the loading script is run.

lucaheft avatar Oct 02 '25 14:10 lucaheft

@willeastcott @mvaligursky Sorry to bother, but this totally breaks our current custom scene loading mechanism as described in the previous post. Is this something you are willing to change? The change is trivial and I don't think it would have many side effects. I'm open for some discussion and can create a PR if desired.

lucaheft avatar Oct 15 '25 07:10 lucaheft