0 votes

Hello, I have a small problem that I don't know how to solve:
I have a parent node that I remove from the tree in the ready() function, I have assigned some of its children a code that causes them to be removed with queuefree(), the problem is that the code removes the child nodes correctly, but when adding the node back to the main tree with addchild gives me an error, node not found, which refers to those that were previously removed. In the application itself it does not give any problem and I imagine that it is because it eliminates the child nodes when it is not in the tree.
Is there a way to read the children's script first and remove them and then pass to the parent's script to detach it from the tree?

Godot version godot 3.4
in Engine by (18 points)

This is hard to imagine.
Please paste and format some of the code for better undestanding. Also explain why is it supposed to be dettached and queued free in this order in your project

1 Answer

0 votes

It is a game that I am making in 3d, where the dungeon is randomly generated rooms and instantiated to conform it. what I do is remove them from the tree once generated in order to improve performance and not lower the fps. these rooms go in and out of the tree as they are needed.
To generate them, what I do is that each room contains all the assets that make it up visually arranged as I intend them to appear and I randomly delete some assets so that the different instances of this same room are different in each one.
The problem is that if I remove the instantiated node from the tree after deleting those assets, when I add it back to the tree it gives me the following error trying to call the assets that no longer exist because they have been deleted.
If I don't delete those assets, it doesn't give any error.
This is the error:
E 0:00:26.136 getnode: (Node not found: "../borra/piedraA" (relative to "/root/room/@cuevaC@11/tile/mapa/RocaA4").)
Condition "!node" is true. Returned: nullptr
scene/main/node.cpp:1325 @ get
node()
cueva.gd:25 @ onVisibilityNotifiercameraentered_cueva()
I have tried to put the script that removes it from the tree at the beginning and at the end of the instantiated branch with the same result.
This is one of the rooms with its tree and the code is the one that takes it out of the tree if it leaves or enters the camera that is at the end of the tree.

And this is the code that removes the assets that I need to delete, they are the other scripts that are seen in the previous image

by (18 points)
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.