Loading Babylon dynamically/asynchronously

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

1 Like

Hi @CarlBateman

If it’s possible then @sebavan knows to do it :slight_smile:

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 ???

1 Like

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.

:eagle: : )

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.

1 Like
    // 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.