I tried loading a city map (less than 7MB in texture files) in runtime by pressing L. I tried loading by tag or enabling the entity. Both freeze the screen while loading for about 3 seconds. Is there a way to load an asset runtime by script without the freeze?
You can press F and see the car move forward inside a tunnel and then press L which will load the city showing up at the end of the tunnel.
You will find that the animation freezes and everything freezes for a few seconds while the city is loading. Basically I will be replacing the L with another event so the city loads as the car approaches the end of the tunnel. Whether L or another event, the freeze will still happen.
The freeze is most likely due to materials compiling their shaders. The first time a material is being rendered in scene if it uses a shader that hasn’t being compiled, it may freeze the main thread for a while.
One way to avoid that is to have your models initially enabled on the application first frame, and immediately disable them. That should be enough to get them to compile.
How does that look code wise? Do I enable the city entity in the beginning and disable right away in the code right after the enabling code? And then reenable again later on upon pressing L?
You can start with the model loaded, then on the first update you check if its enabled and then just set it to disabled.
Use a flag to make sure it only happens once