Template Preload Question

If I choose not to preload a template BUT I choose to mark the assets which make up the template as preload…do those assets get preloaded? (Or are they overridden by the templates preload behaviour?)

It seems to not make much/any difference if I uncheck the assets as well as the template.

Yes, the assets will get preloaded or not depending on their preload state.

That isn’t affect by the template preload flag.

1 Like

So setting the templates preload checkbox really does nothing at all?

Oh it does, template is an asset on its own.

But if I load a template, should it load all related assets if they aren’t already loaded?

It will not load the assets automatically. A template loads entities and you can append those in the scene hierarchy. After you do that, entity components that reference assets will have them load.

Check this thread for more on this: Loading a template via assets.load does not load its associated assets before calling callback

OKay, so is there an easy way to load all assets related to a template (materials and glb files)?

I want to load them in the background.

Cheers

I don’t think there is an easy way to do that.

You will have to traverse the entity hierarchy after you instantiate the template and find them manually in each component.

Actually I want to load them before the template is even instantiated. It seems to load them automatically once instantiated.

1 Like

In the end I just instanced each of my templates and immediately destroyed them. This seems to force the textures and models to continue to load in the background.

Sadly there doesn’t seem to be a way of then prioritizing certain resources depending on user actions. They just seem to load in the order I instanced them.

That’s a nice trick.

If you have a reference to the asset, then you can instruct the assets registry to start loading them immediately. Example:

this.app.assets.load(asset);

I tried doing…

this.app.assets.load(model_to_load);

…using the template name at the point which I want a specific models resources to load, but I think because its already downloading other stuff it doesn’t seem to prioritize this.

I was wrong before, assets.load() requires an asset reference, not an asset ID.

To get the asset from and asset name do this:

const asset = this.app.assets.find(assetName);
if(asset && asset.loaded === false){
   this.app.assets.load(asset);
}

If you have an asset ID it changes slightly to:

const asset = this.app.assets.get(assetId);
if(asset && asset.loaded === false){
   this.app.assets.load(asset);
}

That’s correct, it’s up to the browser after that moment.