0 votes

I am using the function get_nodes_in_group and sending the array to a function and returning 1 of the nodes.
I then create a new instance of an object and set one of it's variables to that node and add it to the scene. When the node from the group gets deleted, my new objects points to random things in scene. For example, a Tween node and an AudioStreamPlayer node. Why is it doing this, and how to I prevent it?

edit:
The variable has a [Deleted Object] that is eventually being replaced by new objects.

in Engine by (19 points)
edited by

1 Answer

+2 votes
Best answer

You can normally check if the variable is valid using is_instance_valid(obj), but in some cases it's unreliable. Issues were opened about this: https://github.com/godotengine/godot/issues/32383

If the object you are referencing is a node, one workaround is to listen for the tree_exited signal, so when the node exits the tree you can properly set your variable to null.
Another way is to not store it in a variable but store the node path instead.

by (27,536 points)
selected by

Dang, listening for the tree_exited signal is the solution I came up with before getting back here. I didn't know the issue was on github. Thank you for helping

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.

Categories