Make Node's add_child() and remove_child() methods virtual #12764
Closed
OptimalFailure
started this conversation in
Engine Core
Replies: 1 comment
-
Closing in favor of: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
While working on a plugin for a custom control I ran into inconsistency overriding add_child() to detect children, only to discover that it is not supported and I should not have been able to override it in the first place.
This is not the only way to detect children. While you can detect adding (and removing) children with the "child_entered_tree" (and "child__exiting_tree") signals, temporarily adding/removing a node from the active scene tree will trigger these signals, potentially causing additional overhead. Additionally, a node must be active in the scene tree to emit these signals, meaning the parent will not register the addition of a new child until it is loaded in the scene tree, which makes constructing elements with code more challenging.
For these reasons I suggest exposing add_child() and remove_child() as virtual methods, so custom nodes that manage their children have a straightforward way of tracking additions and removals.
I would appreciate any feedback on this matter!
Beta Was this translation helpful? Give feedback.
All reactions