Hi everyone. I am hoping someone can help me figure this out, since it is really ruining Godot for me at the moment.
In my project, I am getting a reference to another node via:
var otherNode = get_tree().get_nodes_in_group("TargetNode")
This works fine and as expected.
However, if I then queuefree() this otherNode, its data is seemingly not actually removed from the game/world. More specifically, if I queuefree() it and then reinstance it, all of the variables contain things such as [Deleted Object] along with the new values, and the ready() function does not get called unless I call requestready() on the instancing script.
This is frustrating because I am unable to properly initialize the new instance of the node, since it is seemingly remembering old variables, and containing [Deleted Object]s in arrays etc.
It also appears that no combination of free(), queuefree(), calldeferred("queuefree"), or calldeferred("free") solves this issue, as the reference to the other node still persists. Even if I throw in otherNode = null, and or otherNode = preload("NullScene.tscn").instance().
The accompanying error message is
"Attempt to call function 'add_child' in base 'previously freed instance' on a null instance."
Any discussion or insight would be hugely appreciated. I am not sure what the best practice is regarding getting references to other nodes and how that interacts with the different methods of freeing them from the tree. At this point I am leaning towards something like avoiding references all together and just using signals. Thanks!
Edit: removed underscores because they were causing italics