How many instatiates per frame is too much?
Hi! I am prototyping a game, similar to minecraft in its base idea. World cosists of blocks and layers. For now I am using an xml file to simulate database where world will be stored in the future. Wold will be quite large so I'am only loading cubes around the player: one 10x10x5 square in the center and 8 around it, exactly the same size.
So when player moves lets say right and when game detects that he left the center square, all 3 squares on the left are deleted, and game loads 3 new squares from right side. Lets calculate instantiate calls: Most bottom layer (0) is always filled with ground so there are always blocks there, layer 1 is the same. Then layer 3 is around 40% blocks and rest of the layers are empty. This gives us around 720 instantiates when player walks from area to area. For now all I am instantiating are plain boxes, the ones unity can create, with collider, without any scripts attatched to them.
The problem is - if I wont make this process a coroutine and extend it to about 1-2 seconds, there is a huge fps drop (to about 8) which is not acceptable. But if this process takes this long the player can see the world being generated. I tried optimising it already - changed all foreach'es to for's, and replaced Resources.load with public reference to cube prefab. But it still glitches. What am I doing wrong?
Your answer
Follow this Question
Related Questions
Using constructors in Unity (C#) 8 Answers
Performance of instantiate and destroy for bullets 2 Answers
Instantiate objects around a sphere 2 Answers
More problems with arrow shooting 0 Answers
Instantiation of my GameObjects spell (from other script) 0 Answers