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

Memory issues in big city

Discussion in 'Editor & General Support' started by Artur7, Dec 28, 2017.

  1. Artur7

    Artur7

    Joined:
    Nov 30, 2015
    Posts:
    34
    Hello.
    I have difficult problem.
    I am creating free roam game on iOS in the city.
    I created 20-30 buildings prefabs, and duplicated them many times (about 2000). As far as I know, in Profiler's Memory Tab, when I look onto "Meshes", it should show that 20-30 count (because each prefab uses one mesh - prefabs are duplicated, but they still use same mesh). But instead, that stat in Profiler shows me that 2000 Meshes, which takes more than 500MB of Memory, which kills my app on iOS ;/

    Can you tell me is there a way to reduce that number of used memory?
     
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,589
    Are these GameObjects marked as Static by any chance? From past experience, GameObject's marked with "Static Batching" consume quite a lot of memory.
     
  3. Artur7

    Artur7

    Joined:
    Nov 30, 2015
    Posts:
    34
    Yes, they are Occluder, Occludee, Batching, Navigation and Reflection Probe Static.
     
  4. Artur7

    Artur7

    Joined:
    Nov 30, 2015
    Posts:
    34
    I removed Static Batching from all of them, it only gave me about 50MB of memory ;/
     
  5. kenlem

    kenlem

    Joined:
    Oct 16, 2008
    Posts:
    1,630
    You're trying to do too much for the target platform. You can't just naively throw 2000 objects out and expect a phone to be able to handle it. There are going to be limits. You have to find some way to do less work. Make your world smaller or find a way load and unload the parts of the world the player is in. There are various things on the asset store that can help. See Sectr Stream and World Streamer.
     
  6. Artur7

    Artur7

    Joined:
    Nov 30, 2015
    Posts:
    34
    Ok, but shouldn't the prefabs work like I described? Why duplicating one prefabs multiple times takes so much mesh memory? Isn't the prefab mechanism created exactly to prevent that?
     
  7. kenlem

    kenlem

    Joined:
    Oct 16, 2008
    Posts:
    1,630
    Prefabs are going to save SOME memory but all those prefabs instances still have to be in memory and more importantly drawn. Also, you don't say how you're lighting the scene either so you're probably not doing that efficiently.

    Unity is a great tool for mobile game development but it's not magic. You'll need to learn more about Unity, the target platform and optimization if you want to be able to do an open world game on a phone.
     
  8. Artur7

    Artur7

    Joined:
    Nov 30, 2015
    Posts:
    34
    About lighting - I disabled all real-time lights, I only have Baked lighting. So it shouldn't take too much resources.
    Thanks for those two packages you mentioned - I will definitely try them and see if it helps. Can you recommend which one from those two is better in your opinion?
     
  9. kenlem

    kenlem

    Joined:
    Oct 16, 2008
    Posts:
    1,630
    > So it shouldn't take too much resources.

    You can't take that for granted. You might have lots of very large light maps which can take lots of memory.