Why doesnt this tween change the position of a node twice in a row?

Godot Version

4.2.stable

Question

I’m trying to tween the position of a collectable after a timer goes off, first up two meters, and then to the player. I’ve pretty much copied the tween example straight from the documentation but for some reason only the first tween_property will run. if i comment out either tween_property line the other works fine but if i put both only the first line runs and i don’t know why. please help. thanks in advance.


func _physics_process(_delta) -> void:
	if should_goto_player:
		if not has_set_up_position:
			has_set_up_position = true
			up_position = get_global_position() + Vector3(0,2,0)

		var tween = create_tween()
		tween.tween_property(self, "position", up_position, 1.0)
		tween.tween_property(self, "position", Global.player.position, 1.0)

func _timer_timeout():
	should_goto_player = true

Once should_goto_player becomes true you start to create a tween every single frame, 60 new tweens per second. And they all fight each other for setting the same property.

how is it supposed to be written?

Easy solution? Put everything you have in _phisycs_process() into _timer_timeout() instead.

Proper solution? Depends what else you have in your project, how nodes and scenes are setup and what you want to achieve.

ok, i thought tweens were supposed to run every frame. i guess that’s where the confusion was. thanks for the response.

You can simply place your tween actions in function timer like this, with a tag
tween_processing to avoid call tween repeatedly :

var tween_processing: bool = false

func _timer_timeout():
    if not tween_processing:
		tween_processing = true
        ...

	    var tween = create_tween()
	    tween.tween_property(self, "position", up_position, 1.0)
	    tween.tween_property(self, "position", Global.player.position, 1.0)

It should be work properly

thanks for the reply. i thought tweens were supposed to called every frame but i guess not.