For reasons, I’m loading Babylon dynamically/asynchronously. I’m currently using setTimeout
to wait until BABYLON
is defined. Does Babylon provide some built-in way to execute code after it’s loaded?
TIA
For reasons, I’m loading Babylon dynamically/asynchronously. I’m currently using setTimeout
to wait until BABYLON
is defined. Does Babylon provide some built-in way to execute code after it’s loaded?
TIA
Hi @CarlBateman
If it’s possible then @sebavan knows to do it
Hey @CarlBateman, we do not support this per se but you should be able to hook into your loading code to allow executing code at the end of the run ???
As usual aFalcon does something unconventional…
TLDR; Below you can find we used Promise for your exact question. But we found more to it.
code
deleted, because ignored - as usual.
: )
Use it with requirejs?
Hi @sebavan thanks for the feedback.
I have a solution (the code keeps checking until BABYLON, etc. are defined) I was just checking that there was no built-in method.
// Can use in any place
window.addEventListener('babylon-onload', onBabylonLoad);
Object.defineProperty(window, 'BABYLON', {
get: function () {
return this._BABYLON;
},
set: function (scope) {
this._BABYLON = scope;
window.dispatchEvent(new Event('babylon-onload'));
},
});
Possible solution, but I prefer more explicit script.onload
.