Update variable every second

Hello ,

I have huge mesh who take approximetly 2min to doawnload ( 100 Mo ) , and i want to show a faker preloader with percentage.
I am using BABYLON.SceneLoader.ImportMesh, and knowing that is an asyncFunc so i cant update a faker varibale inside on it .

There is any way to update a variable every second and show it with Gui ?

Thanks a lot

You can totally do it with a setInterval as I believe most of your time your browser will wait for the network so your code will be able to be executed

thanks for replay !
I already try it , but i cant find where i can put it ? i tried scene.registerBeforeRender but the varibale stay in the same value .

Hey there !
The setInterval() function puts the listener on Window, so no matter where you set your interval, it better not be read more than once (or you will have several parallel intervals).

That means you don’t need any Babylon observable like scene.registerBeforeRender(), depending on your environment, you can either call it plain and simple in your script, or in a lifecycle callback like mounted() if you’re using a component based framework (like react or vue).

Here is a demonstration on a playground.

1 Like