How to properly use tweens

Godot Version

4.2

Question

Hi guys, I hope you are all doing fine !
So here is my problem: I’m trying to put together a code that will use tweening and tween animations to:

  • Move a Camera to an object
  • Change shader values to create a circle around this object

So, pretty basic stuff. I put together the code below, but when I launched the scene…nothing happens. The camera doesn’t move, the shader doesn’t change.
I checked that:

  • My code is called
  • My function is properly called
  • The ‘final position’ of my Camera is different than its start pos

No tween in this block seems to work, however, when I do it on the calling block (second block of code) it seems to work.

Code for my tweening:

func spotlightAnObject(pointDescr: SpotPointDescriptor):
	var animationTween = create_tween()
	if pointDescr.tweenTransparency:
		var intermediateCol = Color(pointDescr.colorOfBackground, 0.)
		_set_background_color(intermediateCol)
		animationTween.tween_method(_set_background_color, _get_background_color(), intermediateCol, pointDescr.timeToTravel)
	else:
		_set_background_color(pointDescr.colorOfBackground)
		
	var cameraEndPos = _compute_camera_end_pos(pointDescr.objectToSpotLight, cam.global_position)
	animationTween.tween_property(self, "global_position", cameraEndPos, pointDescr.timeToTravel)
	await get_tree().create_timer(pointDescr.timeToTravel).timeout
	animationTween.kill()
	work_over.emit()

Code for calling this code:

func _ready():
	var pointLightDescr = TutorialSpotLight.SpotPointDescriptor.new(
		ToFocus.global_position,
		70,
		Color.BLACK,
		true,
		5.
	)
	
	spotLight.spotlightAnObject(pointLightDescr)

What am I missing about tweens there ? What could be the issue ?

Have you checked that pointDescr.timeToTravel is not 0 or smaller? (Probably would help to see your code for SpotPointDescriptor.new(...) as well)

Also, instead of this:

await get_tree().create_timer(pointDescr.timeToTravel).timeout
animationTween.kill()

you could simply do this:

await animationTween.finished