Blockchain Terrain Generation #8 - Multi-threading

With the addition of mining and placing blocks, I encountered a problem. Every time there was a change made to the mesh, it would have to make large calculations to calculate the lighting and the block faces that can be seen. This would cause a lag spike that would change based on how large the calculation was. Leaving this in the project would make it frustrating for a player to play so I had to look for solutions.


This is an image from the Profile that shows when a block was mined that it would have a large lag spike and therefore pause the game during that time.


Adding multi-threading into my project would mean that I could assign large calculations away from the main Unity thread so they would happen in the background, instead of making the player movement and other scripts that require and handle user input to wait while the calculations are made.


I started by researching the Unity Jobs system which automatically handles and integrates multi-threading but I eventually realised I would have to re-structure and essentially recode my entire project.


I instead decided to try to add the multi-threading myself using "System.Threading". I did this, there were still parts of the code I had to re-structure, but it could be kept more like the code is without the implementation which is better for my project.




8 views0 comments