Tween reset results in "Tween started with no Tweeners"

Godot Version

4.7.2

Question

Hello ! I’m creating tweens to make a TextureRect and a Label node come into the frame when clicking, like a photograph coming out of an old polaroid. It was working perfectly when the tweens were allowed to finish because I forcibly reset the positions of the nodes at the start of the method, but not so much when clicking during the tweens. The positions wouldn’t reset, instead their animations would get slower and slower with each clicks until they reached their destination.

After searching for a solution I settled on killing the tweens at the start of the method, but in order to do that they needed to already exist, so I created them in the _ready function without using them right away. This causes the “Tween started with no Tweeners” error in the Debugger because my tweens aren’t in use right after their creation. Creating the tweens at the start of the method also doesn’t work and puts me back to the first problem I was having.

Here’s the code:

extends Control

var tweenphoto: Tween
var tweenlabel: Tween

func _ready() -> void:
	tweenphoto = create_tween()
	tweenlabel = create_tween()

func prendre_photo():
	print("click !")
	# Node & Tween reset
	if tweenphoto.is_running():
		tweenphoto.kill()
	if tweenlabel.is_running():
		tweenlabel.kill()
	$TexturePicture.position = Vector2(77.0, -250.0)
	$TexturePicture.texture = null
	$TexturePicture/Label.position = Vector2(0.0, 658.604)
	$TexturePicture/Label.set("theme_override_colors/font_color", Color(0.0, 1.0, 0.0, 0.0))
	
	# Tweens
	tweenphoto = get_tree().create_tween()
	tweenphoto.tween_property($TexturePicture, "position", Vector2(77.0, 60.0), 1.0)
	tweenlabel = get_tree().create_tween()
	tweenlabel.tween_property($TexturePicture/Label, "theme_override_colors/font_color", Color(0.0, 1.0, 0.0, 1.0), 3.0)

In case it could help, here’s a picture of my scene setup and the relevant errors in the Debugger:

Does anyone know a better way to reset these tweens ? I don’t think I’m supposed to upset the editor like that, so I must be doing something wrong even though it’s working perfectly from my perspective…

Thanks !!

I check if they are non-null and running. Sadly you cannot create a invalid tween without errors (but it’s been a while).

if tweenphoto and tweenphoto.is_running():
   tweenphoto.kill()

I would prefer for this to work, creating an invalid tween rather than null; maybe it does now or in the future

var tweenphoto := Tween.new()

This works !! Thanks a lot !