What does giving back control mean?

Hello! Can anyone please tell me what it means when we are giving back control to Unity when we yield our code in our Coroutine? Does it mean that other code is not in control at the same time as the coroutine is being ran? Or does it just simply mean that it’s just being paused until the specified condition is met?


In our computer, everything happens step by step. First A, then B, then C, then D, and so on. The same happens in Unity. At some point, our methods get called, then we do things before Unity “takes over” again: calling methods, calculating stuff, rendering stuff, etc.

Since a coroutine is part of the Unity framework, we do not stop or pause anything that is not supposed to be stopped or paused within the framework. We can control only a part of our game. The rest is being managed by the game engine named Unity.

Did this clear it up for you?

See also:

Thank you Nina I kinda get it. It’s just gonna take some time for my head to wrap around coroutines in general. I’m confused as well why it’s best to call it in awake or start and not update, I’m guessing that in update it would call the coroutine 50 or 60 times per second and that would break things?

When we call StartCoroutine, a new Coroutine object gets created. If we call that method each frame and we have a framerate of 60, we would get 60 new Coroutine objects per second.

1 Like

Like Nina explained, computers do tasks one at a time. When we start a method, the computer runs line for line until the end of the method or until it hits a “return” keyword and then keeps going from wherever it left. The expression “yield return” basically tells Unity “Don’t run this method up until the very end, stop here, go back to the very next line where this coroutine was called and keep doing your step by step thing again from there. Eventually, once the condition in this “yield return” line is met, come back and keep doing this coroutine until the end or until another “yield return” (coroutines can have multiple yield returns in succession)”.

1 Like

Wow ok I get the picture there now got it thank you Nina !

I’m having a tough time wrapping my head around the concept but I’m closer thanks you yours and Ninas help thank you !

1 Like

I’m glad we were able to help you. :slight_smile:

Don’t worry if you haven’t understood every single detail yet. Descriptions are nice and all but many things will be grasped only when you apply your knowledge on problems and experience what people tried to explain. And then you’ll probably be like: “Okay, I’ve got this situation here, and I remember that I read about it a while ago. Now that I see it with my own eyes in my own project, that subject starts making sense. I should try this and that to figure out more.”


That makes sense I’ll take that and run with it thank you :slight_smile:

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms