Loading assets when entity is enabled

Hi guys,

I’m building a project that fetches results from an API, and then displays different environments depending of said results. Each environment is an entity composed of different models and entities, but are all built around the same base.

For instance :

image

Also, the number of environements will grow considerably over time. The issue with the current way I do things is that every single asset is downloaded by PlayCanvas before initialization. That’s going to make the project really heavy, and long to download.

Making a different project for each environement is not an option as it’s a serious hassle for both maintenance and new features that need to be shared. I thought about making a different scene for each environment and then switching programmatically between them, but the issue stays the same, everything is downloaded before the app is ready. Using scenes has the advantage of allowing me to duplicate the base scene to create the new environements, but does not help me when it comes to adding new shared features, that will have to be duplicated over all environements.

So my question is : is there a way to load the assets specific to an entity only when the entity is enabled, even if that means showing a loader or transition in the mean time ?

If you have another solution I’m more than happy to try it too !

If the assets aren’t set to preload and the entity is disabled to start, the assets will not be loaded until they are first enabled.

When it is first enabled, generally the components will kick off load requests async and things start popping into the scene.

The other alternative, is that you tag the relevant assets and load them before enabling the entity. Something similar is done here Load assets with a progress bar | Learn PlayCanvas

Alternatively, if you are wanting these to be in scenes then you can use the same way as I mentioned above where you tag the assets needed for the scene and disable preload.

Find the assets by tag, load them and then load the scene.

Example in the docs here: Loading Scenes | Learn PlayCanvas “Managing assets in scenes”

Thank you so much for your fast reply ! I’ll give this a try !!