- Home /
Why are my 2d sprites so slow to set up?
My 2D game has tiles and layers. It creates one game object per tile, anywhere from 100 to 10,000. To create 3,000 game objects takes 68 msec, which is just fine.
But setting up the sprite and location takes 5,000 msec, or nearly 2 msec per sprite. This is a problem. Here is the code for setting up each tile.
var sprite = _main.GetSprite(LevelIndex); // pre-computed table of sprites
_renderer.sprite = sprite; // the sprite renderer for the tile
if (sprite != null) {
var cursize = _renderer.sprite.bounds.size;
var scale = Math.Max(Size.x / cursize.x, Size.y / cursize.y);
transform.localScale = new Vector3(scale, scale, 0);
}
How can that code take 2 msec? What's going on?
The sprite size is 80x80. Is this a problem?
Once it's all set up it renders at 100 fps easily. So why is the setup so slow, and what can I do about it?
Your answer
Follow this Question
Related Questions
Change a prefab's sprite in all scenes? 2 Answers
A little question about sprites and RAM on a specific device?? 1 Answer
Unity 2D level editor performance 1 Answer
What's an effective method for activating and deactivating gameobjects not visible to the camera? 3 Answers
Unity mobile 2D best practices 0 Answers