Skip to content

Instantly share code, notes, and snippets.

@Gnumaru
Created October 23, 2024 19:54
Show Gist options
  • Save Gnumaru/23700f091ce457005ad336849a9eb832 to your computer and use it in GitHub Desktop.
Save Gnumaru/23700f091ce457005ad336849a9eb832 to your computer and use it in GitHub Desktop.
how to run some code right AFTER an object has been freed
extends Node
func _notification(what: int) -> void:
if what == Object.NOTIFICATION_PREDELETE:
# post_delete is a static method, thus it can be called deferredly even by dying objects. Beware that an object can be "saved" from a queue_free call by calling cancel_free, but a free call (instead of queue_free) should kill it imediatly without chance for survival
post_delete.call_deferred(get_instance_id(), get_path())
static func post_delete(id: int, path: NodePath) -> void:
print("node with instance id %s and path %s was just deleted" % [id, path])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment