How to stop a coroutine while it is executing?

Godot Version

4.2

Question

So I’m having a coroutine function, which draws the bubble of an npc talking. When an event happen, let say for example, the player break a vase, I want to immediately stop that talking of the npc.
For more detail, all these functions has nothing to do with _process() or _physic_process(). They are independent customed one, and are called in some specific places here and there.
the talking function kinda look like this:

func _talking():
   draw_bubble(1)
   await create_timer(1).timeout
   draw_bubble(2)
   await create_timer(1).timeout
   ...

I have looked up for the solution but so far haven’t found one. Any help would be appreciated.

i dont think this is possible, unless you emit the awaited signal by hand

try using tween_interval() instead.
make sure you have/hold the tween variable for the bubble, so you can .kill() it when you deemed it’s no longer used, then recreate the tween by create_tween() to that same tween variable for destroying the bubble for example.

1 Like

here

I am creating and using a coroutine manager that can stop a coroutine and delete a coroutine object at any time.

1 Like