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.