Skip to content
Erik edited this page Nov 6, 2019 · 7 revisions

Unity is single-threaded. (Spool spins off a single thread, weaving up and down on screen as the words are read)

(Using screenshots of pong below)

Awake     / Start 
  |           |
Awake   /   Start 
  |           |           ...           ...        ...        ...            Frame 2 .... Frame 3
Awake /     Start /

Awake       Start      FixedUpdate     Update   Coroutines  LateUpdate ...

In between each frame, objects are updated one at a time in the defined ExecutionOrder.

(Thread continues away from execution order)

Being single-threaded like this protects developers from having to worry about concurrency and contention (2 threads intersect and behave erratically), which is especially important when working with physics and game objects. (Return to Execution Order)

(Animation of new coroutine text being appended to the list) Starting a new Coroutine adds a new execution to the main thread.

(Split off a new of thread and show it exiting the execution order, running in parallel) A new thread will run outside of the standard execution cycle completely.

As a result, this thread cannot leverage any of Unity's runtime methods. If you need to access data about a gameObject in a parallel job, it's best to get the data on the main thread before you invoke the new job. (Show the new thread trying to cross back into the Unity Runtime and to hit "GetComponent", ".Transform", "Time.deltaTime")

It is technically still possible to make this happen with threadsafe collections and savvy programming, but I don't feel confident in my understanding enough yet to teach you about it.

Clone this wiki locally