How to optimise 5000 sprites?
In the scene I spawn 5000 sprites (I'm creating drill game). But the framerate on my laptop (Nvidia Geforce 960M, 16GB, Intel Core i7 - 4 cores) is 0.9 fps. How to optimize them? Sprite Packer doesn't fix this problem.
If you have a problem with spawning them, have a look at Object Pooling. Now for your actual problem: If you $$anonymous$$UST use sprites in your game and no other solution, a general advice would be to $$anonymous$$imize the amount of calculations done on those sprites. Low quality images and no use of physics could help, as well as optimizing scripts that perform actions on them - especially loops like Update().
Answer by ShadyProductions · Dec 27, 2017 at 02:36 PM
Instead of making several gameobjects make chunks of mesh https://forum.unity.com/threads/tutorial-procedural-meshes-and-voxel-terrain-c.198651/
And this is bad way, because i need to store some information in blocks
It's not a bad way, this is how it's done. You make an object like:
public class Block {
public int Info;
public bool Info2;
// keep info variables you need to access
}
then usually you make a grid like
Block[,] grid = new Block[5,5]; //multidimensional so x, y dimension
for (int x=0; x < 5; x++) {
for (int y=0; y < 5; y++) {
grid[x,y] = new Block(); //instance a new block
grid[x,y].Info = 5;
grid[x,y].Info2 = true; // set info etc
}
}
It would be accurately displayed as:
X X X X X
X X X X X
X X X X X
X X X X X
X X X X X
Then to later delete blocks you simply change the block data in the array at that x,y coord u want to some kind of air block (empty) and call a render update on the grid.
There is no simpeler way I'm afraid. If you want to go over 500+ gameobjects and have performance you will have to do it like this.