Alright, so I am making a procedurally generated, tile-based 2D game. This means I have to have 'chunks' so as to not have the entire (infinite) world in memory at once. Furthermore, I limit the player to a single chunk at (0, 0) and teleport everything 3.2 (chunk size) units backwards when the player crosses the chunk boundary. Thus, floating point errors are avoided. Everything works, but I'm now investigating huge lag-spikes (~ 3/4 s) when I move between chunks.
At this point I have profiled the issue down to calling `chunk.gameObject.transform.Translate`. Now, currently all blocks in a chunk are created with `transform.parent = containingChunk.gameObject.transform`, so I don't have to `Translate` every block independently; it is done automatically. However, I suspect this is what is causing the problem. Why? When I make it so the blocks' parent transforms are set to a static object, everything breaks graphically, of course, but the lag spikes mostly disappear (~ 1/4 s, much more to do but this is my main problem). The blocks are still getting created and destroyed and rendered normally; they are just not translated.
Is there a better option for translating large amounts of `GameObject`s? Or is there something in my overall design that I should change?
↧