Why does tween.stop() need an argument?

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

I just want to stop my tween, but it’s not working!

func _process(delta):
	var distance2opponent = self.transform.origin.distance_to(get_node("../Player").global_transform.origin)
	if distance2opponent < 5 and $Tween2.is_active():
		$Tween2.stop()

This gives me this Error:
Invalid type in function ‘stop’ in base ‘Tween’. Cannot convert argument 1 from int to Object.

But if I put say: $Tween2.stop(Tween) it does absolutely nothing.

PLEASE someone help, I’v been stuck on this problem for 2 days and I don’t know what bool stop ( Object object, String key=”” ) is, as stated in the Godot docs. I don’t know what a “key” is. I’ve searched online and I can’t find anyone doing anything with tweens besides creating them. PLEASE HELP.

:bust_in_silhouette: Reply From: Zylann

As you might have noticed, a Tween node can actually animate multiple properties at once. When you start one, you likely specified an object and a property of that object to animate.

The stop function needs the same things: the object you started the tween with, and the property you were animating (the key). If you omit the key, it will stop animating all properties of the passed object.

If you want to stop ALL animations this Tween node is running, use stop_all().

Check the doc:

Thank you very much for the quick response and explaination. I understand now.

I put $Tween2.stop(self) and it worked as expected.

Dumuz | 2019-11-29 18:59

stop_all() is not working for me., help me out
@Zylann

muthu0914 | 2020-02-17 07:06