Passing a changing variable into a Babylon Scene (eg from Svelte)

Hi @awenine and welcome to the community.

This is the way I do it:

Create a global singleton Render class that wraps Babylon.js with your additional functionality, then import the instantiated Render object into your svelve component that contains your render canvas, lastly trigger instantiation of Engine and Scene within your Render object only from within the onMount method of your svelte component.

In your Render class, simply subscribe to or set Svelte global app stores, so whenever they’re updated, it’s reflected across the application, whether 2D UI or 3D.

4 Likes