I’ve noticed a bit of lag whenever I first load my WebGL build. Now, the strange thing is that when I restart the same scene, meaning I do all the same processes than the first time, the lag is gone.
Is there anything that Unity itself does when a game is first started that it doesn’t to when (re)starting a scene? Any idea how I could avoid / optimize it?
When starting always during the first 10 seconds there a lag, no more than ± 10 frames per second … after of 10 seconds frames is OK going to 60 frames per second … and when reload level (sceneManager.LoadScene) no lag for the first 10 seconds …
… i built a project empty … only camera and a UI text … showing frames per seconds … when starting does not reach 60fps immediately … but when you press the restart button (and reload scene) the 60 frames are instantaneous …
Another hacky option is to first load into an empty scene with an image or video that imitates the splash screen and then load the real scene async.
I’ve found that this can overcome the initial frame issues and doesn’t add much loading time.
I’ve recently done this for different reasons but I noted that it certainly helps. My objective was to load an empty scene, play a full screen video (as a fancy loading screen) while my real scene loads.
This worked out really well, it loads the first scene really quickly and then shows the user something far better than the splash screen or black screen or what ever is typically showing and I also don’t get the initial poor FPS performance at startup…
It’s a very simple thing to test, you may be surprised how well it works.
Something similar was thinking … very thankful … thanks @larku
PD: researching from the chrome profiler to find out exactly what happens … lag appears even with simple project clean without code in Awake, Start … functions
I’ve had this problem before, especially in lower end devices like chromebooks. I believe it is the browser JIT compiler trying to optimize your code. Try doing a webassembly build and you shouldn’t have this issue.