How to generate mesh efficiently on mobile?

I created a Minecraft type game in unity which creates and destroys chunks as the player moves through the world. The world is infinite and uses a noisefield to generate random world based on a seed value. Each time a chunk is generated I calculate it a mesh. It runs great on my Mac and I would like to create the same game for mobile however on my iphone the chunk generation is extremely slow and causes lots of lag. I have experimented with reusing the chunk prefabs and changing their mesh instead of destroying them but it seems to be actually changing the mesh and loading into the scene that is causing slow down. How would I prevent this. I don’t mind it taking a few seconds at the start of the game to load but during game play the game freezes every time a chunk is loaded and this spoils the experience. Although Minecraft Pocket Edition (Does anyone know how chunk generation in this works? ) and many of the other Minecraft like games in the app store support infinite worlds, a fixed size world would suit my game fine. Is there any way to generate chunks in the background or in advance that won’t slow down game play? Any help with this is appreciated as I have been struggling for weeks trying to find a solution.

Do you already create the mesh arrays in a seperate thread? If not that would be the best way to start optimising. You have to do the actual mesh creation ( new Mesh() ) and the assigning of the arrays (vertices, triangles, normals, …) in the main thread, but anything else could be done in a seperate thread.

For multithreading in Unity you should take a look at the “Loom” class and this article in general. The source of the Loom class is hidden behind the “Full Source” link button at the bottom. This class allows you to easily schedule tasks on a seperate thread and allow the thread on the other hand to schedule a task on the main thread.