- Home /
Smooth for loop? (for generating games like terarria and minecraft)
I am doing a terarria like game and to make the generation happen I use 2 for loops. One for x and one y generation. However, every time it generates there is a clear lag.
In games like minecraft and terraria they have a loading bar that causes almost no lag...
How can I achieve that in unity?
Answer by hexagonius · Dec 13, 2017 at 06:35 PM
You will have to do this on a seperate thread. That's not a feature that's Unity related though, it's C# based. There's plenty of resources you can dig also with examples related to Unity.
What basically happens is that Unity's main thread stalls for the time it takes to generate your data. Doing this on a seperate thread will calculate this in parallel so Unity can continue. The threaded task does not have a finished percentage on its own though, You'd need to split your working tasks yourself, count the whole iteration loop and update some variable every now and then to know when you're finished.
Be aware that you mustn't use any Unity API except for basic data types, structs and custom classes (think that's about that).
Your answer
Follow this Question
Related Questions
2D Infinite Runner questions 3 Answers
2D Platform Generation: Spawning Platforms Consecutively 3 Answers
Generate minecraft alike terrain 0 Answers
2D Dynamic map generation 1 Answer
2D terrain texturing with submeshes? 0 Answers