I’m setting the loading bar width based on the data from the scene progress callback, but the issue is that the callback only starts firing after a few seconds. Until then, the progress bar just sits at 0, and once the callback starts, it fills up really fast.
Is there a better way to handle this or make the loading bar feel smoother from the beginning?
switcher.removeEventListener("progress", handleSceneProgress);
const handleSceneProgress = (e) => {
const loadingPercent: number = e.loaded / e.total;
if (isInitialLoad.current === 0) {
setLoadingProgress(loadingPercent);
}
setSceneLoadingProgress(loadingPercent);
if (loadingPercent === 1) {
}
};
To create a smoother loading bar experience that provides feedback before the scene progress callback starts firing, you can implement a method to give a preliminary progress update. This could be based on the estimated time it takes to load resources or a random slow increase until the actual loading data starts coming in.
Here’s a refined plan and the corresponding code:
Plan
Create a state variable, estimatedProgress, which starts at 0.
Increase the estimatedProgress at intervals (e.g., every 100 ms) until the actual scene progress callback provides real data.
Within the handleSceneProgress, set the loadingPercent from the callback but keep using estimatedProgress until the first update from the callback.
Transition smoothly between estimatedProgress and the actual loading percentage.
The setInterval function increases estimatedProgress slowly until actual progress is received.
Once the callback starts providing loading updates, you ensure that the actual loading percentage takes precedence.
The interval is cleared when the loading is complete to prevent unnecessary updates.
This approach will help make the loading experience feel smoother right from the start while still reflecting real progress as soon as it becomes available.
Feel free to ask if you need more assistance or improvements to this solution!
1 replies left - Get a PRO license for more AI replies. thread_xoAnNokKqYoZV8iqRLNO5Prb Reply to this message to continue the conversation
Hi, do you have a reprodution? The progress event is passed along directly from the three.js GLTFLoader which in turn is passed to the FileLoader.
Is it possible that you have Preload Next/Previous values set in the SceneSwitcher which starts download of subsequent scenes in the background already?
I’ll check if enabling this option doesnt invoke the event as expected since it’s not using GLTFLoader
Update: I don’t seem to be able to reproduce it and I get the progress event as expected.
In this video, I tried to show the issue more clearly. As you can see, the loading bar stays at 0 for a few seconds and only starts updating after that. For reference, I added a console log saying “from progress listener,” and you can see in the console that it only starts appearing after a short delay.
Link : Game creator Ks's Video - Apr 17, 2025
Relevant Code:
Hello @Ashokkumar_KR i’ve just tried this in a new stackblitz but can’t reproduce it. The progress callback is passed through to the GLTFLoader and fires immediately
See here the console logs (and logs on screen). If it takes a few seconds to start loading it might be related to your server where the asset is hosted?
Yep. The callback fired immediately once all GLBs were downloaded from the server. Do you have any recommendations for showing a progress bar or some updates during the downloads?
You’re asking about the SceneSwitcher? The SceneSwitcher can only load and display one file at a time. If you have multiple SceneSwitcher components in your scene you can combine their progress.
If you refer to the progress attribute on the <needle-engine> web component it’s event contains a totalProgress01 property as well as index and count properties.
Hey, thanks again, but this isn’t what I meant. Is there any callback fired during the fetch requests so that, before the SceneSwitcher progress callback, users can see that the GLBs are downloading—how much has been downloaded and how many are left?
Before the SceneSwitcher starts downloading the loadscene-start is raised, see the api here:
And as said before: the progress event callback is also straight passed into GLTFLoader and the SceneSwitcher can only load and display one file at a time so there’s always just one download process running per SceneSwitcher component
That being said: Your file is currently much larger than it should be and load much faster once we figure out what’s going on with compression in your project
So in your project mySceneClone is the root file (you added a GLTFObject in Unity to that object) and loaded by Needle Engine. Before that is done the SceneSwitcher is not available / not loaded yet.
I’ll reply via DM since i just opened your project