If this question does not belong here, feel free to redirect me anywhere else
Let me explain briefly my situation and my question:
I am developing with my newbie developer skills a 3D game with a procedural infinite terrain.
Currently, each time a new part of the terrain is being generated, I have a second or two lag. This seems normal, everything happens on the same thread, so until the generation is over, the game freezes.
I read that unity 5 will have a new multithread job scheduller.
Having learned everything I know on development with Unity Answers and other forums, I have to say I do not know what the above means exactly.
Will this new multithread job sheduller allow me to generate my terrain on a separate thread to prevent the freeze of the game during my terrain generation?
What could/couldn’t we do with the multithreads?
I have tried to search for answers to this, but couldn’t find any (or at least, none that I could understand).
I repeat that I am far from a pro developer and that pro dev language could be hard for me to read.
Thanks for any help understanding this
Happy development to all,
Garlik
Thanks Sniper! Yes indeed, this would be my goal. But as unity 4 is not multi-thread safe, I understand I should not try to do this (multi-threading) My question (maybe unclear) is thus: will I be able to do so in Unity 5? Indeed smaller chunks helps, but is still not enough to completely eliminate the lag even on my decent computer. This is why I try to understand more on multi-threading (for smaller computer configurations)
You can already generate terrain (and, in fact, many bulk background tasks) on a separate thread using Unity 4.x - the scripting environment is just C#/Mono, so you can use the methods in System.Threading as you would in any .NET application.
The only thing you can’t do is use Unity API methods themselves across different threads, as they are not thread-safe, but that won’t prevent you from doing background processing tasks.
See bunny83’s answer in this thread, or alexzzzz’s example on this forum post for examples of multithreaded code in Unity.
Note that threading is a relatively advanced concept. If you’re not a “pro dev” then you might have to do some background reading, as there are a whole lot of very easy ways to cock things up when threading. Try here for a beginner’s guide: Threading in C# - Free E-book
Thanks tonoshimi, I suppose this will be the best answer for unity 4.x, but do you (or anyone else) knows if Unity API methods will be thread-safe in Unity 5? Also, from my basic understanding, could you confirm I understand things correctly?: In a separate thread one can: - Make heavy calculations that can be sent to the main thread - NOT instantiate GameObjects, modify mesh or do anything on GameObjects Is this indeed what "not thread-safe" means?
Actually never thought of using that. Though this would be a 'workaround' for me, as this requires Unity Pro, witch I do not own currently. I really would love an explanation on Unity 5 multi-threading if anyone has it. Thanks for the info in any case, I'll give it a try if/when I own PRO
I had problem unzipping files, locked the whole game for a few seconds.
and also have large procedural geometry generation.
Just put your code in an ienumerator, then call it with the special async StartCoRoutine method in ThreadNinja, and bob’s your uncle. (translation… it just works)
Thanks Sniper! Yes indeed, this would be my goal. But as unity 4 is not multi-thread safe, I understand I should not try to do this (multi-threading) My question (maybe unclear) is thus: will I be able to do so in Unity 5? Indeed smaller chunks helps, but is still not enough to completely eliminate the lag even on my decent computer. This is why I try to understand more on multi-threading (for smaller computer configurations)
– GrKlAs Unity 5 is now out, is there any new information to be given about this topic?
– adamk33n3r