0 votes

Hi again :)

Why are nodes/object not implement/inherit from reference?
i think there is a reason for that...

ive noticed when nodes removed from tree/parent then they not destructed,
which is ok i expect that.
but why they no reference?

for example, i dynamically build a gui control at runtime, with rows.
each row has n controls.
so now i have to keep an array (or similar) to store the controls (for later destruction)

wouldnt references make this much more simpler?
or have i missed something?

p.s. i come from c# where everything is a reference :)

EDIT: ok i could loop over childs and free all, maybe bad example, but question still vaid :)

greets & tnx :)

in Engine by (65 points)
edited by

You don't need to manually free all the children if you free their parent, because then children are automatically freed as well.

1 Answer

+2 votes
Best answer

Nodes are not references mainly because their ownership is managed by the tree. As raymoo said, deleting a node deletes its children. There are not much use cases for nodes to be references, even if it sounds "magically handy", but when you think about it, you also avoid the overhead of refcounts.
As a result it also needs extra caution, especially in C++.

by (29,088 points)
edited by
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 Frequently asked questions and 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 [email protected] with your username.