1
\$\begingroup\$

I connected signal when a scene is instantiated.

# AsteroidSpawner.gd
func spawn_asteroid():
    var asteroid_instance = asteroid_scene.instance()
    asteroid_instance.connect("destroy", self, "handle_asteroid_destroy")
    add_child(asteroid_instance)
func handle_asteroid_destroy():
    ... # TO SOME STUFFS WHEN ASTEROID DESTROYED...
    ... # How to disconnect this handler from here?

But the problem is, I want to disconnect handle_asteroid_destroy handler when object destroyed(or will destroy, use queue_free). How do I disconnect signal on specific object? Is Godot Engine will free the handler automatically?

\$\endgroup\$
1
\$\begingroup\$

You do not have to worry about disconnecting a signal when an object is destroyed -- the engine will handle that for you. See the connect docs:

If the target is destroyed in the game’s lifecycle, the connection will be lost.

You can also use CONNECT_ONESHOT to ensure that a signal is disconnected after firing once, though it is not necessary in this situation.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.