• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Saad_Khawaja · Aug 08, 2016 at 10:51 AM · buildingmemory managementcity

Large City (Mobile) Memory Optimization Idea

Hi

I'm working on a city building game for mobile (iPhone 5S min) that is similar to Age of Empires (the PC version). The terrain is already present (it is a large terrain - 3500x2000) and the user can place around 100 different buildings in there.

I'm estimating the terrain will be able to have approximately 1000 buildings, a few dozen ships and 300-400 people which causes a memory havoc.

What is the best way to optimize performance in a way that doesn't cause memory issues. I was thinking of destroying buildings/people that were not visible in the camera view and then instantiating as the user is moving the camera. This could be CPU intensive and might cause lag.

Any help will be greatly appreciated.

P.S - I have already optimized the rendering aspect with low poly assets, one texture etc.

Comment
Add comment · Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image YoungDeveloper · Aug 08, 2016 at 12:12 PM 0
Share

Destroying and re-instantiating objects is a horrible idea.

avatar image Saad_Khawaja YoungDeveloper · Aug 08, 2016 at 12:30 PM 0
Share

I agree. Any other ideas?

avatar image damagefilter · Aug 08, 2016 at 12:53 PM 0
Share

Divide the map into a virtual grid of X by Y units. (lets say 128x128 units for instance) $$anonymous$$eep data for all tiles in the view frustum + some radius around it in memory, destroy the rest and load if these tiles fall into the radius of the view frustum.

Put loading in a coroutine to avoid lags. It might cause some popping objects here and there but I suppose it can be countered the one way or the other.

That's a general idea but it's probably not that easy. If stuff isn't in memory it can't be simulated (people going after their tasks for instance).

Perhaps it will suffice to toggle the graphical components on or off.

avatar image Saad_Khawaja damagefilter · Aug 08, 2016 at 12:59 PM 0
Share

Thank you for the reply.

Yes this is what I plan on doing. Adding it into coroutine seems like a good trick to avoid lag. For the people, most of these will be cosmetic (only there to fill up). I won't remove the workers that have to do tasks.

Do you think removing complete building objects using "Destroy/Instantiate" in this case will be fine?

Also, on a side note, how much memory should such a game consume on iPhone 6 that can be handled by the phone?

avatar image damagefilter Saad_Khawaja · Aug 08, 2016 at 01:11 PM 0
Share

If you have absolutely no other solution for this, sure it will do.

But then, with the idea of limiting visible stuff - you'll probably not have all the 1000 objects on screen at once so ins$$anonymous$$d of destroying these, put them in a pool (or one pool each object type) and enable/disable them and adjust positions accordingly.

Like, make a pool of 200 something buildings. Define (in one way or the other) positions in space where houses can be placed.

Take houses out of the pool and place them at the pre-defined coords if they fall into the visible area as defined above. Put them back into the pool if they leave the visible area. That keeps a constant memory footprint and avoids lag of instantiating things during runtime.

You'll have to determine / remember the places where buildings are separately. But a list of Vector3 instances is not such a big memory hog, after all.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Anton-Korhonen · Aug 08, 2016 at 03:02 PM

Using an occlusion culling system could boost the performance of the game greatly. Occlusion culling deactivates the gameobjects that are not visible to the camera.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Saad_Khawaja · Aug 08, 2016 at 03:05 PM 0
Share

Occlusion Culling helps in reducing rendering over head - I'm not sure there is any benefit to reduce memory usage?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

53 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Isometric City Building Game 0 Answers

How to make a grid and able to place buildings on? 0 Answers

Why can't I build Web Player in Unity while I have no problems with building standalone versions? 2 Answers

Destroy last object in generic.list 1 Answer

Help with building a city on a mountain? 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges