Write Faster Code with Coroutines in Godot 4.2+ and 3.5
Channel: Cashew OldDew
Date: 26/02/2024

There was quite a large leap between how coroutines are handled in Godot 3.5 and Godot 4.2+. Instead of Yield, which was used in Godot 3.5, the new Await keyword is being used in Godot 4.2+. 

This video aims to cover what coroutines are, how to use them in Godot 4.2+ with Await, how to use them in Godot 3.5 with yield, the differences between await and yield, how to migrate from Godot 3.5 to Godot 4.2+ and finally some bad practices you should avoid while working with coroutines.

The concepts in this video also apply to Godot 4.3

There have been a lot of useful details about coroutines I found while researching this video. Additionally, I have also used some free assets for which I can't be thankful enough. Here are the links for everything:

Official Godot 4.2 documentation for the Await keyword: https://docs.godotengine.org/en/stable/tutorials/scripting/gdscript/gdscript_basics.html#awaiting-for-signals-or-coroutines (sometimes this link doesn't work properly. An easy fix is to scroll down or search for 'coroutines' to find the docs about await)
Official Godot 3.5 documentation for the Yield function: https://docs.godotengine.org/en/3.5/tutorials/scripting/gdscript/gdscript_basics.html#coroutines-with-yield
Extra useful GDScript blog post about coroutines: https://gdscript.com/solutions/coroutines-and-yield/
Discussion regarding the change from Yield to Await and the lack of support for a way to resume a coroutine, similarly to how it was possible with Yield: https://github.com/godotengine/godot-proposals/issues/5673#issuecomment-1456566139
Godot 4.2 coroutines repository which helps replicate the previous Yield behavior: https://github.com/BimDav/Godot4-Coroutines
Link for a simple coroutine wrapper: https://forum.godotengine.org/t/i-dont-understand-how-await-is-a-replacement-for-yield/4711/3
Helpful coroutines tutorial from @GodotTutorials : https://www.youtube.com/watch?v=XJU0P6M5IKg
Dino character: https://arks.itch.io/dino-characters
Cars used from city pack: https://nyknck.itch.io/citypackpixelart
Thumbnail uses assets from Lethal Company: https://store.steampowered.com/app/1966720/Lethal_Company/

I'm again, extra thankful for all the free information and assets. This video wouldn't have been possible without your help!

--------------------
Github repository for this project. Contains links from the description and the two migration example code documents:
https://github.com/cashew-olddew/godot-tutorials/tree/main/multiple%20versions/1%20-%20Coroutines%2C%20yield%20%26%20await

Support me on Ko-Fi: https://ko-fi.com/cashewolddew
--------------------

Chapters:
0:00 What will you learn?
0:22 What is a coroutine?
1:12 Using the await keyword in Godot 4.2
8:55 Using the yield function in Godot 3.5
17:50 Migrating from Godot 3.5 to Godot 4.2
19:00 Bad practices when using coroutines

Footnote: Sorry for the ASMR in this video. I was a bit too close to the microphone 😞

#gamedev #godot #tutorial