Search code examples
performanceunity-game-enginescrollablegameobject

Does adding many game GameObjects in scene (not rendered) inefficient for performance? [Unity]


I'm using Unity 4.6 to develop a 2D game. I want to know if having a lot of GameObjects in the scene (out of the camera's sight) has a considerable influence on performance. For example, is it efficient to make an scrollable list of names (like 1000 of them)? (each one is a GameObject and has a text, a button etc.) I mask them in a specified area (for example 10 of them are visible at the same time).

Thanks in advance!


Solution

  • Depends on whether or not the objects have visible components. If they do, the engine will draw them even if they are 'off-camera'. A game object by itself has a pretty light load - a tile based game could have thousands in memory. You'll want to toggle the visibility of sprites if you plan on drawing a large number to the scene off-camera. This is where a SpriteManager comes in. It'll check to see if the sprite is in the camera's rectangle and disabled sprites that aren't. There is a semi-offical exmaple here that is good if a little complicated:

    http://wiki.unity3d.com/index.php?title=SpriteManager