Loading Template -> Instatiating

I’m trying to figure out if theres a way to know when all dependencies (children) of a template asset are loaded as I want to instantiate it to the scene.

Using asset.ready doesnt work since it seems to fire as soon as the parent asset is loaded without waiting for the rest.

var self = this;
var onAssetsLoaded = function(asset) 
{
    let go = self.prefab.resource.instantiate(); 
    go.setPosition(0, 0, 0);     
    self.app.root.addChild(go);   
};   
  
self.prefab.ready(onAssetsLoaded);
this.app.assets.load(this.prefab);

Hi @MeanLagrange and welcome,

There isn’t any automatic way of doing that. You will need to come up with a system that gives you a list of assets (dependencies), load them in advance and when all assets are ready instantiate the template.

Common ways of doing that is by tagging the required assets in editor or traversing the entity hierarchy to find referenced assets.

2 Likes