- Home /
Do offscreen gameobjects affect performance?
Hey,
I'm creating a 2D, tilebased, top-down game. My map is randomly generated and should be about 1000x1000 tiles. Now my question is: is it okay to instantiate all tiles at the start of the game, or should I only instantiate those tiles that are on the screen?
Thanks in advance
Cheers
Answer by dschneider · Dec 16, 2014 at 07:58 PM
I use SpriteTile for randomly generating my world. I started out with 1024x1024 and as far as I can remember it worked fine. SpriteTile doesn't use meshes, it's heavily optimized for this kind of games. However I populate my world with game objects like palms and stones and that pulls down performance. So I ended up dividing my world into different sectors which are game objects themselves. They contain entities and whenever you are not in a sector, the entities are disabled. The sectors are 256x256 now and that works well with AI controlled enemies, game objects etc.
Answer by robertbu · Oct 10, 2014 at 03:03 PM
1000 x 1000 is 1 million tiles. You are not going to be able to create that number of tiles (or at least I wouldn't be able to on my reasonably high-end desktop system). If the number of tiles visible at one time is small, then you might be able to play some sort of shell game...using a set number of objects and swapping them in and changing their display to represent the 1000 x 1000.
But typically this kind of things for tiles is done by creating each tile as s quad in a mesh. Each mesh can then contain up to 16K of quads. So around 65 game object can represent all 1 million tiles. There is some starter code here if you are interested in this approach:
http://answers.unity3d.com/questions/769358/tile-game-slow-lots-of-sprites-texture-atlas.html
Search Unity Answers for 'voxels' or 'minecraft' for more information representing many game objects using meshes.
Answer by Eric5h5 · Oct 10, 2014 at 04:22 PM
Assuming you could have 1000x1000 objects (spoiler: nope), off-screen objects do affect performance to some extent because they need to be culled every frame to determine whether they should be drawn or not.
Your answer
![](https://koobas.hobune.stream/wayback/20220613164812im_/https://answers.unity.com/themes/thub/images/avi.jpg)