- Home /
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?
Just to be clear. Coroutines are not running besides the Unity main thread. They claim the main thread until they yield like any other Unity $$anonymous$$ethod. Perhaps you already know this but it is not clear in your post.
Answer by Ran-Quan · Mar 24, 2017 at 02:07 AM
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.
Your answer
Follow this Question
Related Questions
Return value from coroutine to non monobehaviour 1 Answer
What's the best way to structure a recursive long running algorithm? 1 Answer
Unity3D and C# - Coroutines vs threading 4 Answers
Thread ending prematurely? 2 Answers
Multi threading problem ! 2 Answers