how can i create a terrain with a procedural function without freeze.

i created a procedural function which create a terrain reading a file , the problem is when the terrain is spawning , the game freeze 2 o 3 seconds, i try use a thread but the game stop because only the game thread can spawn actor.

how i can improve the time for when the terrain is created not freeze the game?

thank you!.

  1. optimize your generation processes
  2. generate small chuncks/pieces by timer/tick

For example, see how the map is generated in Factorio when creating the world