When to know scripts is ready in loading screen?

hello All,

I created a customLoad script that I want to call right after the preload. The idea is to load some extra assets from the web while im still in the loading screen.

I start my custom load when I receive the ‘preload:end’ message in the loading screen, I then call :
app.fire(‘customload:start’); I then load all my extra stuff.

I will hide my loading screen when I receive :
app.on(‘customload:end’, function () {

The problem I have right now is that sometime my script is not yet loaded or finished loading. So I added this :
app.on(‘preload:end’, function () {

     setTimeout(function() {
            //let the time for scripts to load properly
        }, 100);

But on some situation, I would need to put 1000ms or more for this to work.

Is there a sure way to know that my script is loaded and ready to use?

I tried
app.assets.on(“load”, function (asset) {
console.log("asset loaded: " + asset.name);

But seems like script is not yet available at that moment? (script will never receive app.fire(‘customload:start’))

Thanks for your support.


Hi @memleak,

If you want to call an event listener in one of your scripts, then you need to do that after pc.Application fires the ‘initialize’ event:

app.on('initialize', function(){
  // all scripts have gone through their initialize method

Check the order of execution here:

ha!! thanks!!

1 Like