Last Updated: March 02, 2016
· moechofe

Yield always ⚠ return from the function in Godot

Coroutines & Signal are a powerfull feature for the Godot game engine. It's remind me the lua coroutines. I use it a lot until I was stuck with a problem.

yield(node_instance, signal_name)

The line above stop the execution of the current function and wait for node_instance to send the signal_name with the instruction:


One day, I put the yield instruction inside a sort of a getter function that use the return keyword. It was without counting the fact that yield return from the function. It actually return an instance of a GDFunctionState used to resume the function.

# The getter
func get_thing():
    return yield(a_node,"executed")

# In the a_node script:
signal executed(val)
func execute():

The example above do not work: get_thing will return a GDFunctionState instead of 123.