Having 5k+ gameobject

I’m making a basic tile fog but I’m having a huge problem, i need about 5k of those plane (scale to .5) to cover my entire level. it doesn’t lag on my pc but it do lag on android, the tiling and revealing are all done, i make a mistake in not thinking ahead, what is the best way to make fog that I can save and load? and does unity renderer object that are not seen in the main camera?

A gameobject is an entity in your game - it has its own name, location, position, rotation. It can have relationships to other game objects. It can be cloned and destroyed. The very fact that a gameobject exists in your scene means that memory and CPU resources are required by that object - whether it is being rendered or not. It is very unlikely that you ever want to have 5,000 gameobjects. But it is unclear exactly what the solution is without understanding more about your game: why do you need to “save and load” fog? Does fog have a material effect on the mechanics of the game rather than just aesthetic?

  • A fog effect is fairly trivial to create using shaders or image effects. In fact, Unity comes supplied with several models of in-built fog. Particles are another alternative. However, it’s tricky to change or “save” the state of fog created like this - it’s just a visual effect.
  • If you want a custom fog plane, you can define a dynamic mesh to which you alter vertices and triangles in runtime. It’ll be much faster than having several gameobjects. You could serialise the state of the mesh at any time to save and restore it, but it would probably take more work up front to get working.

This is an issue to be addressed by shaders, to have few, “fog” objects.

However, I think it’s possible to be solved in a dirty way with particle systems. You could simulate what you currently have with fairly large-sized particles, and correct fog textures. Just make sure their movement is zero and that they always face camera.
Particle systems are much cheaper than having such a huge number of items. Each one can be passed to GPU in 1 draw call, + you will have a significantly smaller number of such items.

Each object has an axis-aligned bounding box, which envelops the entire object. As soon as all of the box goes off screen, the object is not drawn by the GPU.