How to optimize a large number of game objects

My framerate goes down to 20 fps after my game’s world creation, so I need to optimize it. Any suggestions are appreciated. I will now give a description of what I did so you know what optimizations are appropriate. My game is a grid-based city building game. The world consists of 9 different biomes (but no height variation, the world is completely flat), and I need to be able to interact with them separately because these biomes affect building efficiency. Therefore, each grid spot is currently a separate tile. I did not use tilemaps because I do not know how I would be able to get this sort of functionality with them, so each tile is currently a separate GameObject with separate colliders (but no physics module). Currently, I have a 100 X 100 tile map, for 10,000 total GameObjects. I would like my maps to be at least 250 x 250 tiles, but that just freezes Unity altogether to the point where I have no choice but to use task manager to forcefully close it. And there will be more game object later, as this game is still very early in development. The tiles only have a basic collider and an attached material for now, but later I will need to add 3D models to make them look more like the biomes they are meant to represent.

I am open to suggestions that either optimize the game objects themselves, or that reduce the number of GameObjects (as long as it doesn’t decrease the quality of the world generation). If needed, I could use the two heightmaps generated by my world generation algorithm to create a 2 dimensional array representing the biome tiles before disposing of those hieghtmaps, rather than relying on the tiles themselves to determine the biome, if there is some way to turn the ground into a single GameObject after the random generation.

If you haven’t seen it yet I recommend watching this talk on the practical optimization of code by Jason Booth:

Practical Optimizations - Jason Booth

1 Like

Code isn’t my problem. The world generation algorithm itself is actually very fast at generating the terrain. it’s the shear number of GameObjects that is the problem. I’ll still look at it because it will probably help later when I have to do more complicated coding stuff, but I don’t know if it will have anything that will help with my specific problem.

Have you looked into a technique called “Prefabs without Game Objects”? It’s a way of doing more of the processing on the GPU and freeing up the CPU.
Prefabs are put into your scene, but without instantiating game objects.
There is an asset on the Unity Asset Store called “GPU Instancer”, people seem to have mixed results with it, but I know that it does provide a way of doing “Prefabs without Game Objects”. I expect that there are others ways to take the same approach.
I’m no expert, so I can’t really comment more than this; the approach seems to fit your brief, from what I understand.

i have same problem too
so i start to search and i am here
but my problem wasn’t a real problem
it is a mistake in coddling and i found it
in fact when i reloading the level i forgotten to destroy gameobjects and each time player fails game objects became more and more in count and device start to behave abnormal.
but i think that what if we really need so much game objects…

about your problem. if it can be done in case of your project. i think you can do like this
you can have your universe and the operands only in calculations but realize them only in the field of view