Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Optimize scene load time

Discussion in 'Scripting' started by Xuzon, Aug 7, 2016.

  1. Xuzon

    Xuzon

    Joined:
    Mar 21, 2014
    Posts:
    83
    Hello!

    My team and I have just created our first complex map and we are having troubles with optimization.

    The artist made the map in a modullar way, I think too much modullar because the map is composed at least by 2k objects.

    In the editor the load time of that scene from the main menu is short (around 3s) but in a build the scene load time is about 40s !! it is unacceptable for a multiplayer online game with short matches.

    so, I think the artist have to make the map in another way because the 2k objects is increasing the scene load time a lot and dropping the FPS.

    Is that the way? or may I can do something to reduce that time as a programmer?

    Thanks!!
     
  2. Gametyme

    Gametyme

    Joined:
    May 7, 2014
    Posts:
    618
    There's a way to combine mesh through script.
     
  3. image28

    image28

    Joined:
    Jul 17, 2013
    Posts:
    457
    Don't think the number of gameobjects in the scene is the issue. I have 10k gameobjects in our game and load time is around 10 seconds on android
     
  4. Xuzon

    Xuzon

    Joined:
    Mar 21, 2014
    Posts:
    83
    And what could be? because it is not normal, in the editor it goes fast as hell but in the build :/ I don't know what happens
     
    dccoo likes this.
  5. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,631
    Well, what else do you have on the scene?
     
  6. Xuzon

    Xuzon

    Joined:
    Mar 21, 2014
    Posts:
    83
    That 2k more or less modular objectss (all have a renderer) and lights, I disabled all but the walls and duplicated all the walls like 5 times to reach the number of all objects and it is lasting more or less like before (3~4s in editor 40~s in build)
     
  7. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,631
    Textures? Music? Sounds? Any plugins? Shaders?
     
  8. jimroberts

    jimroberts

    Joined:
    Sep 4, 2014
    Posts:
    560
    You need to provide more information on what type of objects are in your scene, how many vertices are used by the all the meshes, and any code that might be using reflection or loops inside any of the functions Unity calls.
     
  9. Xuzon

    Xuzon

    Joined:
    Mar 21, 2014
    Posts:
    83
    Thanks for your answers, I'll take a closer look but there is only one background sound, no plugins and the common PBR shader, in textures we use 4K and 2K textures.
    There are 3 reflection probes in the scene but they are not active.
    There isn't any code in the scene, is only a map where I spawn the players that in other map works perfect and fast.
    How do you check how many vertices are used in a unityScene?
     
  10. jimroberts

    jimroberts

    Joined:
    Sep 4, 2014
    Posts:
    560
    I believe you can click and enable the "Stats" button when using the "Game" view in the Unity editor. It will display the total number of "Tris"(triangles) and "Verts"(vertices) if you zoom the camera out to encompass the entire scene. My guess is an over abundance of 4K and 2K textures if there are no scripts in the scene. It would also be helpful if you provide a picture of the scene view, the number of textures, the total file size of the client folder after building, the target build platform, the specs of the system you're running the build on, and the current version of Unity3D that you are using.
     
  11. image28

    image28

    Joined:
    Jul 17, 2013
    Posts:
    457
    The Frame Debugger in the window menu may help too. Also the profiler
     
  12. Xuzon

    Xuzon

    Joined:
    Mar 21, 2014
    Posts:
    83
    Ok, here is the Stats view if I align a camera in a view where I can see all the scene


    but when I'm playing looks like this


    I don't understand anything It is supposed that our artist used low poly :/ and the player is inside a room so... I don't know how unity is rendering 11.1M tris, he is in a room not seeing all the map, I suppose that unity doesn't use oclussion culling and frustum culling automatically right?

    EDIT: I have 1970 Gameobjects (counted them by script) and our wall modules for example Have 86 verts, I don't know how is rendering 15M verts because that means 7.614 verts per Object in average :/.

    I've counted the number of vertex by script of all gameobjects and the is 1.7M vertex (counting all the gameobjects.sharedMesh.vertexCount), I don't know how Unity reach the 15M.

    I know now what happens, if I deactivate the lights It goes down to 1.7M vertex but with lights it raise to 15M
     
    Last edited: Aug 12, 2016
  13. jimroberts

    jimroberts

    Joined:
    Sep 4, 2014
    Posts:
    560
    Unity automatically culls objects that are not in view. I wanted the total vertex count to see how many vertices you are trying to load at run time. Please provide the rest of the information I requested.
     
    Last edited: Aug 13, 2016
  14. image28

    image28

    Joined:
    Jul 17, 2013
    Posts:
    457
    It would be lighting and shader passes, multiple passes in a shader multiplies the vertex count.
     
    BhaktiGhodasra likes this.
  15. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    9000 batches. ouch.

    I thought my 2000 were bad.
     
    dclmrl and Er_ellison like this.
  16. image28

    image28

    Joined:
    Jul 17, 2013
    Posts:
    457
    Working on mobile I thought 200 was bad :)
     
  17. image28

    image28

    Joined:
    Jul 17, 2013
    Posts:
    457
    Unity 5.4's new deep memory debugger in the profiler can tell you exactly what is being loaded into memory and how much memory it is taking. Should be able to work out problem area's from there
     
  18. image28

    image28

    Joined:
    Jul 17, 2013
    Posts:
    457
    I had an issue with thing's being loaded into memory that didn't need to be in the build at all. Fixed the issue by tagging them OnlyInEditor before doing a build
     
  19. amzin7000

    amzin7000

    Joined:
    Nov 16, 2014
    Posts:
    48
    To improve my loading times, when my level is saved in the editor, a script removes all meshes and meshrenderers and saves the meshes and the gameobject's name to a serializableDictionary in a ScriptableObject.
    When I load my game, I use a mesh combiner to combine all the meshes stored in the dictionary, using the gameobjects transform scales rotations and positions. Also to prevent any objects from popping up, I have my camera fade in to the level.

    I should add that my game is 2d, and that you might not want to do this if you want to combine every mesh together if you plan to use occlusion culling. You could combine small portions of meshes that are in the same place
     
    Last edited: Aug 18, 2016
  20. lloydsummers

    lloydsummers

    Joined:
    May 17, 2013
    Posts:
    350
    Modular scenes are a GOOD thing. You actually, on big projects, don't want to have 10 million tri's combined to a single object. This will prevent you from taking advantage of occlusion culling although it will benefit your draw calls (batches).

    There are a bunch of ways to optimize this, and as mentioned above, some issues you need to consider. Generally speaking, breaking your level up into smaller chunks and bringing them in through LoadLevelAdditiveAsync is a good way to go for faster loading.

    Another important step, is LOD.

    Then you can load say, only a Cube first (think : immediate load) then lazy load the rest of the scene in at a reduced LOD (think reduced simplified meshes) and let the system up the mesh count slowly. You can also use this to take advantage of GI and light baking, so it doesn't have to rebake the entire background level for example, if you are re-using it through 50 scenes.

    That said, the second issue you are going to run into quickly is your FPS. Generally speaking, you want to aim for around 1.5 million tri's and 2,500 batches at most on desktop (this is where I've found the sweet spot to be on VR anyway). Vive excluded, it has some bad SteamVR stuff that needs to be optimized in their camera loops if you want to push that much to their minimum spec systems (nested, iterative, GetComponent calls per frame, just bad design - but I digress).
     
  21. Xuzon

    Xuzon

    Joined:
    Mar 21, 2014
    Posts:
    83
    Thanks for all your replies, I've been in a place without internet so I couldn't connect to the forums.

    Our performance problem (FPS drops) is because not using oclusion culling so it will render all the vertex of the scene in some views (1.7M but with lights almost 15M even using the standard shader).

    The loading time is weird, in the editor loads almost inmediatly ~3s but in build is 52s, too much time, does anybody know why this is happening?

    We are talking to make the map less modullar because 2k objects to make a small map is a nonsense (each tile is a gameobject), they event have spaces so we are changing all this.

    My system is a msi laptop GE60
    CPU: Intel core i7 4200HQ
    GPU: Nvidia GTX 860M
    RAM: 12 GB DDR3 1600MHz

    Our final build weights 1.88 GB but we have 6 weapons with 4K textures and their audio, 2 Player models with 4k textures and another map with an 8K texture, when I say textures I mean diffuse map, normal map and metallic map.


    Here is a screenshot of the memory profiler, the peaks of the right is where I load the scene in the editor.

     
  22. EETechnology

    EETechnology

    Joined:
    Aug 15, 2015
    Posts:
    185
    One question, what code do you use to load scene?
     
  23. Xuzon

    Xuzon

    Joined:
    Mar 21, 2014
    Posts:
    83
    Is a multiplayer game, I'm testing with the LAN so I derived a class of networkDiscovery (as it says in the manual) and called startAsHost() who calls LoadSceneAsync If I'm not wrong
     
  24. kru

    kru

    Joined:
    Jan 19, 2013
    Posts:
    452
    Yes, as should be apparent. In the editor, your meshes and textures are already in memory. Unity doesn't have to read them from the disk again when you enter play mode. In a build, you have to load the meshes and textures from scratch.

    I bet that the first time you open the scene or enter play mode in the editor, it takes about the same amount of time as loading into a build.

    I'd suggest loading as many of your levels meshes and materials during your intro sequence (intro movies & main menu). Then the actual level loading can be snappier. Additionally, as someone else mentioned, break your big scene into several smaller ones and load them additively in an order that makes sense. eg, if you start in a small room, only load up that room and its neighbors, then slowly load in the surrounding area until the whole scene is in. Breaking your big levels up in to smaller scenes, then loading and unloading them selectively as the user moves around, is the standard way to get high poly scenes onto the screen with reasonable load times.
     
  25. Xuzon

    Xuzon

    Joined:
    Mar 21, 2014
    Posts:
    83
    I supposed that difference was because of that, and yes, the first time I open the scene in the editor it takes time, I think not that much but more or less.

    How can I load the materials and meshes through main menu and movies? Resources.Load()? but what Should I do with that Object?
     
  26. image28

    image28

    Joined:
    Jul 17, 2013
    Posts:
    457
    In the Memory profiler change simple to detailed and click take sample, can take a long time but shows exact memory usage of each gameobject.

     
  27. image28

    image28

    Joined:
    Jul 17, 2013
    Posts:
    457
    Also you have a lot of GC Alloc... you code could use some optimization
     
  28. EETechnology

    EETechnology

    Joined:
    Aug 15, 2015
    Posts:
    185
    Right there! For some reason, the function LoadAsync its causing that time to be so long. It has happened to me before and switching back to Application.LoadLevel(), made it work a LOT faster, in like 3 seconds! I hope that helps!
     
    Er_ellison likes this.
  29. Xuzon

    Xuzon

    Joined:
    Mar 21, 2014
    Posts:
    83
    In the memory profiler it looks like the textures have a lot of memory usage:




    And also Other -> Objects



    And it seems that the GC Allocation is in that map because I set a map (with the same player but different map only) and I have around 170 GC per frame with a few peaks to 1400
     
    Alvarezmd90 likes this.
  30. Xuzon

    Xuzon

    Joined:
    Mar 21, 2014
    Posts:
    83
    Seriously? I'll take a look

    Edit: I took a look with SceneManager.LoadScene because Application.LoadLevel is obsolete but the result is the same, around 50s of loading time
     
    Last edited: Aug 23, 2016
  31. image28

    image28

    Joined:
    Jul 17, 2013
    Posts:
    457
    Maybe Find out the problem texture and adjust the compression settings, also you have 300mb of Lightmap data which seems rather large, is it a enormous level or something
     
  32. Xuzon

    Xuzon

    Joined:
    Mar 21, 2014
    Posts:
    83
    Nope, is not enormous, it is like two floors of a building but the 2k objects I think have something to do with that lightmap data
     
  33. image28

    image28

    Joined:
    Jul 17, 2013
    Posts:
    457
    Maybe compare your lightmap and texture settings on the map to you other map settings.... We have a large scene with thousands of objects and our lightmap data is only 5mb
     
  34. Xuzon

    Xuzon

    Joined:
    Mar 21, 2014
    Posts:
    83
    And where can I change the settings of my lightmap? in the lightning window?
     
    AcidArrow likes this.
  35. image28

    image28

    Joined:
    Jul 17, 2013
    Posts:
    457
    In the lightmap windows and you can also adjust the texture settings of the baked lightmap that is generated.
     
  36. Mark-Davis

    Mark-Davis

    Joined:
    Jun 21, 2011
    Posts:
    156
    Looks like I'm a little late to this discussion, but in case this helps anyone else.... if you're using more than a few Substances in your project, you may want to prebake or at least cache them as opposed to building on level load each and every time. You may notice a difference.

    upload_2017-1-17_17-34-20.png
     
  37. Xuzon

    Xuzon

    Joined:
    Mar 21, 2014
    Posts:
    83
    We don't use any substance in this moment, We deleted that level, it was usable in that moment but hey, thanks for the info XD
     
  38. Meri

    Meri

    Joined:
    May 25, 2013
    Posts:
    14
    Browsing through comments - am I the only one concerned by your scene having 11M triangles? This is a huge amount and way beyond what should game have o.o
     
    Er_ellison likes this.
  39. Xuzon

    Xuzon

    Joined:
    Mar 21, 2014
    Posts:
    83
    It was the lightning, too many lights in forward rendering cause that much triangles, I would use occlusion if I have to set it again
     
  40. hodge47

    hodge47

    Joined:
    Apr 14, 2014
    Posts:
    25
    Had 20+ substances in my scene and didn't realize that they were the scene loading problem. Didn't even know you could prebake them. Went from 20+ min load times down to a few seconds, so thank you so much!
     
  41. juliochernandezh

    juliochernandezh

    Joined:
    Oct 9, 2017
    Posts:
    1
    hi i had the same problem and i quit mesh collider of all (obj), and the run better, you can try.
     
  42. McDev02

    McDev02

    Joined:
    Nov 22, 2010
    Posts:
    664
    Maybe make a copy of your scene (and GI data) and try to remove stuff, starting with the baked lighting. Once you get a loading boost you know that that thing caused the loading time and you can start optimizing.

    But when I see >1GB of Textures, that is not just loaded in in a fraction of time. Of course the editor already has that data loaded so I bet this has a big influence. So one solution is to use AssetBundles and load that textures e.g. the first time the player starts a match and before you load the level. Or will Unity even keep those Textures in memory if you unload the scene? I think not but I don't know for sure.

    Probably not hte case: Are you sure that it is the loading of the scene or maybe also caused by Awake() and Start() mehtods? But that should then also be happening in the Editor.
     
    Last edited: Nov 22, 2017
  43. Er_ellison

    Er_ellison

    Joined:
    Jul 8, 2017
    Posts:
    10
    hi there , looks like i'm little bit late to the party but , same here
    i had about 40 ~ 45 seconds of load scene and i'm just reduced that to less than 25 seconds on android build by removing the songs from game but now by taking samples of memory in profiler i faced with this :
    Untitled-1.png
    so the textures 2d is way far off the bounds , but when i expand it iface with this :
    Untitled-2.png
    what the hell is going on???
    what are those unnamed hidden files ???
     
    Last edited: Feb 24, 2018
  44. Bratveja

    Bratveja

    Joined:
    Mar 11, 2015
    Posts:
    29
    If you were in front of me i would kiss you man! I have 2 days to finish my project and everything is ready besides the 2 mins loading time! After doing this it went to 9 secs... By the way if someone reading this and trying it, you should reimport the substance material. Will save you headache later!
     
  45. BhaktiGhodasra

    BhaktiGhodasra

    Joined:
    Mar 19, 2018
    Posts:
    1
    Even 70 to 80 plus start producing lags for 3d games I always try to make them lower to 30 to 70 always.