How does cancel_free() work?

Godot Version

4.2.2

Question

I’ve got this script attached to a node:

extends node

func _notification(what: int) → void:
if what == NOTIFICATION_PREDELETE:
print(“u cannot kill me”)
cancel_free()

I thought this script would prevent the node from being freed, but when i call node.queue_free(), it prints the message but gets freed anyway.
Can someone explain me what’s going on?
Thanks in advance

P.S. sorry for any grammatical error

NOTIFICATION_EXIT_TREE - if you’re using free and remove methods
NOTIFICATION_PREDELETE - if you’re using remove methods (removed from tree, but not freed)

I haven’t used them both before, maybe I’m wrong, I’ve found solution there `NOTIFICATION_PREDELETE` isn't immediately sent when a tool script node is removed · Issue #84366 · godotengine/godot · GitHub

I guess you’re freeing it, that’s why notifications not emitting

Thanks for the tips!

If it helped you, could you make it as a solution?)

Sorry, I’m new to Godot forum and I didn’t know I could do that

1 Like

All is Ok, thanks :slight_smile:

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