How to get sprite to disappear after 5 seconds?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Cakee

I am showing a sprite and would like to have a coded way to make a sprite disappear after showing for five second without using animations.

:bust_in_silhouette: Reply From: Nobledestus

I’m new to Godot but I think you can use the timer node and use signal to connect it to the sprite. Then on the inspector increase wait to 5.
That’s it I think

:bust_in_silhouette: Reply From: JCNegar

You can show the sprite start a timer then use the timer’s timeout signal

func on_timer_timeout():
    $Sprite.visible = false
:bust_in_silhouette: Reply From: Ertain

Have you looked into using a Timer? Set the Timer to “One shot”, then assign its timeout() signal to some script (such as the sprite’s script). Set the signal function (the one that’s usually called _on_timer_timeout()) to either hide the sprite, or free it completely. The function would look like this:

# In the sprite script.
func _on_timer_timeout():
    # Either call this function or hide()
    queue_free()