How can I delete a node(from code) after a tween (from code) is completed?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By fader

I currently am creating AudioStreamPlayer nodes from code when a button is pressed. When that button is pressed again, the audio is meant to fade out using a Tween also generated from code. What I don’t understand is how to have the Tween node delete itself when the Tween is over.

When the Tween node is created, the following code is used to connect the “tween_completed” signal, but clearly I am not using “queue_free” properly, or something else.

WeatherTween.connect("tween_completed", WeatherTween, "queue_free")

If I am understanding this correctly, this should connect the WeatherTween’s “tween_completed” signal to itself, such that the signal triggers the node to delete itself at the next frame.

:bust_in_silhouette: Reply From: njamster

You should see an error in the Debugger once the tween finishes:

emit_signal: Error calling method from signal 'tween_completed': 'Tween::queue_free': Method expected 0 arguments, but called with 2..

Use “tween_all_completed” instead, it does not expect any arguments:

WeatherTween.connect("tween_all_completed", WeatherTween, "queue_free")

Thanks. That fixed it.

fader | 2020-05-12 20:58