Couroutines and Threading for Procedural Generation

So I’m making this procedural level generator which can take quite a lot of time to run. Therefore I am thinking it should be put into a coroutine or thread to not freeze the game. However the algorithm in question uses things like Find() and .transform to determine parts of the generation. This creates two problems

  1. If I use the coroutine, the game still freezes upon starting.

  2. If I use another thread, I cannot use the .transform or Find() functions/objects etc.

What is the recommended solution for this problem? What am I doing wrong?

Maybe you could try Thread Ninja

First you should profile your code and see if the slowest parts have nothing to do with Unity API, if that’s the case, you should benefit from multithreading.