Taming Coroutines - Unity Tips

preview_player
Показать описание
In this video, I show an interesting idea of how to improve the way we start coroutines in Unity. This approach allows us to easily check whether or not our coroutine is still running or even dispatch an event once it's finished. Similarly to how AsyncOperations work.

Sources:

Support me on Patreon:

Timestamps:
0:00 IEnumerator
1:58 Controlling a coroutine
2:53 Waiting for other coroutines

#unity #unitytips #gamedev
Рекомендации по теме
Комментарии
Автор

First of all great Video, i am a big fan of your stuff, i just want to add something regarding yielding other Coroutines.
From my experience, yielding for a Coroutine can lead to problems in some cases. If you stop the Couroutine, you are waiting for, with StopCoroutine() or StopAllCoroutines() the yield will not count that as the Coroutine finishing correctly. The Code after the yield will never be executed and the Coroutine will be cleared at some point by the garbage collector. This is only a problem, if your Coroutines run on 2 seperate GameObjects, or you have some case where only one Coroutine is killed, however its definitelly something you should be aware of.
I hope that can help someone ^^

jesco
Автор

I don't even use Unity, but your videos are always interesting and well-made that I just have to watch.

PleepusPlopus
Автор

These clean and minimalistic visuals are excellent. Quite satisfying to watch. Great video :)

Leonardorth.
Автор

Half of this melts my brain. This guy is on another level of intellect.

anshpudaruth
Автор

This video is incredible!! Its super helpful and the animation and educational quality is off the charts

_kett
Автор

After seeing Brackeys use Coroutines with this odd IEnumerator syntax a couple of times, I was always mystified by how it worked; this video made everything click into place and gave me a nice 'aha!' moment. Well done!

ProjectV
Автор

This is just the right video I needed this month. Thank you!!!

lllennelll
Автор

that outro though - "possibilities are endless, unlike this video"

It seems like a quote, so imma make it one

SLR
Автор

ACtually one of the smartest game devs i have ever seen. Every video is short, to the point well edited and explained and genuinely if all these fake youtuber trying to get views devs were like him then the world would be a better place

Junivieve
Автор

This is a very short but amazing explanation of how coroutines work in Unity but also how IEnumerable functions work in C#. Brilliant video!

not__nugget
Автор

Your video's always motivate me to continue on my projects :)

Wobling
Автор

Heads up: The names "IEnumerator" and "IEnumerable" threw me off for a bit - I kept conflating them and it led to a lot of confusion.

C# interface names aside, this video is fantastic! Thanks for putting it together :)

BretHudson
Автор

basically everything went over my head but great video

AngusJMcGregor
Автор

Awesome video, I instantly cleaned up some weird coroutine madness I had setup afterwards

NaejDoree
Автор

Fantastic video dude, explained so clearly and edited to perfection. Smashed it!

ShibaDogStudios
Автор

Very great video! I had no idea you could pause IEnumerators like that. Thank you!

KjipGamer
Автор

This is literally the only video I could find with an intuitive explanation of coroutines.

Unity doesn't even have a video period

IPODsify
Автор

I had a lot of success using UniTask for asynchronous code because the native coroutines are very limited and require a lot of boilerplate to do more complex things. To make generators possible it contains a "Channel" abstraction which essentially behaves like an async iterator for async foreach and the generator just calls a write message instead of yielding.
But the library doesn't stop you from using native coroutines for anything you need and even provides adaptors for C# Tasks as well as coroutines. Its first focus is on performance so the library overhead is surprisingly small.

The library brings the default async facilities of C# to unity and nicely integrates it into the single-threaded game loop but also allows dispatch of long-running tasks to a background thread pool exactly as .net does. It can decouple a lot of complex logic from the polling nature of the unity update method but also allows frame by frame logic with await UniTask.Yield() which just waits for the next frame like yield null.
I am not affiliated with the library in any way btw.

lexer_
Автор

Excellent video, super clear explanation.
Can't wait to see the next video!!

peterhuijsen
Автор

Amazing video! You really can simply explain complicated things. I knew about how Coroutines work intuitively (because of the type that it returns), but never dived into this deeply.

capsey_