Is it safe? Freeing nodes before they enter tree

Godot Version 4.4.1

Hi! Is it safe to free() a child node that has yet to enter the tree so you can replace it with a modded scene? The caller of the free() call is the parent node, on their enter_tree(), before the child has a chance to do so. Yes, queue_free() would be prefered but is too slow. No crashes yet, but I suspect there might be some minuscule risk?

In case you’re wondering why: I use an autoload as my main scene and want to add extensive support for modding. Adding on top has no issues, but replacing scenes should be done before they load. (For convenience)

Thanks :winking_face_with_tongue:

Unless you are calling other deferred functions on the child node, then it should be fine to free it. But maybe it would be better to just not instantiate the child node in the first place?

1 Like

Absolutely, hehe. However, I’d rather sacrifice the performance than loose this pretty scene tree :sweat_smile:

1 Like