Tween loops and queue_free loop

Godot Version

4.3

Question

`I want to loop 2x then delete the object after loop 2x. in my script the object is deleted after the first loop. how to fix this. this is my script. thanks

extends Control

@onready var _texture_rect = $BG/TextureRect

func _on_button_pressed():
var tween = get_tree().create_tween().set_loops(2)
tween.parallel().tween_property(_texture_rect, “position”, Vector2(get_viewport_rect().size.x - 128, 476), 1.0)
tween.parallel().tween_property(_texture_rect, “scale”, Vector2(2, 2), 1)
tween.tween_interval(1)
tween.tween_property(_texture_rect, “position”, Vector2(0, 476), 1.0)
tween.parallel().tween_property(_texture_rect, “scale”, Vector2(1, 1), 1)
tween.tween_callback(_texture_rect.queue_free)`

I always use “tween.finished” signal for it, you can try this:

await tween.finished
_texture_rect.queue_free()

I am not sure it will work, but let me know what happened, if it not works, then try this:

await get_tree().create_timer(3.0).timeout
_texture_rect.queue_free()

But first remove this line then try my codes.

oh wow, immediately succeeded. thank you so much

await tween.finished
_texture_rect.queue_free()

is work for me

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.