- Home /
Why is first time level load much slower? (iPhone)
So I have noticed this lately but I can't explain why...
When I put a fresh build of my game on my iPhone 4, the first time I load a level (go through UI, select level to play > load that level), the load time is around 10 seconds. Then I exit the level, go back to the level selection screen, and load any level (same level or other level doesn't matter), my load times go down to 2-3 seconds tops!
At first I though that maybe it was caching the assets for that level, and when loading it again, it was faster because the assets were ready, but I don't think that's the case, because it doesn't matter which level I load first, ALL following level loads for ANY level are much faster.
If someone could enlighten me I would really appreciate it!
Thanks for your time guys, Stephane
It could be releated to not gameobject but the textures and other assets which requires a litttle bit more time to load maybe. Unity might be decompressing audio/texture etc behind the scenes depending on the format of your choice. So the second time you load the level some of those textures/audio you are sharing between levels may still be in cache.
But without seeing the actualy project its just an idea of what might be happening :) hope this helps :)
Other ideas:
Garbage collection?
Something in the previous level's destroy routines?
Something in the new level's awake/start routines?
You could also try this to see if it's an asset loading issue like Nidre suggested: In the previous level/main menu, call Resources.UnloadUnusedResources before loading the new level. This should force Unity to reload any assets that are in the new level but not the previous level.
Thanks for the tips guys, I will definitively call Resources.UnloadUnusedResources before loading the new level to see if it's an assets loading issue.
I use PVR compressed textures everywhere. I also do lots of reference caching in my Awake and Start functions.
The weird thing I have noticed tho is that on the first time level load, nothing gets printed to the XCode console for about 10 seconds, and then finally all my Debug.Logs from Awake and Start functions get printed and the level loads.
I am wondering why nothing happens during the first 10 seconds...any subsequent level loads after that happen right away (the logs get printed as soon as I load the level, there is no delay). Any idea why this is happening?
Thanks again, I will report back my findings...
$$anonymous$$aybe you have a lot assets in Resources folders? Those assets are always packed with the first scene that is loaded and prepared even before the scene loads. That's also the reason why you should avoid Resources folders and Resources.Load if possible.
I have about 20 fonts and a few GameObjects in my Resources folder, but I need to check if some of the plugins I use do have their own Resources folders with lots of stuff in it... You say that it is always packed with the first scene that is loaded, and in my case, it's my $$anonymous$$ain$$anonymous$$enu scene which loads quickly, the 10 seconds hold up happens when I load an actual GamePlay level, which is probably the 3rd or 4th scene being loaded by then. So the hold up then shouldn't come from the Resources folder correct?
Answer by ronronmx · Apr 13, 2013 at 06:57 PM
UPDATE
Well I realized that my MaterialManager as a link (dragged and dropped in editor) to a substance, so that's why they're being used. What I still don't understand is why the other 10 substances are being compiled since I don't use them anywhere.
Anyways, here's a post I found about substances and loading times:
The last post reads:
"Just to ensure thats kept in mind: Prior to Unity 4.1, there was no support for dynamic substances in mobile targets at all! If you used substances in Unity 4.0 and earlier for a mobile target, they were baked upon export, there was 0 runtime allocation and 0 disksize saving, all you got was an easy, consistent cross platform development.
This indeed means that it will now take significantly longer at runtime if you decide against bake at edit time (which was what it did before 4.1)"
So yeah no wonder my load times went up all of a sudden with Unity 4.1, would be nice if they warned us about this!
ORIIGNAL
So I pinned down the problem to Substances!
I have a folder with a dozen Substances in my Project, and if I remove this folder and make a new build, the 10 seconds hold goes away...it's compiling Substances! The weird thing is that none of my assets in any of the levels I'm loading use Substances, so I don't understand why they are getting included in the build, and especially why they are being processed since no assets use them?!?
So the good news is that I finally figured out what the problem was, the bad news is that I don't understand why the problem is happening in the first place :)
Thanks guys!
Stephane
Good call Stephane - I'm searching my project now for .sbars!
You should mark this as the right answer, saved me a bunch of headaches.
I have similar Issue with my game, On iOS the load time is as long as 1 $$anonymous$$ute for the first time it loads after installation. Any other time, it would load within 6 seconds.
I tried to find the substances folder, but didn't find anything. Can you help ?
BTW - I am using curved world shaders, not sure if that are causing the Issue. The build size is around 34 $$anonymous$$B.
Answer by Graham-Dunnett · Apr 11, 2013 at 11:54 AM
Unity's compiling shaders for you. See:
http://docs.unity3d.com/Documentation/ScriptReference/Shader.WarmupAllShaders.html
(Note that API allows you to warm the shaders up. Your delay is Unity doing this before the level plays the first time. The API won't help you, I just use it as a way of teaching you what happens.)
Interesting - no way of turning that off to get a menu screen up faster?
So are ALL the shaders I have in my project being Warmed Up before the first level load, or just the shaders used by the GameObjects of that particular level?
$$anonymous$$y very first level being loaded is my $$anonymous$$ain $$anonymous$$enu scene, which loads rather quickly, and uses maybe 3-4 simple UI shaders. The 10 second loading hold up happens when I load one of my GamePlay level for the first time, which is probably the 4th scene being loaded by then, and is of course the scene which uses the most shaders.
So is it first war$$anonymous$$g up my $$anonymous$$ain $$anonymous$$enu scene shaders when the $$anonymous$$ain $$anonymous$$enu is being loaded, and then my GamePlay level shaders when that scene is being loaded? Or are ALL the shaders being warmed up before the very first scene load?
Thanks!
Your answer
Follow this Question
Related Questions
Android load/unload times 0 Answers
How to transition from Load to scene ? 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Preloading scene issue 0 Answers
how to save a load a game? 1 Answer