title: In Unity specifically, "where" does an await literally return to?
body: <p>In Unity, say you have a <code>GameObject</code> .  So, it could be Lara Croft, Mario, an angered bird, a particular cube, a particular tree, or whatever.</p>
  <p><a href="https://i.stack.imgur.com/IHYy5.png" rel="noreferrer"><img src="https://i.stack.imgur.com/IHYy5.png" alt="enter image description here" /></a></p>
  <p>(Recall that Unity is not OO, it's ECS. The <code>Component</code>s themselves which you can &quot;attach&quot; to a <code>GameObject</code> may or may not be created in an OO language, but Unity itself is just a list of <code>GameObject</code>s and a frame engine that runs any <code>Component</code>s on them each frame. Thus indeed Unity is of course &quot;utterly&quot; single-thread, there's not even a conceptual way to do anything relating to &quot;actual Unity&quot; (the &quot;list of game objects&quot;) on another<sup>1</sup> thread.)</p>
  <p>So say on the cube we have a <code>Component</code> called Test</p>
  <pre><code>public class Test: MonoBehaviour {
  </code></pre>
  <p>It does have an Update pseudofunction, so Unity knows we want to run something each frame.</p>
  <pre><code>  private void Update() { // this is Test's Update call
       
       Debug.Log(ManagedThreadId); // definitely 101
       if (something) DoSomethingThisParticularFrame();
    }
  </code></pre>
  <p>Let's say the unity thread is &quot;101&quot;.</p>
  <p>So that Update (and indeed any Update of any frame on any game object) will print 101.</p>
  <p>So from time to time, perhaps every few seconds for some reason, we choose to run <code>DoSomethingThisFrame</code>.</p>
  <p>Thus, every frame (obviously, on &quot;the&quot; Unity thread ... there is / can only be one thread) Unity runs all the Update calls on the various game objects.</p>
  <p>So on one particular frame (let's say the 24th frame of the 819th second of game play) let's say it does run <code>DoSomethingThisParticularFrame </code> for us.</p>
  <pre><code>void DoSomethingThisParticularFrame() {
  
     Debug.Log(ManagedThreadId); // 101 I think
     TrickyBusiness();
  }
  </code></pre>
  <p>I assume that will also print 101.</p>
  <pre><code>async void TrickyBusiness() {
  
     Debug.Log(&quot;A.. &quot; + ManagedThreadId); // 101 I think
     var aTask = Task.Run(()=&gt;BigCalculation());
     
     Debug.Log(&quot;B.. &quot; + ManagedThreadId); // 101 I think
     await aTask;
  
     Debug.Log(&quot;C.. &quot; + ManagedThreadId); // In Unity a mystery??
     ExplodeTank();
  }
  
  void BigCalculation() {
     
     Debug.Log(&quot;X.. &quot; + ManagedThreadId); // say, 999
     for (i = 1 to a billion) add
  }
  </code></pre>
  <p>OK so</p>
  <ol>
  <li><p>I'm pretty sure at A it will print 101.  I think.</p>
  </li>
  <li><p>I guess that at B it will print 101</p>
  </li>
  <li><p>I believe, but I'm uncertain, at X it will have started another thread for BigCalculation. (Say, 999.)  (But maybe that's wrong, who knows.)</p>
  </li>
  </ol>
  <h1>My question, what happens, in Unity, at &quot;C&quot; ?</h1>
  <p>What thread are we on at C, where it (tries to?) explode a tank????</p>
  <h1>I believe in normal .Net environments, you'd be on another thread at C, say 202.</h1>
  <p>(For example, consider this <a href="https://stackoverflow.com/a/55604269/294884">excellent answer</a> and notice the first example output &quot;Thread After Await: 12&quot;. 12 is different from 29.)</p>
  <p>But that's meaningless in Unity -</p>
  <p>... how can <code>TrickyBusiness</code> be on &quot;another thread&quot; - what would that mean, that the whole <em>scene</em> is duplicated, or?</p>
  <p>Or is it the case that (in Unity especially and only?  IDK),</p>
  <p>at the point where <code>TrickyBusiness</code> begins, Unity actually puts that (what - a naked instance of the class &quot;Test&quot; ??) on another thread?</p>
  <h1>In Unity when you use <code>await</code> what does it print at C, or A for that matter?</h1>
  <p>It would seem that:</p>
  <h1>If indeed &quot;C&quot; is on a different thread - you simply can't use awaits in that way in Unity, it would be meaningless.</h1>
  <hr />
  <p><sup>1</sup> <em>Obviously some ancillary calculations (eg, rendering, whatever) are done on other cores, but the actual &quot;frame based game engine&quot; is one pure thread. (It's impossible to &quot;access&quot; the main engine frame thread in any way whatsoever: when you are programming, say, a native plugin or some calculation which runs on another thread, all you can do is leave markers and values for the components on the engine frame thread to look at and use when they run each frame.)</em></p>