- Home /
Start another thread for a function
Hello,
I have some big calculations to do and want the game continue to run while this calculations (generating a terrain) are running. How can I do that in c#?
@Fattie - it's not made to Asset Store yet :S It's just here: http://unitygems.com/threads/
Ahhhhhhhhhhh! @whydo ... that clears things up:
https://www.assetstore.unity3d.com/#/content/7285
"I just stumbled on this,
http://www.youtube.com/watch?v=k$$anonymous$$0$$anonymous$$ubh0CWA
a package called Loom by $$anonymous$$ichiel Frankfort. His demo is great!"
namespace confusion, heh !
also @whydo unrelatedly ...
http://answers.unity3d.com/questions/452773/how-to-use-yield-within-a-class-function.html
the whole world awaits your discussion there :-)
Ah yeah, $$anonymous$$e this time :) Well I guess the name is obvious... :S
Answer by Mortoc · May 09, 2013 at 01:41 AM
You can use the normal C# System.Threading library. Here's the official MSDN tutorial: http://msdn.microsoft.com/en-us/library/aa645740(v=vs.71).aspx
Just be careful not to call any Unity API functions from anything other than the main thread. Some basic data types are safe (Vector3, Color, etc), but don't call anything on GameObjects or Components.
Well but I have to create a Game Object :/ I already heard of that method but heard its not safe to use :/
Yes, you won't be able to do anything multithreaded that accesses a game object. I suggest you do your calculations off-main and then just apply to the gameobject on the main thread when you're done (coroutines are helpful for that)
Yeah I figured out and whydoidoit told me that already. $$anonymous$$akes it a little hard to change the whole code ~_~
Your answer
Follow this Question
Related Questions
ExportTerrain doesn't work 1 Answer
Procedurally generating terrain? 0 Answers
Get Height of Terrain in Script 1 Answer
Terrain Painting Script 0 Answers
Terrain Shading 1 Answer