[SOLVED] Asset marked for preload is not loaded in specific case

So I have this ‘prefab’ object in scene, that has some resources in it (particularly, shaders)

Now I want it to be a new instance for each health-containing actor (in part bc I dont know how to make per-instance parameter, not sure if that possible in webgl)

I have another script that contains this Template entity as a parameter:

Then I create a clone of that object on start and call procedural creation:

this.bar = this.barPrefab.clone()
this.bar.script.healthbar.create()

now weirdly if I try to take shader asset from cloned object, instead of asset engine returns me number (asset id). Why is it not loaded after start? It’s fine and I can load it by checking asset like so:

// for some reason, only fragment shader isn't loaded, vertex is fine
var fragmentShader = "precision " + gd.precision + " float;\n"
if (typeof(fs) === 'number') {
    fs = pc.app.assets.get(fs)
}
fragmentShader = fragmentShader + fs.resource;

still, feels odd, since it’s the only place where I check for actually loading an asset.

Why it behaves like so? I thought if asset marked for preloading I’m guaranteed to have it in runtime.

It looks like a race condition, because if I call create method directly in template object (in initialise method) it loads fine.

Thanks.

Hi @nikita_osyak,

Check the top of your Healthbar.js script:

The fs attribute has a syntax error, ajsset instead of asset. If you fix that the asset will be made available loaded.

I am surprised that the editor parser didn’t complain though and you were able to reference the asset and also you got back the asset id.

@will @vaios I am not sure if that is a bug or a feature.

omg :smiley:

undocumented features

sorry about that, that was a silly issue. on the other hand, I wouldn’t go look for typos (usually), because they tend to break things in some other ways. that one really gotten out of hand.

Thanks, @Leonidas

1 Like