Tween not working as expected [Godot 4 beta 3]

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Godot_Starter
func move_body_part():
var tween :Tween = get_tree().create_tween()
tween.tween_property(self,"position",Vector2.RIGHT * 16, 0.5)

I am having this function, which gets called every 0.5 seconds, but I am only seeing a movement the first time it gets called, rather then a continious movement to the right. What am I doing wrong?

:bust_in_silhouette: Reply From: lakshaya

I think this is by design.

Can you try giving the tween a global scope, and calling tween.kill() at the beginning of this function.

So instantiate the tween globally, and just do tween.kill() and tween.tween_property() in this function.

Thank you for your response! Unfortunatly, I dont really get what you mean.

I tried modifiying the function like this:

func move_body_part():
 Globals.tween.tween_property(self,"position",Vector2.RIGHT * 16, 0.5)

and adding a autoloaded script like this:

@onready var tween :Tween = get_tree().create_tween()

but now it doesnt moves to the right at all and instead, I am getting this error whenever I try to call the function:

_on_timer_timeout: Tween invalid. Either finished or created outside scene tree.

Did I understand your answer wrong?

Godot_Starter | 2022-10-22 12:40