Error - Tween / started with no Tweeners

Godot version 4

I have the following error in my animation code for a card. The bug appears when I hover over the cards and the card rotation animations happen with the mouse.

Error:

E 0:00:04:0603 step: Tween (bound to /root/Control/RoundResult/Control2/PlayerCard2Position): started with no Tweeners.

  • <C++ Error> Method/function failed. Returning: false*
  • <C++ Source> scene/animation/tween.cpp:319 @ step()*

E 0:00:04:0987 step: Tween (bound to /root/Control/RoundResult/Control/PlayerCard1Position): started with no Tweeners.

  • <C++ Error> Method/function failed. Returning: false*
    <C++ Source> scene/animation/tween.cpp:319 @ step()

I attach the complete code…

extends TextureButton

@export var angle_x_max: float = 15.0
@export var angle_y_max: float = 15.0
@export var max_offset_shadow: float = 50.0

@export_category("Oscillator")
@export var spring: float = 150.0
@export var damp: float = 10.0
@export var velocity_multiplier: float = 2.0

var displacement: float = 0.0 
var oscillator_velocity: float = 0.0


var last_mouse_pos: Vector2
var mouse_velocity: Vector2
var following_mouse: bool = false
var last_pos: Vector2
var velocity: Vector2

@onready var card_texture: TextureRect = $CardTexture
@onready var shadow = $Shadow
@onready var collision_shape = $DestroyArea/CollisionShape2D

func _ready() -> void:
	angle_x_max = deg_to_rad(angle_x_max)
	angle_y_max = deg_to_rad(angle_y_max)
	collision_shape.set_deferred("disabled", true)
	last_pos = position

func _process(delta: float) -> void:
	rotate_velocity(delta)
	handle_shadow(delta)


func rotate_velocity(delta: float) -> void:
	if not following_mouse: return
	var _center_pos: Vector2 = global_position - (size / 2.0)
	velocity = (position - last_pos) / delta
	last_pos = position
	oscillator_velocity += velocity.normalized().x * velocity_multiplier
	var force = -spring * displacement - damp * oscillator_velocity
	oscillator_velocity += force * delta
	displacement += oscillator_velocity * delta
	rotation = displacement

func handle_shadow(_delta: float) -> void:
	if not is_instance_valid(shadow):
		return
	var center: Vector2 = get_viewport_rect().size / 2.0
	var distance: float = global_position.x - center.x
	shadow.position.x = lerp(0.0, -sign(distance) * max_offset_shadow, abs(distance / center.x))

func follow_mouse(_delta: float) -> void:
	if not following_mouse: return
	var mouse_pos: Vector2 = get_global_mouse_position()
	global_position = mouse_pos - (size / 2.0)

func handle_mouse_click(event: InputEvent) -> void:
	if not event is InputEventMouseButton: return
	if event.button_index != MOUSE_BUTTON_LEFT: return

	if event.is_pressed():
		following_mouse = true
	else:
		following_mouse = false
		collision_shape.set_deferred("disabled", false)
		var tween_handle = create_tween().set_ease(Tween.EASE_IN_OUT).set_trans(Tween.TRANS_CUBIC)
		tween_handle.stop()  # Stop immediately after creation
		tween_handle.tween_property(self, "rotation", 0.0, 0.3)
		tween_handle.play()  # Start the tween manually

func _on_gui_input(event: InputEvent) -> void:
	handle_mouse_click(event)
	if following_mouse: return
	if not event is InputEventMouseMotion: return

	var mouse_pos: Vector2 = get_local_mouse_position()
	var _diff: Vector2 = (position + size) - mouse_pos
	var lerp_val_x: float = remap(mouse_pos.x, 0.0, size.x, 0, 1)
	var lerp_val_y: float = remap(mouse_pos.y, 0.0, size.y, 0, 1)
	var rot_x: float = rad_to_deg(lerp_angle(-angle_x_max, angle_x_max, lerp_val_x))
	var rot_y: float = rad_to_deg(lerp_angle(angle_y_max, -angle_y_max, lerp_val_y))

	if is_instance_valid(card_texture) and card_texture.material:
		card_texture.material.set_shader_parameter("x_rot", rot_x)
		card_texture.material.set_shader_parameter("y_rot", rot_y)

func _on_mouse_entered() -> void:
	var tween_hover = create_tween().set_ease(Tween.EASE_OUT).set_trans(Tween.TRANS_ELASTIC)
	tween_hover.stop()  # Stop immediately after creation
	tween_hover.tween_property(self, "scale", Vector2(1.2, 1.2), 0.5)
	tween_hover.play()  # Start the tween manually

func _on_mouse_exited() -> void:
	var tween_rot = create_tween().set_ease(Tween.EASE_OUT).set_trans(Tween.TRANS_BACK).set_parallel(true)
	tween_rot.stop()  # Stop immediately after creation
	if is_instance_valid(card_texture) and card_texture.material:
		tween_rot.tween_property(card_texture.material, "shader_parameter/x_rot", 0.0, 0.5)
		tween_rot.tween_property(card_texture.material, "shader_parameter/y_rot", 0.0, 0.5)
	tween_rot.play()  # Start the tween manually

	var tween_hover = create_tween().set_ease(Tween.EASE_OUT).set_trans(Tween.TRANS_ELASTIC)
	tween_hover.stop()  # Stop immediately after creation
	tween_hover.tween_property(self, "scale", Vector2.ONE, 0.55)
	tween_hover.play()  # Start the tween manually

You should paste your code directly into the post using the following code format:

```
your code here
```

If you could provide a screenshot of your editor view, that would be much more helpful than a picture of a PDF.

I have created the code in the post

Here you add the tweeners (tween_property) inside the if statement, so if the if statement is false then you’ll just try to start the tween with on tweeners added, I think that might be the issue.

Try creating the tween inside the if statement and put all the code in there, so if the if statement is false then nothing will happen, no tween will be created at all, so it shouldn’t give an error.

You can also add and else: statement after the if and print something in it like “instance is invalid” to test if that is the problem or I’m wrong about it…

edit: also you don’t have to stop and start the tweens manually.

2 Likes

Thank you very much!!..it has been solved, I actually had to create the interpolation within the if statement and place all the code there

1 Like