- Home /
Program-Flow Control and Unity 5 Engine Threads
Does Unity 5 still use a single thread for the majority of its inner-workings? From here, Unity staff, Aras states that multi-threading is limited to mesh skinning, audio, network, and some other small things, but that was in Nov 2010 (Unity 3?). Does my following program-flow control impede itself from benefiting from multi-threaded performance, if it exists?:
I have been controlling the flow of my game program manually by having a "level" script (a MonoBehaviour) that conceptually sits on top of all other scripts in that game level, and in its Update(), manually calls methods of the other scripts (not MonoBehaviours) in the order that I want. E.g., first script detects user touches and stores them, second script filters user touches to those coinciding with enemy colliders, third script evaluates touch speed to determine which enemy response to trigger, etc.
I don't want to rely Unity's Script Execution Order, which requires me to rely heavily on MonoBehavior, as I'm trying to learn to better architect my code, have looser class coupling, highest unit testability, etc.
Answer by Bunny83 · Apr 15, 2016 at 04:35 AM
Nothing has changed in this regard. The Unity engine itself does use threads for various tasks internally. However the whole scripting environment is executed from the main thread (aka the main loop). The whole scripting API is designed for a single thread. This design simplifies the API drastically. A Unity game is always frame based. So you always have a destinct order of events happening between two frames (one iteration through the main loop).
Linear code can't possible make itself "multithreaded". If you use multithreading you have to handle that yourself. If you do, you have to create worker threads yourself and do proper synchronising / locking. However keep in mind that the Unity API can't be used from a different thread than the main thread. They actually implemented a check which will throw an exception if you try.
Your vague code descriptions doesn't sound like something that could be split in a meaningful way since every piece of code seems to depend on another (== linear code). There is no way to automatically split code into multiple threads.
Your answer
![](https://koobas.hobune.stream/wayback/20220612074810im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Google Daydream Thread with Unity 1 Answer
Thread in Jar verify it in Unity 1 Answer
Making calls to Spotify REST API blocks main thread 2 Answers
Multi threading problem ! 2 Answers
Unity Jobs Error - "Job can only create Temp memory" 1 Answer