Search Unity

Extremely slow scene loading with Unity Android

Discussion in 'Android' started by tr1stan, Dec 15, 2010.

  1. tr1stan

    tr1stan

    Joined:
    Jan 23, 2009
    Posts:
    150
    There's a wired problem for my android game (migrated from my existing iPhone game), the scene loading is too long, almost longer than a minute.

    My devices are Galaxy S and Galaxy Tab. Since they have fast CPU GPU than iPhone 4 so I can't believe this result is normal.

    My game loading was fast for iPhone version. On iphone 4 it was about 10s and on 3GS that was 15s.

    I thought that could be the problem of the asset so I reduced the size of texture but it does no help. Then it must be some thing wrong with my project settings. Can anyone help me to figure this out?

    Any help will be appreciated

    Edit

    In android task manager, it consumes more than 100m RAM during loading a scene. And then reduced to 30m when the new scene is loaded. The RAM can be the cause, but I can I fix it?
     
    Last edited: Dec 15, 2010
  2. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
    Android is currently expected to have slightly longer loadtimes, but that seems a bit excessive. Are you perhaps relying heavily on Resources.Load() to access your assets? Is the logcat showing anything 'useful' / related?
     
  3. tr1stan

    tr1stan

    Joined:
    Jan 23, 2009
    Posts:
    150
    Thanks for the reply.
    Yes I have some assets with Resources.Load(). It's about 4 skinned meshes to be allocate in Start() method when the scene is loaded.
    If that was the problem, what's is the replacement if I want assets loaded at runtime?
     
  4. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
    There is no replacement as such; I'm more trying to pinpoint if the loadtimes you see is because of using Resources.Load() (which we have plans to optimize) or that you find some other corner case. If you could point those skinned meshes to a (global) dummy asset in the scene, to remove the dependency on Resources.Load() and to see if that drastically changes the loadtimes; then we at least know that the problems you are seeing is because of slow Resources.Load().
    And, if possible, open a bug with your project as a repro case would of course be valuable too.
     
  5. foyleman

    foyleman

    Joined:
    Feb 19, 2009
    Posts:
    116
    Has this been resolved?
    I'm trying to figure out how if this is causing my issues with very long load times (4 minutes for one scene) or if I should be looking for something else. I am trying to trial and error the issue, but 20+ minute build times is making it quite a hassle.

    A little more background... we're going from a fully functional iOS game to Android.

    Also, if you don't know the answer but also experience this issue, let me know. I wouldn't feel so alone here. ;)
     
  6. mindlube

    mindlube

    Joined:
    Oct 3, 2008
    Posts:
    993
    Hmm I don't see anything in the 3.2 release notes about Android Resources.Load() being slow I was also wondering if it's not recommended to use Resources.Load().

    -- edit --
    OK cool- my scenes seem to load very quickly on Android. And that's even with the PVRTC->RBG decompression going on in the background.
     
    Last edited: Feb 16, 2011
  7. TMK

    TMK

    Joined:
    Mar 29, 2010
    Posts:
    91
    Ah, I'm having the same problem on my project. It works great on iPhone and iPad, but not on Android (testing on Nexus One).

    Whenever I switch to a new scene, it takes about 20+ secs to switch to it, while it takes just 1 second on iPhone.

    I'm not using Resources.Load much (just on a couple text files), so that shouldn't be the cause for my problem.

    I do however use AssetBundles on all the bigger graphics, so whenever I switch scenes, I go through a "Load" scene which pre-loads the needed AssetBundles and unloads all other AssetBundles, before continuing to the target scene, so I'm suspecting that might have something to do with it...

    I haven't gotten to test it out much yet, as I just started on the Android build today.
     
  8. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
    Interesting; have a look in the logcat ('adb logcat' from cmd.exe / Terminal, or DDMS; both part of the Android SDK) when you trigger that "Load" as there might be some hints to what's going on.
    Also, if you manage to get a small'ish / simple project that reproduces that problem please just report it as a bug (Help -> 'Report a Bug') and attach said project.
     
  9. Enzign

    Enzign

    Joined:
    Aug 20, 2010
    Posts:
    169
    I don't know if this has anything to do with anything, but if i use async loading for scenes, loading times on iphone takes 30+ extra seconds, and on android i have never waited long enough to see the level finish loading...
     
  10. n0mad

    n0mad

    Joined:
    Jan 27, 2009
    Posts:
    3,732
  11. TMK

    TMK

    Joined:
    Mar 29, 2010
    Posts:
    91
    Here's what logcat says:

    Code (csharp):
    1. D/dalvikvm(  610): GC_EXPLICIT freed 2310 objects / 135248 bytes in 880ms
    2. V/Unity   ( 1198):
    3. V/Unity   ( 1198): Unloading 7 unused Assets to reduce memory usage. Loaded Objects now: 1340.
    4. V/Unity   ( 1198): Unloading 3 Unused Serialized files (Serialized files now loaded: 0 / Dirty serialized files: 0)
    5. V/Unity   ( 1198):
    6.  
    7. SWITCHED SCENE HERE
    8.  
    9. V/Unity   ( 1198): Unloading 1 unused Assets to reduce memory usage. Loaded Objects now: 1801.
    10. V/Unity   ( 1198): Unloading 2 Unused Serialized files (Serialized files now loaded: 0 / Dirty serialized files: 0)
    11. V/Unity   ( 1198): Non platform assembly: /assets/bin/Data/Managed/System.dll (this message is harmless)
    12. D/dalvikvm( 1198): GC_FOR_MALLOC freed 5980 objects / 402504 bytes in 64ms
    I've also turned off any AssetBundle loading, and it still happened. I also switched from LoadLevelAsync to LoadLevel but that didn't help either...

    When starting the game, if I go directly to the title scene without going through others, it seems to go faster though, instead of going through the "load" scene (even if the load scene doesn't do anything but loading the target scene). So might somehow be just the scene switch itself that takes a long of time.

    I've submitted a bug report with a small project it happens on now though, so hopefully we'll be able to find out what makes it happen :)
     
  12. TMK

    TMK

    Joined:
    Mar 29, 2010
    Posts:
    91
    Have you happened to gotten any further with this, tr1stan?

    I've submitted a sample project bug report to Unity a week ago, but haven't heard anything back yet. Hoping it's something that will be looked at, as it's the only thing keeping me from releasing the game on Android :)
     
  13. Wozik

    Wozik

    Joined:
    Apr 10, 2009
    Posts:
    662
    TMK, may be your report got lost? Please provide a six digit case number (no links please) of your bugreport so I can recheck.
    And thank for submitting a bug.
     
  14. bbvrdev

    bbvrdev

    Joined:
    Aug 11, 2009
    Posts:
    221
    I also experience this issue. I'm not doing Resources.Load() or anything crazy, but my scenes are like 30 seconds or more to load, whereas on iPhone4, they're like 1 second.

    Anyone made any progress on it? I have got to get this fixed before we release!

    EDIT: I am doing LoadLevelAsync() on one scene, but the loading of all the scenes is super slow, not just that one.
     
    Last edited: Feb 25, 2011
  15. TMK

    TMK

    Joined:
    Mar 29, 2010
    Posts:
    91
    Thanks for your reply! It would be great if you could check it :)

    Here's the bugreport number: Case 392128
     
  16. bbvrdev

    bbvrdev

    Joined:
    Aug 11, 2009
    Posts:
    221
    Reducing some of my textures to 16-bit made a HUGE difference. I went down from 30 secs to 10.
     
  17. TMK

    TMK

    Joined:
    Mar 29, 2010
    Posts:
    91
    Ah, thanks for that info, sandworm! That's very interesting. Unfortunately I've set almost all my textures to 16-bit already, so perhaps I already have that speed boost on my project...
     
  18. bbvrdev

    bbvrdev

    Joined:
    Aug 11, 2009
    Posts:
    221
    No worries :) I wish I could get a better 16-bit render from the unity texture converter though, it looks really ugly on some of mine if I do 16-bit.
    I'm at GDC in San Francisco now, and I intend to ask the Unity dudes tomorrow a few questions :)
     
  19. TMK

    TMK

    Joined:
    Mar 29, 2010
    Posts:
    91
    Oh, I was about to comment on that too actually. On iOS, 16-bit textures looks very good, depending on the texture it looks very similar to 32bit, but on Android, the same textures looks like they have even less colors, making them more ugly.

    That's hopefully something we can work around though, just have to get that slow-scene loading fixed somehow :)
     
  20. TMK

    TMK

    Joined:
    Mar 29, 2010
    Posts:
    91
    Just an update, I installed the newest Unity 3.3 version now, and the same very slow scene loading happens there unfortunately...
     
  21. TMK

    TMK

    Joined:
    Mar 29, 2010
    Posts:
    91
    Had any chance of checking if my report with example project got lost? Still haven't heard anything regarding this pretty big problem in Unity... Case number 392128, submitted it 17th February.
     
  22. YossiMH

    YossiMH

    Joined:
    Mar 22, 2011
    Posts:
    11
    In the unlikely event that my chiming in will be of help to anyone, I too am having a crazy slow scene loading experience.

    Thanks.
     
  23. TMK

    TMK

    Joined:
    Mar 29, 2010
    Posts:
    91
    Ah, if you happen to have the time, it would be great if you could submit an error report with a sample project to Unity, the more reports they get on this, the better chance we have of figuring out what makes it happen :)
     
  24. Wozik

    Wozik

    Joined:
    Apr 10, 2009
    Posts:
    662
    Martin, sorry for a slow response. I'll take a look at this asap and return to you.
     
  25. nekokiller

    nekokiller

    Joined:
    Dec 9, 2010
    Posts:
    12
    I have the same problem ( scene loading very slow ) with Unity 3.3 on Android mobile device. ( Samsung Galaxy I9000 )

    In my project, I have some scenes and the order is :

    MainMenu.unity 0
    Level_01.unity 1
    Level_02.unity 2
    Level_03.unity 3
    ...


    Loading time of MainMenu is very fast (less then 1 sec.), and then I start to jump to Level_01.

    It is also very fast (loading time less then 1 sec), and then jump to Level_02 from Level_01, it is still very fast..(less then 1 sec.)

    Jump to Level_03 from Level_02, is very fast, too. ( less then 1 sec.)


    But if I jump to Level_02 from MainMenu, it is very slow! loading time is more then 20 sec.

    Also, jump to Level_03 from MainMenu, very slow!

    Jump to Level_03 from Level_01, very slow!

    Jump to Level_01 from Level_03, very slow!



    I have try this: setup the scenes building order:

    MainMenu.unity 0
    Level_03.unity 1
    Level_01.unity 2
    Level_02.unity 3
    ...


    You can guess what happened. Loading Level_03 from MainMenu , is very fast ( less then 1 sec.)

    Jump to Level_01 from MainMenu is very slow ( more then 20 sec.)

    Jump to Level_01 from Level_03 is very fast ( less then 1 sec.)

    Jump to Level_03 from Level_01 is very slow ( more then 20 sec.)


    ( use Application.LoadLevel or Application.LoadLevelAsync , nothing different )



    But there is no problem on iPad/iPhone, it's always fast with any scenes building order.

    So , is this problem cause by the data seeking speed of the storage device ( like SDHC class 2 ) of mobile ??
     
    Last edited: Apr 13, 2011
  26. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    not only the card (though class 2 is very slow, not just for seeking but especially data transfer) but also the interface itself - card interfaces tend to be much slower than internal flash on the throughput end (going down to "is that a joke?" ranges). Additionally naturally also worse CPUs and slower ram can play in, you can't really compare whatever you have with iOS unless you are on Nexus S / Galaxy S, as thats the only Android device thats comparable technically (as same hardware)

    Thats why devices with 8-16GB internal and potentially not even a card slot (like nexus s) are to favor over 400mb internal + card slot like Xperia Play (Microsoft realized that right from start, thats why they put up an 8GB internal min requirement for WP7 and apple never sold with less either) if your target is gaming.
     
    Last edited: Apr 13, 2011
  27. Wozik

    Wozik

    Joined:
    Apr 10, 2009
    Posts:
    662
    We're working on optimizing prefab/level loading on Android now. There will be a beta 1 soon to get the first wave of fixes ;-)
     
  28. mindlube

    mindlube

    Joined:
    Oct 3, 2008
    Posts:
    993
    Wozik, is this beta 1 going to be a public release? i.e. will it show up through "check for updates" in the editor? thanks
     
  29. tion80

    tion80

    Joined:
    Mar 5, 2009
    Posts:
    54
    Same question here... Would it be a public build? or should I report a bug to get the fixed build?

    We're having more than 1 min loading time for many scenes.

    -Junction
     
  30. Wozik

    Wozik

    Joined:
    Apr 10, 2009
    Posts:
    662
    Only beta Editors would notice the beta updates. Release editors get only new final releases.

    Anyway, sorry guys, the beta 1 is not out yet, so I cannot share it with you just yet.

    It's better to spend some more time on development/testing rather then release a not-so-ready thing to you, right?
     
  31. kromenak

    kromenak

    Joined:
    Feb 9, 2011
    Posts:
    270
    I think I'm having a similar problem, though in a bit of a different situation.

    I built a scene file with several game objects with large textures. Running this scene on the Android yields a 2-3 second loading time, nothing out of the ordinary. I then have some object instantiations that occur during gameplay, and these work fine.

    However, I then took the different parts of that scene and created prefabs out of them. Then, I created a "bootloader" script that will load the prefabs at runtime (this is because I have many scenes with the same game object setup). As a result, the loading time went up to 20-30 seconds. Additionally, any other instantiations I did during the game caused the game to freeze for ~2-3 seconds!

    Is this expected behavior? It seems to me that whether the game objects were initially in the scene or instantiated when the scene loads, they still have to load in all the object data and call awake on everything. What is causing the huge load time increase when using prefabs?
     
  32. Wozik

    Wozik

    Joined:
    Apr 10, 2009
    Posts:
    662
    most probably this is a bug. At the time we're testing the complex solution that fixes the slow loading times. So if you report a bug on your issue, then I'll be able to check out if we have a solution for it.
     
  33. kromenak

    kromenak

    Joined:
    Feb 9, 2011
    Posts:
    270
    Thanks, I will try submitting a bug report! My issue sounded very similar to this, so just wanted to check.
     
  34. polsen

    polsen

    Joined:
    Nov 2, 2010
    Posts:
    11
    Hi Wozik, any idea on when a fix "might" be released for optimizing prefab/level loading on Android?
     
  35. Falin

    Falin

    Joined:
    Sep 29, 2009
    Posts:
    242
    I'm getting slow loading too but I get a other problem too.
    When i run the game on android it shows the unity splash screen but it doesn't go to the first scene. if I press the home button and start the app(it's still running) it's show the first scene.
    Is there a fix to this?
     
    Last edited: May 6, 2011
  36. hima

    hima

    Joined:
    Oct 1, 2010
    Posts:
    183
    Glad to hear that I'm not alone on this. Though I can wait for the fix, considering we can release for iOS first.
     
  37. Falin

    Falin

    Joined:
    Sep 29, 2009
    Posts:
    242
    ok just for the update. I set every texture lower than the 1024 max size and I have set every texture 16-bit. And instead of it's loading ~1 min it now loads in ~10 seconds.
     
  38. Wozik

    Wozik

    Joined:
    Apr 10, 2009
    Posts:
    662
    We have a beta version with the prefab/scene loading issue solved. It is available for our beta testers at the time.
     
  39. jonbonazza

    jonbonazza

    Joined:
    Nov 6, 2010
    Posts:
    453
    Galaxy S and Nexus S are far from the only android devices with similar specs and speeds to the iPhone.
     
  40. Tysoe

    Tysoe

    Joined:
    Jul 6, 2009
    Posts:
    577
    We are having the same issue with the Galaxy S and other Android phones. Our coder says it isn't actually loading times but in our case, we are porting a windows game with a few shaders including one normal/diffuse texture atlas material in. Currently it seems like the game has crashed and I only found out it hadn't because I put it down one time and went to get a cup of tea.

    Anyway, he's been trying to find whats slowing the loading process down and found that it was the shaders that seem to be compiled at runtime on Unity Android instead of precompiled. So it takes an age compiling shaders before it can finish loading the levels and display them on screen.

    Our game isn't that demanding and runs perfectly well with normal maps and ragdoll but seems to take minutes to load.

    That's about 1/4 of the first level in this screenshot

    If our coder is correct about compiling shaders at runtime causing the slowdown, is there a way to precompile them in Unity?
     
  41. gram

    gram

    Joined:
    May 11, 2011
    Posts:
    5
    When loading files from the Resources directory to an Android device, the speed is very slow if there is a lot of files in the Resources directory.

    In other words when the following conditions coexist,

    *1. used on an Android device
    *2. thousands of files are in the Resources directory
    *3. loading files from the Resources directory

    the speed drops.

    On iOS devices (iPhone, iPad), no speed differentiation occurs.*
    The speed does not change, regardless the amount of files contained in the Resources directory.

    Not only when loading from Resources.Load() function, but also when the files in the Resources directory are registered as component property, the speed drops.

    I'm guessing Android devices, in comparison to iOS, have a less efficient routine of finding files in the Resources directory.

    I already reported on April 19th(Case 402665) and today(Case 403370).
     
    Last edited: May 23, 2011
  42. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Android devices, unlike iOS, rely on a swappable MicroSD to store all these data (even those which claim in their specs to have 8GB internal like Galaxy S II have them and only 0.2 - 2GB real internal space as I had to find out), while iOS has no such thing but only completely inbuilt internal memory (flash) which is lightyears faster than the 5-20mb/s the microsd can offer and as if that wouldn't be worse enough, it seems like a "agreed standard" that the device formats these cards with FAT32 instead of ext2 / ext 3 / ext4 / raiserfs which out of the devices view, are significantly faster.
     
  43. Wozik

    Wozik

    Joined:
    Apr 10, 2009
    Posts:
    662
    Tysoe, shaders compiling in real time is close to the reality if you supply it with the right IF's. But in OGLES1 mode shaders should not require and additional computation when they showup for the first time.

    Anyway, we're having a beta 3 soon, so the release is imminent. Beta testers return mostly positive results and we;re working hard to make them absolutely positive. Also we're looking into even more Android-specific loading optimizations. They may end up in the next release though.

    So please, _do report_ your "slow loading" bugs. We really care and we'll try to fix your very special cases for the next release that is happening soon. Otherwise you'd need to wait for us to discover the corner cases you may be experiencing.

    Thanks
     
  44. Wozik

    Wozik

    Joined:
    Apr 10, 2009
    Posts:
    662
    dreamora, currently I have a project that takes more than 72000ms to load on Motorola Xoom from the internal memory and about 21000ms to load on HTC Desire Z from the external micro sd flash.

    I mean, there's too much to investigate and benchmark before blaming explicitly the memory transfer speed or the particular device or the Unity bugs.

    I can just sum up with same "please report your issues and get them fixed".
     
  45. Wozik

    Wozik

    Joined:
    Apr 10, 2009
    Posts:
    662
    gram, I found your cases on Friday but didn't have a time to look yet. I am working on it. Thanks a lot for your time and efforts.
     
  46. gram

    gram

    Joined:
    May 11, 2011
    Posts:
    5
    dreamora, I don't think so because It's fast enough when the number of files in Resource directory is small.
     
  47. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Oh I definitely don't blame Unity :)
    You guys did a fantastic job in that nightmaric environment :)
    I also own Shiva 3D Advanced which allows me to compare the 3 possible options at the time (unity, shiva, airplay sdk) pretty well and its Unity that ends at the upper end commonly, not the two others.

    I blame it on the "each damn manufacturer F***s up androids potential with own brainless modifications", cause I'm pretty sure its not even Android itself thats causing it but the decisions the device makers do for whatever reasons although they are known to not work out fine (the fat32 is potentially to put the microsd into your pc and grab the data. but that people don't need to do that at all as Kies over Air shows and as basic syncing and harddisk modes on HTCs have always shown and would be much happier with raiserfs / ext4 microsd formating seems to be beyond the logical thinking of some manufacturers). the two best examples of such manufacturer F***ups are the galaxy s on its original firmware where Samsung really has shown how bad it can go and it seems the xoom is using some anti-optimizations on various edges too that got even worse since 3.1

    One can only hope that Googles approach for Android 3 will be applied to android 2.4 too, no public handout anymore only to those manufacturers complying to basic standards, that they no longer allow creators to trash the experience totally so manufacturer stupidity gets blamed back on Android.


    @gram: Unsure. Could be a unity thing (unsure how the VFS works there) but it can just as well point into the direction of FAT32 vs a "not 1990 disk format with bad performance" like the modern linux formats (which the devices to my knowledge use for the internal, its just the SDs they mix up)
     
  48. Rhapsodus

    Rhapsodus

    Joined:
    Aug 31, 2009
    Posts:
    30
    I am getting this problem as well. I am on Unity 3.3.04f and building to an android X (2.2). I am not sure if the previously mentioned fixes are not out yet, but I have a scene where the iphone takes ~10 seconds and the droid takes over a minute to load. The droid scene is just a copied scene from iphone so it is using the same textures materials.

    Are there tricks we can do to alleviate the load hit in the meantime? or will we just have to wait for the next release to get the fix?

    Would signing up for the beta program conflict with the production / pro licenses I already have ? I understand the potential unsupported features/issues that may bring...

    As a side note: I am using LoadLevelAsync on a Coroutine for my loading and I make a call to Resources.UnloadUnusedAssets prior.
     
    Last edited: May 26, 2011
  49. gram

    gram

    Joined:
    May 11, 2011
    Posts:
    5
    Android copies compressed package files as is when installing the app.
    The app unzips the package when it needs access to the file in the package.
    Therefore, without optimization, it inevitably takes a long time to find files.

    Android APIs like AssetManager have this optimization, but through profiling with DDMS I confirmed that Android API is not in use.
    I'm guessing Unity uses a unique function of its own to find and read files, and this is causing the problem.

    Please confirm this.
     
  50. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
    The 3.4 release currently in beta includes fixes and optimizations for various loading related issues; please stay tuned.