This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

In the game I'm making I need a sprite to despawn after a timer has gone off. The issue is, The sprite is instanced, and the node that instanced it would be queue_free()'d at this point.

Let me explain this more clearly: After the health of an enemy teachers 0, I call the queue_free() function and spawn a sprite in its place, as the child of the previous node's owner. Now, this is all fine and dandy, but I want this sprite gone after 5 seconds, which isn't happening.

I've tried a few things: I've tried attaching a timer to the sprite, which would queuefree() the sprite after its time has run out (the script is attached to the sprite itself). I thought about autoloading a timer that would queuefree() anything with the tag "debris" but I don't know how I would specify which bodies the timer would target.

I've been thinking and searching for a solution for over an hour but I've come up on nothing. Any help would be appreciated.

in Engine by (105 points)

1 Answer

0 votes

So, the problem is that you cannot have access to the temporary sprite' s instance? If this is the case, maybe you can define a variable and store there the sprite' s instance. Then you can use this variable with a timer on its timeout method. Something like this:

var temp_sprite

temp_sprite = sprite.instance()

func on_timer_timeout():
    temp_sprite.queue_free()
by (222 points)

I want to be able to queue_free() more than just one sprite: if two enemies die 5 seconds apart, I want their sprites to be deleted according to their respective timers (aka 5 seconds apart). To clarify I've set the timer to autostart and connected the timeout signal.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.