When using coroutines to pause logic and resuming later, it would be very convenient if the “context” in the background were also kept and restored on resume. I have a central system that maintains coroutine “threads”, it checks continuously if they are paused to resume them based on conditionals. However if I yielded within a .gui_script and later resume from update within a .script, then errors like “node used in wrong scene” will appear.
The current workaround I use involves sending messages and then resume from on_message instead. It would also be possible to store all coroutines within the “self” context of the scripts, then add an update to each and check if they want to resume based on conditionals. The second “solution” would however require many more wasted updates in addition to being less flexible.
If the engine could perform the message passing “under the hood” or store the original go/gui context within the coroutine that would be awesome!