About 'Introducing Coroutines'!

In this video (objectives)…

  1. How loops stall of block our code
  2. Use 'IEnumerator' as a return type
  3. Using 'StartCoroutine()'
  4. How to 'yield' execution
  5. Returning a yield instruction
  6. Using 'WaitForSeconds()'

After watching (learning outcomes)…

Use a basic co-routing to make a time-based sequence appear to run in parallel to the rest of your game code.

(Unique Video Reference: 7_RR_CU2)

We would love to know…

  • What you found good about this lecture?
  • What we could do better?

Remember that you can reply to this topic, or create a new topic. The easiest way to create a new topic is to follow the link in Resources. That way the topic will…

  • Be in the correct forum (for the course).
  • Be in the right sub-forum (for the section)
  • Have the correct lecture tag.

Enjoy your stay in our thriving community!

Unrelated, just thought I’d mention it here though. The topic of video capture keeps coming up due to the many many options out there, but I feel one is overlooked on Windows 10.

There’s actually a built in way to do it that has minimal impact on performance. Just hit the Windows key + G, say yes this application is a game. Then you’re free to use the game bar to stream or just record whatever it is you’re doing with ease. No downloading or messing with settings. Just Windows + G.

Cheers.

Thanks for sharing

I totally did not understand the coroutine explanation. Even after watching the Unity channel’s official coroutine video explanation, I was still confused. The explanation explained what a coroutine could do before properly explaining what it is. I would recommend this video that I finally found that explains it quite well. https://www.youtube.com/watch?v=UnrITNPDnas

Thanks for sharing

wow im learning alot here, this is good stuff, thanks ben!

1 Like

Hi

I changed the game to use a Coroutine in the Search algoritme so i could see how the algoritme worked.

It worked fine - but now i have a problem with the path.

As the Coroutine slows down the search - the explored from is not set when the calculatePath tries to add the waypoints.

How can i set so a method call should only be called when a coroutine is entirely finished.

I tried adding a bool and setting a while (!bool){Thread.Sleep(1000)} but that just broke the game.

@Nina can you help here?

Hi Jacob,

Without knowing your code, I’d suggest the following solution:

void DoSomething() {
    // ...
}

IEnumerator MyCoroutine {
    WaitForSeconds delay = new WaitForSeconds(1f);

    loop {
        // ...
        yield return delay;
     }

    DoSomething();

}

DoSomething() gets called when the loop is terminated. In my example, “loop” is pseudo-code, not C#. You have to replace it with your own loop.

Hi
Thanks alot. Will try to refactor it like that.

Jacob

Privacy & Terms